• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

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

武飞扬头像
深度混淆
帮助1

学新通

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

  1.  
    namespace Legalsoft.Truffer.Binarization
  2.  
    {
  3.  
    public static partial class BinarizationHelper
  4.  
    {
  5.  
    #region 灰度图像二值化 局部算法 Bernsen 算法
  6.  
     
  7.  
    /// <summary>
  8.  
    /// Bernsen算法
  9.  
    /// https://blog.csdn.net/Abaqus3_0/article/details/81205168
  10.  
    /// </summary>
  11.  
    /// <param name="data"></param>
  12.  
    /// <param name="kernel"></param>
  13.  
    /// <param name="threshold_diff"></param>
  14.  
    /// <param name="global_threshold"></param>
  15.  
    public static void Bernsen_Algorithm(byte[,] data, int kernel = 15, int threshold_diff = 32, int global_threshold = 128)
  16.  
    {
  17.  
    int height = data.GetLength(0);
  18.  
    int width = data.GetLength(1);
  19.  
     
  20.  
    int halfKernel = kernel / 2;
  21.  
    int[] kernelData = new int[kernel * kernel];
  22.  
    byte[,] dump = (byte[,])data.Clone();
  23.  
    for (int y = 0; y < height; y )
  24.  
    {
  25.  
    for (int x = 0; x < width; x )
  26.  
    {
  27.  
    if (x < halfKernel || x > width - halfKernel - 1 ||
  28.  
    y < halfKernel || y > height - halfKernel - 1)
  29.  
    {
  30.  
    data[y, x] = 0;
  31.  
    }
  32.  
    else
  33.  
    {
  34.  
    int k = 0;
  35.  
    for (int yy = y - halfKernel; yy < y halfKernel; yy )
  36.  
    {
  37.  
    for (int xx = x - halfKernel; xx < x halfKernel; xx )
  38.  
    {
  39.  
    kernelData[k] = dump[yy, xx];
  40.  
    }
  41.  
    }
  42.  
     
  43.  
    int kernelMax = kernelData.Max();
  44.  
    int kernelMin = kernelData.Min();
  45.  
    int Tkernel = (int)((kernelMax kernelMin) * 0.5);
  46.  
     
  47.  
    //灰度差值小,该点要么在目标区域,要么在背景区域
  48.  
    if (kernelMax - kernelMin <= threshold_diff)
  49.  
    {
  50.  
    data[y, x] = (byte)((Tkernel > global_threshold) ? 255 : 0);
  51.  
    }
  52.  
    //灰度差值大,说明在边缘区域,将均值作为局部阈值
  53.  
    else
  54.  
    {
  55.  
    data[y, x] = (byte)((data[y, x] > Tkernel) ? 255 : 0);
  56.  
    }
  57.  
    }
  58.  
     
  59.  
    }
  60.  
    }
  61.  
    }
  62.  
     
  63.  
    #endregion
  64.  
    }
  65.  
    }
学新通

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

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

学新通

POWER BY 315SOFT.COM & TRUFFER.CN

学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgfkbai
系列文章
更多 icon
同类精品
更多 icon
继续加载