C#,图像二值化(22)——局部阈值的伯恩森算法(Bernsen Thresholding)及源程序

news/2025/2/19 9:29:25/

1、局部阈值的伯恩森算法(Bernsen Thresholding)

Bernsen方法是为图像分割开发的局部自适应二值化方法之一。在这项研究中,实现了Bernsen的局部自适应二值化方法,并对不同灰度图像进行了测试。

Bernsen’s method is one of locally adaptive binarization methods developed for image segmentation. In this study, Bernsen’s locally adaptive binarization method is implemented and then tested for different grayscale images. In this tutorial, we will use “luispedro” image, below is the command to load it.

该方法使用用户提供的对比度阈值。如果局部对比度(max-min)高于或等于对比度阈值,则将阈值设置为局部中间值(局部窗口中最小和最大灰度值的平均值)。如果局部对比度低于对比度阈值,则认为邻域仅由一个类组成,并且根据中肠的值将像素设置为对象或背景。

The method uses a user-provided contrast threshold. If the local contrast (max-min) is above or equal to the contrast threshold, the threshold is set at the local midgrey value (the mean of the minimum and maximum grey values in the local window). If the local contrast is below the contrast threshold the neighbourhood is considered to consist only of one class and the pixel is set to object or background depending on the value of the midgrey.

在数字图像处理中,二值化(二级阈值)是一种常用的图像分割技术。这是将灰度图像转换为二进制图像的过程。此外,二值化方法分为全局二值化和局部自适应二值化两组。多年来已经提出了许多二值化技术。Bernsen方法是为图像分割开发的局部自适应二值化方法之一。在这项研究中,实现了Bernsen的局部自适应二值化方法,并对不同灰度图像进行了测试。

In digital image processing, binarization (two-level thresholding) is a commonly used technique for image segmentation. It is the process of converting a gray scale image to a binary image. Furthermore, binarization methods are divided into two groups as global binarization and locally adaptive binarization. A number of binarization techniques have been proposed over the years. Bernsen’s method is one of locally adaptive binarization methods developed for image segmentation. In this study, Bernsen’s locally adaptive binarization method is implemented and then tested for different gray scale images.

由于适用于数字图像处理的许多领域,二值化是一种众所周知的图像分割方法(Sahoo等人,1988)。为了将对象与背景分离,这是一种有效的技术。多年来,已经提出了许多二值化应用,例如用于提取印刷字符、徽标、图形内容或乐谱的文档图像分析、用于查找线条、图例或字符的位置的地图处理、用于检测目标的场景处理、材料的质量检查、,视频图像的边缘场提取和时空分割(Sezgin和Sankur,2004)。近年来,文档图像分析领域受到了广泛关注,并已成为数字图像处理的重要组成部分之一。有许多研究人员正在寻求设计从地图、杂志、报纸、工程图纸、表格和邮件等广泛文档中提取信息的系统。在大多数这些系统中,二值化作为第一步应用(Trier和Taxt,1995a)。文档图像二值化的目的是从图像中提取文本,去除噪声并减小图像大小。该过程是在去除无用信息的情况下进行的,以提高图像中有用信息的可见性(Bataineh等人,2011)。在Kefali等人(2010)的工作中,二值化的目的是减少不期望数据的存在,并保存文档图像中的期望数据。此操作通过将图像的所有灰度级转换为黑白两级来完成。二值化技术分为两组。这些是全局二值化和局部自适应二值化(Singh等人,2011)。全局二值化方法计算整个图像的单个阈值。具有比阈值暗的灰度级的像素被标记为黑色(前景)。在相反的情况下,其他像素被标记为白色(背景)(Trier和Jain,1995)。文献中存在的一些全局二值化方法包括Abutaleb方法(Abutaleb1989)、Kapur等人的方法(Kapur等人,1985)、Kittler和Illingworth方法(Kittler and Illingworth1986)和Otsu方法(Otsu,1979)。此外,局部自适应二值化方法基于包含在像素的邻域中的信息来计算每个像素的阈值。其中一些方法在整个图像上计算阈值曲面。在输入图像中,如果像素(x,y)具有比在(x,y)处评估的阈值表面更高的灰度级,则将像素(x、y)标记为背景,否则将其标记为前景(Trier和Jain,1995)。在文献中,一些局部自适应二值化方法是Bernsen方法(Bernsen,1986)、Chow和Kaneko方法(Chow和Kaneko,1972;Nakagawa和Rosenfeld,1979)、Eikvil等人的方法(Eikvil et al.,1991)、Mardia和Hainsworth方法(Mardia和Heinsworth,1988)、Niblack方法(Niblack,1986)和Taxt等人的方法,Yanowitz和Bruckstein的方法(Yanowitz and Bruckstein,1989)、White和Rohrer的动态阈值算法(White and Rohrer,1983)、White和Rohreer的综合函数算法(Whiteand Rohreer,1983),Parker的方法(Parker,1991)以及Trier和Taxt的方法(Trier and Taxt,1995b)。

