C#,图像二值化(07)——全局阈值的迭代算法及其源代码

news2024/10/5 20:25:01

1、 全局阈值的迭代算法

图像阈值分割---迭代算法

(1) 为全局阈值选择一个初始估计值T(图像的平均灰度)。
(2) 用T分割图像。产生两组像素:G1有灰度值大于T的像素组成,G2有小于等于T像素组成。
(3) 计算G1和G2像素的平均灰度值m1和m2;
(4) 计算一个新的阈值:T = (m1 + m2) / 2;
(5) 重复步骤2和4,直到连续迭代中的T值间的差小于一个预定义参数为止。
 

二值算法综述请阅读:

C#,图像二值化(01)——二值化算法综述与二十三种算法目录icon-default.png?t=MBR7https://blog.csdn.net/beijinghorn/article/details/128425225?spm=1001.2014.3001.5502

支持函数请阅读:

C#,图像二值化(02)——用于图像二值化处理的一些基本图像处理函数之C#源代码icon-default.png?t=MBR7https://blog.csdn.net/beijinghorn/article/details/128425984?spm=1001.2014.3001.5502

2、全局阈值的迭代算法的C#源程序

using System;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Drawing.Imaging;

namespace Legalsoft.Truffer.ImageTools
{
    public static partial class BinarizationHelper
    {

        #region 灰度图像二值化 全局算法 迭代算法

        /// <summary>
        /// 阀值分割:迭代法
        /// https://blog.csdn.net/xw20084898/article/details/17564957
        /// </summary>
        /// <param name="data"></param>
        /// <param name="nMaxIter">最大迭代次数</param>
        /// <param name="iDiffRec">使用给定阀值确定的亮区与暗区平均灰度差异值</param>
        /// <returns></returns>
        private static int Iteration_Threshold(byte[,] data, int nMaxIter, out int iDiffRec)
        {
            int height = data.GetLength(0);
            int width = data.GetLength(1);

            iDiffRec = 0;

            int[] histogram = Gray_Histogram(data);
            int iMinGrayValue = Histogram_Left(histogram);
            int iMaxGrayValue = Histogram_Right(histogram);

            int iThrehold = 0;
            int iTotalGray = 0;
            int iTotalPixel = 0;
            int iNewThrehold = (iMinGrayValue + iMaxGrayValue) / 2;
            iDiffRec = iMaxGrayValue - iMinGrayValue;

            for (int a = 0; (Math.Abs(iThrehold - iNewThrehold) > 0.5) && a < nMaxIter; a++)
            {
                iThrehold = iNewThrehold;
                for (int i = iMinGrayValue; i < iThrehold; i++)
                {
                    iTotalGray += histogram[i] * i;
                    iTotalPixel += histogram[i];
                }
                int iMeanGrayValue1 = (iTotalGray / iTotalPixel);
                iTotalPixel = 0;
                iTotalGray = 0;
                for (int j = iThrehold + 1; j < iMaxGrayValue; j++)
                {
                    iTotalGray += histogram[j] * j;
                    iTotalPixel += histogram[j];
                }
                int iMeanGrayValue2 = (iTotalGray / iTotalPixel);

                iNewThrehold = (iMeanGrayValue2 + iMeanGrayValue1) / 2;
                iDiffRec = Math.Abs(iMeanGrayValue2 - iMeanGrayValue1);
            }

            return iThrehold;
        }

        public static void Iteration_Algorithm(byte[,] data)
        {
            int threshold = Iteration_Threshold(data, 100, out int iDiffRec);
            Threshold_Algorithm(data, threshold);
        }

        #endregion

    }
}

3、全局阈值的迭代算法的计算效果

Image threshold segmentation iterative algorithm

(1) Select an initial estimate T (the average gray level of the image) for the global threshold.

(2) Use T to segment the image. Two groups of pixels are generated: G1 consists of pixels with a gray value greater than T, and G2 consists of pixels with a gray value less than or equal to T.

(3) Calculate the average gray value m1 and m2 of G1 and G2 pixels;

(4) Calculate a new threshold: T=(m1+m2)/2;

(5) Repeat steps 2 and 4 until the difference between T values in successive iterations is less than a predefined parameter.

An iterative algorithm is the most common way to solve the data flow analysis equations. In this algorithm, we particularly have two states first one is in-state and the other one is out-state. The algorithm starts with an approximation of the in-state of each block and then computed by applying the transfer functions on the in-states.

