1、大津算法OTSU ALGORITHM

OTSU算法效果很一般。

最大类间方差法是1979年由日本学者大津(Nobuyuki Otsu)提出的,是一种自适应阈值确定的方法,又叫大津法,简称OTSU,是一种基于全局的二值化算法,它是根据图像的灰度特性,将图像分为前景和背景两个部分。当取最佳阈值时,两部分之间的差别应该是最大的,在OTSU算法中所采用的衡量差别的标准就是较为常见的最大类间方差。前景和背景之间的类间方差如果越大,就说明构成图像的两个部分之间的差别越大,当部分目标被错分为背景或部分背景被错分为目标,都会导致两部分差别变小,当所取阈值的分割使类间方差最大时就意味着错分概率最小。

2、Image Threshold

If the intensity of a pixel in the input image is greater than a threshold, the corresponding output pixel is marked as white (foreground), and if the input pixel intensity intensity is less than or equal to the threshold, the output pixel location is marked black (background).

Image thresholding is used in many applications as a pre-processing step. For example, you may use it in medical image processing to reveal tumor in a mammogram or localize a natural disaster in satellite images.

A problem with simple thresholding is that you have to manually specify the threshold value. We can manually check how good a threshold is by trying different values but it is tedious and it may break down in the real world.

So, we need a way to automatically determine the threshold. The Otsu’s technique named after its creator Nobuyuki Otsu is a good example of auto thresholding.

Before we jump into the details of the technique let’s understand how image thresholding relates to image segmentation.

3、Otsu thresholding

To improve on the segmentation, we next investigated a smarter thresholding approach: Otsu’s method. Otsu thresholding assumes that there are two classes of pixels in the image which we wish to separate. Additionally, Otsu’s method assumes that the two classes are separated by a roughly bimodal intensity histogram. The algorithm will then find the optimal threshold that separates the two classes via an exhaustive search for the threshold that minimizes the variance between the two classes. Our golf course images seemed to fit the assumptions of the algorithm: the two classes of pixels are “trees” and “the rest” and the intuition for our bimodal intensity histogram is “trees are dark”, “the rest is light”.

Using Otsu’s method for thresholding worked much better than the simple thresholding: large parts of the playable rough are now included in the segmented mask. There are some small false-positives such as the masked pixels in the tree crowns on the right upper side of the image. However, those small areas of noise were easily fixed via morphological operations such as opening, erosion and dilation.

One area where we noted that Otsu’s method broke down is in an image that contains shadows such as the example below. Otsu’s method operates on grayscale images so it can’t distinguish the deep dark green color of the tree canopy from the dark shadows of a tree. This is very visible in the upper center of the picture where shadows on the right end of the horizontal tree line are being included. However, for our golf course image segmentation, these shadows should be excluded.

二值算法综述请阅读:

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

4、大津OTSU算法的源代码(两个版本)

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 灰度图像二值化 全局算法 大津OTSU 算法(两种代码)/// <summary>/// 图像二值化的大津算法/// Otsu's Thresholding/// https://blog.csdn.net/weixin_35811044/article/details/85255924/// </summary>/// <param name="data">灰度化的图片数据</param>/// <returns></returns>public static int Otsu_Threshold(byte[,] data){int height = data.GetLength(0);int width = data.GetLength(1);int[] histv = Gray_Histogram(data);double[] histogram = Histogram_Normalize(histv);int pixelNumb = height * width;double[] variances = new double[256];for (int T = 0; T < histogram.Length; T++){double n1 = 0, n2 = 0;double total1 = 0, total2 = 0;double aver1 = 0, aver2 = 0;double w1 = 0, w2 = 0;double ft1 = 0, ft2 = 0;for (int i = 0; i < T; i++){n1 += histogram[i];total1 += histogram[i] * i;}for (int j = T; j < variances.Length; j++){n2 += histogram[j];total2 += histogram[j] * j;}w1 = n1 / pixelNumb;w2 = n2 / pixelNumb;aver1 = (n1 == 0) ? 0 : (total1 / n1);aver2 = (n2 == 0) ? 0 : (total2 / n2);for (int i = 0; i < T; i++){ft1 += (Math.Pow((i - aver1), 2) * histogram[i]);}for (int j = T; j < 256; j++){ft2 += (Math.Pow((j - aver2), 2) * histogram[j]);}ft1 = (n1 == 0) ? 0 : (ft1 / n1);ft2 = (n2 == 0) ? 0 : (ft2 / n2);variances[T] = w1 * ft1 + w2 * ft2;}double min = variances[0];int threshold = 0;for (int i = 1; i < variances.Length; i++){if (variances[i] < min){min = variances[i];threshold = i;}}return threshold;}/// <summary>/// 大津算法之二/// </summary>/// <param name="histogram"></param>/// <returns></returns>public static int Ostu_Threshold_Second(int[] histogram){int left = Histogram_Left(histogram);int right = Histogram_Right(histogram);int amount = Histogram_Sum(histogram);double PixelIntegral = Histogram_Sum(histogram, 1);int Threshold = 0;double PixelBack = 0.0;double PixelIntegralBack = 0.0;double SigmaB = -1.0;for (int i = left; i <= right; i++){PixelBack = PixelBack + histogram[i];double PixelFore = amount - PixelBack;double OmegaBack = (double)PixelBack / (double)amount;double OmegaFore = (double)PixelFore / (double)amount;PixelIntegralBack += histogram[i] * (double)i;double PixelIntegralFore = PixelIntegral - PixelIntegralBack;double MicroBack = (double)PixelIntegralBack / PixelBack;double MicroFore = (double)PixelIntegralFore / PixelFore;double Sigma = OmegaBack * OmegaFore * (MicroBack - MicroFore) * (MicroBack - MicroFore);if (Sigma > SigmaB){SigmaB = Sigma;Threshold = i;}}return Threshold;}/// <summary>/// 图像二值化的大津算法/// </summary>/// <param name="data">灰度化的图片数据</param>public static void Otsu_Algorithm(byte[,] data){int threshold = Otsu_Threshold(data);Threshold_Algorithm(data, threshold);}#endregion}
}

