Otsu阈值分割详解
Otsu(大津法或最大类间方差法)使用的是聚类的思想,把图像的灰度数按灰度级分成2个部分,使得两个部分之间的灰度值差异最大,每个部分之间的灰度差异最小,通过方差的计算来寻找一个合适的灰度级别来划分。 所以可以在二值化的时候采用otsu算法来自动选取阈值进行二值化。otsu算法被认为是图像分割中阈值选取的最佳算法,计算简单,不受图像亮度和对比度的影响。因此,使类间方差最大的分割意味着错分概率最小。
设t为设定的阈值。
图像总平均灰度为: u = w0∗u0 + w1∗u1
从L个灰度级遍历 t,使得 t 为某个值的时候,前景和背景的方差最大,则 这个 t 值便是我们要求得的阈值。其中,方差的计算公式如下:
g = wo∗(u0−u)∗(u0−u) + w1∗(u1−u)∗(u1−u)
此公式计算量较大,可以采用:
g = w0∗w1∗(u0−u1)∗(u0−u1)
由于Otsu算法是对图像的灰度级进行聚类,因此在执行Otsu算法之前,需要计算该图像的灰度直方图。
源码(matlab):
function [t,em] = otsuthresh(counts)
%OTSUTHRESH Global histogram threshold using Otsu's method.
% T = OTSUTHRESH(COUNTS) computes a global threshold from histogram
% counts COUNTS that minimizes the intraclass variance for a bimodal
% histogram. T is a normalized intensity value that lies in the range [0,
% 1] and can be used with IMBINARIZE to convert an intensity image to a
% binary image.
%
% [T, EM] = OTSUTHRESH(COUNTS) returns effectiveness metric, EM, as the
% second output argument. It indicates the effectiveness of thresholding
% using threshold T and is in the range [0, 1]. The lower bound is
% attainable only by histogram counts with all data in a single non-zero
% bin. The upper bound is attainable only by histogram counts with
% two non-zero bins.
%
% Class Support
% -------------
% The histogram counts COUNTS must be a real, non-sparse, numeric vector.
%
% Example
% -------
% % This example shows how to compute a threshold from an image histogram
% % and binarize the image .
%
% % Read an image of coins and compute a 16-bin histogram.
% I = imread('coins.png');
% counts = imhist(I, 16);
%
% % Compute a global threshold using the histogram counts.
% T = otsuthresh(counts);
%
% % Binarize image using computed threshold.
% BW = imbinarize(I,T);
%
% figure, imshow(BW)
%
% See also IMBINARIZE, GRAYTHRESH.% Copyright 2015-2018 The MathWorks, Inc.
validateattributes(counts, {'numeric'}, {'real','nonsparse','vector','nonnegative','finite'}, mfilename, 'COUNTS');
num_bins = numel(counts);
% Make counts a double column vector
counts = double( counts(:) );% Variables names are chosen to be similar to the formulas in
% the Otsu paper.
p = counts / sum(counts);
omega = cumsum(p);
mu = cumsum(p .* (1:num_bins)');
mu_t = mu(end);sigma_b_squared = (mu_t * omega - mu).^2 ./ (omega .* (1 - omega));
% Find the location of the maximum value of sigma_b_squared.
% The maximum may extend over several bins, so average together the
% locations. If maxval is NaN, meaning that sigma_b_squared is all NaN,
% then return 0.
maxval = max(sigma_b_squared);
isfinite_maxval = isfinite(maxval);
if isfinite_maxval
idx = mean(find(sigma_b_squared == maxval));
% Normalize the threshold to the range [0, 1].
t = (idx - 1) / (num_bins - 1);
else
t = 0.0;
end% compute the effectiveness metric
if nargout > 1
if isfinite_maxval
em = maxval/(sum(p.*((1:num_bins).^2)') - mu_t^2);
else
em = 0;
end
endend
Otsu阈值分割详解相关推荐
- 基于MATLAB改进Otsu阈值分割的车道线检测
基于MATLAB改进Otsu阈值分割的车道线检测 摘要:在判断车道偏离以防止车辆碰撞等危害时,车道标线检测需要通过图像处理来进行,检测方法是否适用于各种背景环境条件以及检测的及时性至关重要传统的Ots ...
- C++手敲基于梯度图和像素数量数组的OTSU阈值分割
一.OTSU算法原理 ➢OTSU法(最大类间方差法,有时也称之为大津算法) ➢ 使用聚类的思想,把图像的灰度数按灰度级分成2个部分, 使得两个部分之间的灰度值差异最大,每个部分之间的灰 度差异最小 ...
- Nacos系列--保护阈值--作用/详解
原文网址:Nacos系列--保护阈值--作用/详解_IT利刃出鞘的博客-CSDN博客 简介 说明 本文介绍Spring Cloud Alibaba Nacos的保护阈值的作用. 在 Nacos 的路由 ...
- SLIC超像素分割详解
SLIC超像素分割详解(一) 超像素概念是2003年Xiaofeng Ren提出和发展起来的图像分割技术,是指具有相似纹理.颜色.亮度等特征的相邻像素构成的有一定视觉意义的不规则像素块.它利用像素之间 ...
- 【MATLAB教程案例23】基于MATLAB图像分割算法仿真——阈值分割法、Otsu阈值分割法、K均值聚类分割法等
FPGA教程目录 MATLAB教程目录 目录 1.软件版本 2.通过二值图实现图像分割 3.通过Otsu阈值分割实现图像分割
- OTSU阈值分割+孔洞填充+海陆分离
1. OTSU阈值分割 参考1. https://zhuanlan.zhihu.com/p/124944108 OTSU算法(大津算法)的详细步骤: 假设初始有个阈值 T 0 T_0 T0,并将图像 ...
- otsu阈值分割算法_图像分割之大津算法(OTSU)
关注公众号,获取更多信息 引言 最近一直在看图像二值化相关的东西,一直想寻找一个好的方法,能够自适应的设定阈值.这个过程中,发现了OTSU算法,其实这也算是基本的图像处理算法,之前有过接触,但是放过了 ...
- 【DP1】钢条分割详解
[DP] 原文再续书接上一回,上一篇文章的背包讲的有点过于狭隘,我就某一类问题解释一种算法的思想:动态规划(Dynamic Programming).简称DP. 我们在生活中不免会遇到一类问题,求什么 ...
- otsu阈值分割原理及实现
OTSU算法是由日本学者OTSU于1979年提出的一种对图像进行二值化的高效算法,是一种自适应的阈值确定的方法,又称大津阈值分割法. OTSU算法利用阈值将图像分为前景后背景两部分,使前景与背景之间的 ...
- otsu天空分割 matlab,matlab图像处理--Otsu阈值分割
原文:https://blog.csdn.net/weixin_41721222/article/details/80207909 Otsu算法:取一个最优阈值把原图像分为前景色(A部分)与背景色(B ...
最新文章
- Application Installation Failed
- 在HYPER-V中利用差异磁盘和SYSPREP技术安装多个WINDOWS 2008
- 12C OCP 1Z0-063 题库(8月以前)
- TCP/IP / TCP 头
- Bound Services
- 深度学习数据更换背景_开始学习数据科学的最佳方法是了解其背景
- “一学就会”微服务的架构模式
- tomcat 开启 https 使用apr
- 学习C++项目——mysql 数据库知识学习(关于 mysql 8.0 版以后基础部分学习)
- mysql自动去重_关于mysql自联去重的一些记录
- 复杂网络中的结构洞理论及其Python实现
- 合宙Air202--Luat入门学习
- 股票买卖问题-含手续费
- poi对word读取(文本和图片)、修改、保存操作及word转换为PDF
- 在windows本地创建svn及遇到错误:svn create repository here 报错
- QGIS 添加国内地图提供商(高德/百度/必应/腾讯)卫星及路网图
- duplicate symbol in....
- 开发者说:深度剖析开源分布式事务方案 Seata 的事务协调器
- drools规则引擎的基本使用和原理介绍
- 计网真题:信道利用率计算