Iterative algorithms (IA) of solving the inverse problems of the scalar theory of diffraction for the calculation of the DOEs, investigated in this section, do not cover the entire spectrum of the currently available iterative algorithms. No attention has been given to algorithms such as the method of direct stochastic search for the binary phase [49], the annealing modelling method [51], the error diffusion method [88], the Newton method for calculating the Dammann gratings [58], and others. These methods are less efficient in comparison with the parametric and gradient iterative algorithms investigated in this chapter, although they are characterised by convergence and reach a global minimum after a large number of iterations.

Although the IAs of the calculating DOEs have shortcomings (for example, the stagnation effect, i.e., as a result of the incorrect selection of the initial estimate of the sought DOE phase, the algorithm can reached a local minimum when the error does not change with the increase of the number of iterations), the obvious advantages of the IA explain why they are used widely in diffractive optics. Some of the advantages of the IA are described below.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/126230.html

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

相关文章

机器学习笔记之Sigmoid信念网络(二)醒眠算法

机器学习笔记之Sigmoid信念网络——醒眠算法引言回顾Sigmoid\text{Sigmoid}Sigmoid信念网络的模型表示Sigmoid\text{Sigmoid}Sigmoid信念网络——对数似然梯度求解过程中的问题醒眠算法基于平均场假设变分推断求解后验概率平均场理论求解后验的弊端醒眠算法引言 上一节介绍了对…

jsp+servlet+mysql实现的在线图书商城源码附带论文开题报告及视频指导教程

今天给大家演示的是一款由jspservletmysql实现的在线图书商城系统&#xff0c;主要分为前台后后台管理员功能&#xff0c;前台用户可以浏览查看各类图书信息&#xff0c;可自定义搜索&#xff0c;注册登录后可以将书添加到购物车&#xff0c;购物车中的商品可以提交订单&#x…

【复习笔记】JavaWeb实验重点代码

JavaWeb实验重点代码笔记 一、课上练习题目汇总&#xff08;部分&#xff09; 题目一 基础HTML、CSS和JavaScript 1.1 问题要求 页面上有下拉菜单、文本框、跳转按钮并排放置&#xff0c;当下拉菜单选中某个具体网站名称时&#xff0c;文本框出现其对应的链接地址&#xff0…

Linux环境下vs code中Markdown与PlantUML联合工作

PlantUML是一个可以让你快速编写UML图的组件。 在线服务器 https://www.plantuml.com/plantuml/uml/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000 Markdown是一种轻量级标记语言&#xff0c;排版语法简洁&#xff0c;让人们更多地关注内容本身而非排版。它使用易读易写的纯文本格式编写…

零膨胀泊松回归案例分析

零膨胀泊松回归分析 计数研究模型中&#xff0c;常用泊松回归模型&#xff0c;但泊松回归模型理论上是要求平均值与标准差相等&#xff0c;如果不满足&#xff0c;则可使用负二项回归模型 在实际研究中&#xff0c;会出现一种情况即因变量为计数变量&#xff0c;并且该变量包…

Lua闭包和Upvalue上值

一、lua中的作用域 在Lua语言中声明的变量默认是全局变量&#xff0c;声明局部变量需要使用local关键字&#xff0c;和其他语言相比这有点特殊。 -- 全局变量 a 10function func()b 100 -- 仍然是全局变量local c 20 -- func的局部变量 end func()print(a b) -- 输出…

终极.NET混淆器丨.NET Reactor产品介绍

无与伦比的 .NET 代码保护系统&#xff0c;可完全阻止任何人反编译您的代码。 产品优势 01、混淆技术 .NET Reactor通过向 .NET 程序集添加不同的保护层来防止逆向工程。除了标准的混淆技术之外&#xff0c;它还包括NecroBit、虚拟化、x86代码生成或防篡改等特殊功能。NET Re…

xilinx srio ip学习笔记之初识srio

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 xilinx srio ip学习笔记之初识srio前言IP 设置总结前言 因为工作原因&#xff0c;需要对rapidio 的协议进行了解&#xff0c;在xilinx的IP核中&#xff0c;是对应着Serial R…

这支隐藏“球队”,颠覆消费品「赛场」

【潮汐商业评论/原创】 大好的黄金周末&#xff0c;Fred约了几个朋友来家里看球。按照他的计划&#xff0c;周五准备下班后&#xff0c;他赶紧得去一趟附近的大型超市扫货&#xff0c;买一批零食酒水招待朋友。没想到的是&#xff0c;好不容易等到快下班了&#xff0c;领导通知…

外包呆一年,外包的工作经历怎么写?外包的项目经验怎么写?