Binarization is a well-known method for image segmentation due to applicability to many fields in digital image processing (Sahoo et al., 1988). In order to separate objects from background, it is an effective technique. A number of binarization applications have been proposed over the years such as document image analysis for extracting printed characters, logos, graphical content or musical scores, map processing for finding place of lines, legends or characters, scene processing for detecting a target, quality inspection of materials, extraction of edge field and spatio-temporal segmentation of video images (Sezgin and Sankur, 2004). In recent years, the field of document image analysis has received significant attention and has become one of the important parts of digital image processing. There are various researchers which are seeking to design systems for extracting information from extensive documents as maps, magazines, newspapers, engineering drawings, forms and mails. In most of these systems, binarization is applied as the first step (Trier and Taxt, 1995a). The aim of the binarization of document images is extracting text from images, removing noise and reducing image size. This process is performed with removing useless information in order to increase visibility of useful information in an image (Bataineh et al., 2011). In the work of Kefali et al. (2010), it is asserted that the purpose of binarization is to decrease the existence of undesirable data and conserve the desired data in document images. This operation is done by converting all gray levels of images into two levels as black and white. Binarization techniques are divided into two groups. These are global binarization and locally adaptive binarization (Singh et al., 2011). Global binarization methods compute a single threshold value for the entire image. Pixels having a gray level darker than the threshold value are marked as black (foreground). In the contrary case, the other pixels are labeled as white (background) (Trier and Jain, 1995). Some of the global binarization methods existing in the literature are Abutaleb’s method (Abutaleb, 1989), Kapur et al.’s method (Kapur et al., 1985), Kittler and Illingworth’s method (Kittler and Illingworth, 1986) and Otsu’s method (Otsu, 1979). Besides, locally adaptive binarization methods calculate a threshold value for each pixel on the basis of information contained in a neighborhood of the pixel. Some of these methods compute a threshold surface over the entire image. In the input image, if a pixel (x, y) has a higher gray level than threshold surface evaluated at (x, y), then the pixel (x, y) is marked as background, otherwise it is marked as foreground (Trier and Jain, 1995). In the literature, some of the locally adaptive binarization methods are Bernsen’s method (Bernsen, 1986), Chow and Kaneko’s method (Chow and Kaneko, 1972; Nakagawa and Rosenfeld, 1979), Eikvil et al.’s method (Eikvil et al., 1991), Mardia and Hainsworth’s method (Mardia and Hainsworth, 1988), Niblack’s method (Niblack, 1986), Taxt et al.’s method (Taxt et al., 1989), Yanowitz and Bruckstein’s method (Yanowitz and Bruckstein, 1989), White and Rohrer’s dynamic threshold algorithm (White and Rohrer, 1983), White and Rohrer’s integrated function algorithm (White and Rohrer, 1983), Parker’s method (Parker, 1991) and Trier and Taxt’s method (Trier and Taxt, 1995b).

本文的其余部分组织如下。在材料和方法部分,Bernsen的局部自适应说明了二值化方法。在结果和讨论部分,显示了在不同邻域值和对比度极限下,将Bernsen方法应用于灰度图像的结果。最后,结论部分总结了正在研究的结论。

The rest of the paper is organized as follows. In materials and methods section, Bernsen’s locally adaptive

binarization method is explained. In results and discussion section, the results of applying Bernsen’s method on gray scale images are showed for different neighborhood values and contrast limits. Finally, conclusions being under study are summarized in conclusion section.

2、局部阈值的伯恩森算法(Bernsen Thresholding)源程序

二值算法综述请阅读:

C#,图像二值化(01)——二值化算法综述与二十三种算法目录

https://blog.csdn.net/beijinghorn/article/details/128425225?spm=1001.2014.3001.5502

支持函数请阅读:

C#,图像二值化(02)——用于图像二值化处理的一些基本图像处理函数之C#源代码

https://blog.csdn.net/beijinghorn/article/details/128425984?spm=1001.2014.3001.5502

