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

news2025/2/28 13:33:11

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.coloradmin.cn/o/161236.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

04_FreeRTOS任务挂起和恢复函数

目录 任务的挂起与恢复的API函数 任务挂起函数介绍 任务恢复函数介绍 中断中恢复函数 vTaskSuspend()任务挂起函数 vTaskResume()任务中恢复函数 xTaskResumeFromISR()中断中恢复函数 任务的挂起与恢复的API函数 挂起:挂起任务类似暂停,可恢复;删除任务,无法恢复,类似“…

公务员行测常识积累(持续更新中)

公务员行测常识积累政治天文地理人文戏曲历史经济物理生物医学政治 区域协调发展战略&#xff1a;以城市群为主体构建大中小城市和小城镇协调发展的城镇格局&#xff1b;以疏解北京非首都功能为“牛鼻子”推动京津冀协同发展&#xff1b;以共抓大保护、不搞大开发为导向推动长…

个人建议【建议】

以下只是个人的一些看法 本文已在CSDN博客中发布文章 本文已在CSDN建议社区中发布帖子 重点内容已经被蓝色字体标志出来了&#xff0c;希望能对建设优秀的CSDN有所启发 快速浏览看总结 中心思想看最后 1.我的专栏上限问题还没解决 在2022-10-24 20:33:41就发出了这个问题&…

如何突破以往模式的束缚,如何让互联网行业重新开启新的想象空间

在流量和资本的红利已然被出清的大背景下&#xff0c;以平台经济为代表的互联网经济的发展同样被逼退到了进退维谷的境地里。如何突破以往发展模式的束缚&#xff0c;如何让互联网行业的发展重新开启新的想象空间&#xff0c;成为每一个互联网玩家必然需要思考的重要课题。于是…

Java基础学习笔记(十五)—— Sream流

Sream流1 Stream流初体验2 Stream流概述3 生成Stream流4 中间操作方法5 终结操作方法6 收集操作方法7 Stream流案例1 Stream流初体验 案例需求 创建一个集合&#xff0c;存储多个字符串元素把集合中所有以“张”开头的元素存储到一个新的集合把"张"开头的集合中的长…

SpringCloud高级应用-2(Gateway-01)

Gateway介绍&#xff1a; Spring Cloud Gateway 是Spring Cloud团队的一个全新项目&#xff0c;基于Spring 5.0、SpringBoot2.0、Project Reactor 等技术开发的网关。旨在为微服务架构提供一种简单有效统一的API路由管理方式。 Spring Cloud Gateway 作为SpringCloud生态系统…

Acwing---1214.波动数列

波动数列1.题目2.基本思想3.代码实现1.题目 观察这个数列&#xff1a; 1 3 0 2 -1 1 -2 … 这个数列中后一项总是比前一项增加2或者减少3&#xff0c;且每一项都为整数。 栋栋对这种数列很好奇&#xff0c;他想知道长度为 n 和为 s 而且后一项总是比前一项增加 a 或者减少 …

Grafana配置sqlserver,展示数据

Grafana配置sqlserver&#xff0c;展示数据1. 连接数据源2. Visualization2.1 时间表达式2.2 Graph2.2.1 Example with metric column2.2.2 convert null values to be zero instead2.2.3 Using multiple columns3. AwakeningGrafana Document: https://grafana.com/docs/grafa…

java MultipartFile+vue+element 批量上传文件、图片,与普通数据同时提交保存才上传到后端

一.背景 文件上传项目可参考&#xff1a;点击预览 1.最简单也是最普遍的做法是form表单提交&#xff0c;其实前端提交到后端也是难以离开form表单提交&#xff0c; 一般有两种方式来处理文件、图片上传&#xff1a; 先上传&#xff0c;获取返回路径&#xff0c;再整个表单提…

PyTorch实现基本的线性回归

线性回归理论知识参考文章&#xff1a;线性回归 下面我们将从零开始实现整个线性回归方法&#xff0c; 包括数据集生成、模型、损失函数和小批量随机梯度下降优化器。 1.导入 %matplotlib inline import random import torch from d2l import torch as d2l2.生成数据集 我们…