0. 先来看下大家的各种问题&#xff1f; 外包的工作经历怎么写&#xff1f;外包的项目经验怎么写&#xff1f;外包如何优化简历&#xff1f;进入外包后黑化了简历&#xff0c;如何成功跳出外包圈&#xff1f;外包该如何提升自己&#xff1f;外包仔如何自我救赎&#xff1f; ……

前端基础_离线Web应用概述

离线Web应用概述 在Web应用中使用缓存的原因之一是为了支持离线应用。在全球互联的时代&#xff0c;离线应用仍有其实用价值。当无法上网的时候&#xff0c;你会做什么呢&#xff1f;你可能会说如今网络无处不在&#xff0c;而且非常稳定&#xff0c;不存在没有网络的情况。但…

【服务器数据恢复】误操作导致ocfs2文件系统被格式化的数据恢复案例

服务器故障&#xff1a; 用户误操作将linux文件系统误装入到Ocfs2文件系统的数据卷上&#xff0c;导致原始Ocfs2文件系统被格式化为Ext4文件系统。 因为Ext4文件系统每隔几百兆就会写入文件系统的原始信息&#xff0c;所以本案例中的原始Ocfs2文件系统中的数据可能受到一定程度…

搭建开源版个人图床

在微博图床、gitee、jsDelivr 陆续被 ban 的今天&#xff0c;很有必要搭建自己的图床系统了。 兰空图床 兰空图床官网&#xff1a;https://www.lsky.pro docker版本&#xff1a;https://hub.docker.com/r/halcyonazure/lsky-pro-docker 本次讲解使用 docker 版本进行部署使用 …

linux跟踪技术之ebpf

ebpf简介 eBPF是一项革命性的技术&#xff0c;起源于 Linux 内核&#xff0c;可以在操作系统内核等特权上下文中运行沙盒程序。它可以安全有效地扩展内核的功能&#xff0c;而无需更改内核源代码或加载内核模块。 比如&#xff0c;使用ebpf可以追踪任何内核导出函数的参数&…

漫画电学原理

电是什么 电压 电压是两点的电势差。 电流是指每秒在导线中流动的电量。 电功率是指在1s内消耗的电能。 电的本质是什么 万物都是有原子构成,原子有原子核(正电),核外电子(负电)构成。电子的定向移动形成了电。 电子离开原子,原子的电子减少,从而带正电。带正电的…

互联网时代“陨落”,国家发布元宇宙战略的信号对失业和担心失业的我们带来了什么启迪?

互联网这头“猪 ”真的掉下来了 流量红利已经一去不复返了&#xff01;3年前业界其实已经发出各种密集信号&#xff0c;在当时无论是BAT还是一些经济学家在3年前都已经预测过&#xff0c;互联网的流量模式已经衰竭&#xff0c;并且它将一去不复返。 曾经处于互联网大潮的我们…

day10Git

1.Git介绍 1.1版本控制(理解) 无论是代码编写&#xff0c;还是文档编写&#xff0c;我们都会遇到对文档内容反复修改的情况 1.2开发中存在的问题(理解) 程序员小明负责的模块就要完成了&#xff0c;就在即将提交发布之前的一瞬间&#xff0c;电脑突然蓝屏&#xff0c;硬盘光…

HTC FOCUS 3连接FOHEART H1数据手套

本教程介绍使用H1数据手套与HTC腕带式追踪器驱动VR中的虚拟手运动&#xff0c;实现手部的追踪及定位。 需要准备的硬件&#xff1a; 1、FOHEART H1数据手套 2、HTC VIVE Focus 3一体机 3、HTC VIVE 腕带式追踪器 01 一体机连接腕带追踪器 首先断开Focus3的手柄&#x…

【JavaWeb】Mybatis深度进阶练习

学习目标 能够使用映射配置文件实现CRUD操作能够使用注解实现CRUD操作 文章目录1、配置文件实现CRUD1.1 环境准备1.2 查询所有数据1.2.1 编写接口方法1.2.2 编写SQL语句1.2.3 编写测试方法1.2.4 起别名解决上述问题1.2.5 使用resultMap解决上述问题1.2.6 小结1.3 查询详情1.3.1…

(一) 初识python

1. python的特点&#xff1a; 可读性强 可读性远比听上去重要的多得多。一个程序会被反复的修改&#xff0c;可读性意味这让你可以在更短时间内学习和记忆&#xff0c;直接提高生产率。高效、简洁 研究证明&#xff0c;程序员每天可编写的有效代码是有限的。完成同样功能只用一…