namespace Legalsoft.Truffer.Binarization
{
public static partial class BinarizationHelper
{#region 灰度图像二值化 局部算法 Bernsen 算法/// <summary>/// Bernsen算法/// https://blog.csdn.net/Abaqus3_0/article/details/81205168/// </summary>/// <param name="data"></param>/// <param name="kernel"></param>/// <param name="threshold_diff"></param>/// <param name="global_threshold"></param>public static void Bernsen_Algorithm(byte[,] data, int kernel = 15, int threshold_diff = 32, int global_threshold = 128){int height = data.GetLength(0);int width = data.GetLength(1);int halfKernel = kernel / 2;int[] kernelData = new int[kernel * kernel];byte[,] dump = (byte[,])data.Clone();for (int y = 0; y < height; y++){for (int x = 0; x < width; x++){if (x < halfKernel || x > width - halfKernel - 1 ||y < halfKernel || y > height - halfKernel - 1){data[y, x] = 0;}else{int k = 0;for (int yy = y - halfKernel; yy < y + halfKernel; yy++){for (int xx = x - halfKernel; xx < x + halfKernel; xx++){kernelData[k] = dump[yy, xx];}}int kernelMax = kernelData.Max();int kernelMin = kernelData.Min();int Tkernel = (int)((kernelMax + kernelMin) * 0.5);//灰度差值小,该点要么在目标区域,要么在背景区域if (kernelMax - kernelMin <= threshold_diff){data[y, x] = (byte)((Tkernel > global_threshold) ? 255 : 0);}//灰度差值大,说明在边缘区域,将均值作为局部阈值else{data[y, x] = (byte)((data[y, x] > Tkernel) ? 255 : 0);}}}}}#endregion
}
}

3、局部阈值的伯恩森算法(Bernsen Thresholding)计算效果

调整一些参数可以获得更好的或更不好的效果。大家可以试试。

POWER BY 315SOFT.COM & TRUFFER.CN


http://www.ppmy.cn/news/12049.html

相关文章

在OpenDDS应用程序中将样本记录为JSON

简介在本文中,我演示了如何 1)将样本序列化为JSON以进行日志记录 2)记录OpenDDS应用程序中写入、接收(存储在DataReader的缓存中)、读取和获取的所有样本。 这样的日志可能对调试和审计有用。OpenDDS中的相应接口称为ValueWriter和Observer。总之,这些功能允许您创建所有…

Unity 3D 三维模型简介||

Unity 3D 三维模型简介 三维模型是用三维建模软件建造的立体模型&#xff0c;也是构成 Unity 3D 场景的基础元素。 Unity 3D 几乎支持所有主流格式的三维模型&#xff0c;如 FBX 文件和 OBJ 文件等。 开发者可以将三维建模软件导出的模型文件添加到项目资源文件夹中&#xf…

【每日一道智力题】之 药瓶毒鼠鼠

题目&#xff1a; 有1000个一模一样的瓶子&#xff0c;其中有999瓶是普通的水&#xff0c;有1瓶是毒药。任何喝下毒药的生命都会在一星期之后死亡。现在你只有10只鼠鼠和1个星期的时间&#xff0c;如何检验出哪个瓶子有毒药&#xff1f; 这是一道经典的面试题&#xff0c;我们先…

【TypeScript】TS基础

TypeScript基础 文章目录TypeScript基础类型注解TypeScript类型概述TypeScript原始数据类型数组类型联合类型类型别名函数类型基本使用void 类型可选参数对象类型基本使用箭头函数形式的方法类型对象可选属性使用类型别名练习接口类型基本使用interface vs type接口继承元组类型…

2023.1.14单词打卡

cube n.立方体 detain v.扣押&#xff0c;拘留&#xff1b;耽搁 in the interest of 为了...的利益 implication n.含意&#xff0c;暗示&#xff1b;牵连&#xff1b;可能的影响 articulate v.明确表达&#xff1b;adj.善于表达的 ubiquitous adj.普遍存在的&#xff1b;…

分享120个ASP源码,总有一款适合您

ASP源码 分享120个ASP源码&#xff0c;总有一款适合您 链接&#xff1a;https://pan.baidu.com/s/1WwTsUTLS_qLvP-TC1w-1vQ?pwdvxpk 提取码&#xff1a;vxpk 下面是文件的名字&#xff0c;我放了一些图片&#xff0c;文章里不是所有的图主要是放不下...&#xff0c;大家下载…

PyQt6快速入门-显示表格数据(NumpyPanda)

显示表格数据(Numpy&Panda) 文章目录 显示表格数据(Numpy&Panda)1、QTableView介绍2、自定义QAbstractTableModel3、格式化数据4、表格样式4.1 行列颜色样式4.2 文本对齐4.3 文本颜色4.4 数字范围颜色渐变4.5 图标和图像装饰4.6 颜色块5、显示Numpy和Panda数据5.1 …

makefile文件解释

makefile文件解释makefile文件详细解释makefile文件 CC gPROGRAM ubuntuopenglSRC $(wildcard ./*.cpp)OBJECTS $(patsubst %.cpp,%.o,$(SRC))LIBS -lX11 -lGL -lGLEW%.o: %.cpp$(CC) $(LIBS) -c -o $ $< $(PROGRAM): $(OBJECTS)$(CC) -o $ $(OBJECTS) $(LIBS)clean:-…