js垃圾回收(引用计数算法、标记清除算法、v8垃圾回收机制、浏览器性能监控、任务管理器、内存分析、JSBench)

目录 垃圾 可达对象 GC算法&#xff08;垃圾回收机制&#xff09; 引用计数算法 优点 缺点 标记清除算法 优点 缺点 标记整理算法 优点 缺点 V8 V8垃圾回收 新生代对象回收 晋升条件 老生代对象回收 性能监控Performance 浏览器任务管理器 内存分析 ​编…

Apache Doris 系列: 基础篇-BitMap索引

1. 测试数据准备 本文使用SSB&#xff08;Star-Schema-Benchmark&#xff09;的测试数据&#xff0c;读者也可以自行准备测试数据 1.1 编译ssb-dbgen 数据生成工具 ## 拉取Apache Doris源代码 git clone https://github.com/apache/doris.git## 编译ssb-dbgen cd doris/tool…

计算机网络复习之应用层

统一资源定位系统&#xff08;uniform resource locator;URL&#xff09;是因特网的万维网服务程序上用于指定信息位置的表示方法。它最初是由蒂姆伯纳斯李发明用来作为万维网的地址。现在它已经被万维网联盟编制为互联网标准RFC1738。邮局协议&#xff08;Post Office Protoco…

TDemo 备注文本的二种存贮方式

TDemo 备注纯文本的二种存贮方式 数据库使用过程中&#xff0c;对于TDeme控件&#xff0c;对应数据库的分为nvarchar(n)类型字段。 一、通常使用二种格式的文本&#xff1a; &#xff08;1&#xff09;单纯文本 &#xff08;2&#xff09;带换行符的文本 这二种格式&#xff0c…

Pdf 转换成Word如何在线转换?职场公认好用软件推荐

Pdf 转换成Word如何在线转换&#xff1f;生活中很多时候我们需要接触大量的办公文件&#xff0c;特别是利用office的三种常见的文件格式编辑各类文件&#xff0c;最常见的便是Word文件操作。为了更方便我们进行文件传输&#xff0c;大部分情况下我们会把格式排版完好的Word文档…

UDS诊断系列介绍08-19服务

本文框架1. 系列介绍1.1 19服务概述1.2 DTC故障码定义1.3 DTC状态位2. 19服务常用子服务2.1 19 01服务2.2 19 02服务2.3 19 04服务2.4 19 06服务2.5 19 0A服务2.6 否定响应3. Autosar系列文章快速链接1. 系列介绍 UDS&#xff08;Unified Diagnostic Services&#xff09;协议…

Android 深入系统完全讲解(15)

4 权限相关的知识 1 安卓权限 上层 APK 权限获取方式&#xff0c;配置 AndroidManifest.xml&#xff0c;系统会对应的给 gid&#xff0c;在创建进程的时候就带下去&#xff0c;这样子就可以访问对应的设备。 而系统相关的&#xff0c;会限制必须是 uidsystem 这类&#xff0c…

一年融资三轮,一文读懂亿格云这家公司

数字办公时代&#xff0c;网络安全是企业经营的底线工作。如何构建一个安全、稳定、高效的网络安全体系&#xff0c;是企业谋求发展的基础条件之一。近年&#xff0c;倡导“永不信任&#xff0c;始终验证”的零信任网络安全服务理念开始兴起。而国内致力于基于零信任理念构建办…

MySQL 行级锁(行锁、临键锁、间隙锁)

行级锁 行级锁&#xff0c;每次操作锁住对应的行数据。锁定粒度最小&#xff0c;发生锁冲突的概率最低&#xff0c;并发度最高。应用在InnoDB存储引擎中。 InnoDB的数据是基于索引组织的&#xff0c;行锁是通过对索引上的索引项加锁来实现的&#xff0c;而不是对记录加的锁。 1…

类和对象(上)

文章目录引用autoNULL&nullptr&0类和对象类的实例化默认成员函数构造函数析构函数拷贝构造函数运算符的重载赋值运算符的重载拷贝构造次数编译器优化前置后置> < ! - -const成员operator>>&&operator<<再谈构造函数初始化列表初始化expli…