5、大津OTSU算法的计算效果

C#,图像二值化(06)——全局阈值的大津算法(OTSU Thresholding)及其源代码相关推荐

  1. 图像二值化处理(全局阈值 自适应阈值 手动阈值操作以及直方图画法)

    文章目录 图像二值化处理 二值化原理 API介绍 手动设置阈值 均值法 迭代法 自动设置阈值 直方图法 全局阈值法 OTSU法 三角形法 自适应阈值法 API 绘制图像直方图 图像二值化处理 二值化原 ...

  2. 【图像处理】——图像的二值化操作及阈值化操作(固定阈值法(全局阈值法——大津法OTSU和三角法TRIANGLE)和自适应阈值法(局部阈值法——均值和高斯法))

    目录 一.二值化的概念(实际上就是一个阈值化操作) 1.概念: 2.实现方法 3.常用方法 二.阈值类型 1.常见阈值类型(主要有五种类型) (1)公式描述 (2)图表描述 2.两种特殊的阈值算法(O ...

  3. 图像二值化_三角阈值法

    前言 一.三角阈值法是什么? 二.算法原理 1.算法 总结 参考文献 前言 图像二值化有很多方法,比较经典的为OTSU,三角阈值法,本文主要想一探三角阈值法的算法原理. 一.三角阈值法是什么? 三角阈 ...

  4. java 用遗传算法解决图像二值化问题 找阈值

    image类对图像处理 import java.awt.image.BufferedImage; public class Image {public int h; //高public int w; ...

  5. OTSU_图像二值化分割阈值的算法

    简介: 大津法(OTSU)是一种确定图像二值化分割阈值的算法,由日本学者大津于1979年提出.从大津法的原理上来讲,该方法又称作最大类间方差法,因为按照大津法求得的阈值进行图像二值化分割后,前景与背景 ...

  6. 自适应阈值图像二值化

    一.二值化 关于二值化的介绍,以前的博客中有介绍,这里就不再描述了,二值化介绍:二值化分为固定阈值二值化和自适应阈值二值化,固定阈值二值化方式是我们常用的二值化方式,需要自己摸索一个经验阈值,不断调整 ...

  7. 图像二值化(选择阈值)

    目录 1. 双峰法 2. 大津法(Otsu法或最大类间方差法) 1. 双峰法 在一些简单的图像中,物体的灰度分布比较有规律,背景与各个目标在图像 的直方图各自形成一个波峰,即区域与波峰一一对应,每两个 ...

  8. 二值化图像的欧拉数_Android OpenCV(八):图像二值化

    图像二值化 简介 图像二值化( Image Binarization)就是将图像上的像素点的灰度值设置为0或255,也就是将整个图像呈现出明显的黑白效果的过程.在数字图像处理中,二值图像占有非常重要的 ...

  9. OpenCV-Python 图像二值化

    OpenCV-Python 图像二值化 一.什么是图像二值化 二.图像二值化 Ⅰ先获取阈值: Ⅱ根据阈值去二值化图像 ⅢOpenCV中的二值化方法 三.全局阈值函数cv2.threshold · 函数 ...

最新文章

  1. 测试发现equals和hashCode与书上描述的不一样
  2. MPS(主生产计划)
  3. php结尾的链接_优化 PHP 代码建议(结尾有彩蛋)
  4. NYOJ-42 一笔画问题
  5. 不安装oracle 连接数据库,不安装oracle 连接服务器oracle数据库方法
  6. Win10+VSCode搭建opencv+C++环境(1)
  7. django模板变量的使用详解 200309
  8. jQuery验证码发送时间秒递减(刷新存储cookie)
  9. ROS入门-3.C++/python极简基础
  10. Spark 1.0.0版本号公布
  11. 勒索病毒解密工具的汇总
  12. 批判性思维-真理符合论
  13. 编程之道(英汉对照)[转载]
  14. 等分频率法模拟随机波列(线性波叠加原理)
  15. 如何缓解眼疲劳(眼疲劳敷眼睛是热敷还是冷敷)
  16. C#中使用正则表达式验证电话号码、手机号、身份证号、数字、邮编、时间(仅年月日)、邮箱、小数的正则表达式...
  17. 大家之言 | 谈“网络安全终身教育”
  18. linux 用户 组区别吗,Linux用户组之主组和附加组
  19. (自兴人工智能)python列表
  20. 怎么在线给pdf加盖电子公章

热门文章

  1. MyBatis中关于resultType和resultMap的区别
  2. AutoCAD2018错误提示:“许可管理器不起作用或未正确安装”的解决办法
  3. eml html显示工具,电脑打开eml文件的三种方法【图文教程】
  4. 联想电脑Z460安装Win7
  5. Python 对图片进行颜色识别
  6. Android开发:WGS-84、GCJ02坐标名词解释及坐标转换
  7. 状告迅雷是电影公司不想迅雷“独享其成”
  8. 计算机CMOS设置详解
  9. PERT管与PERT二型管的区别
  10. JDK1.6中文版下载