资源简介
Ostu方法又名最大类间差方法,通过统计整个图像的直方图特性来实现全局阈值T的自动选取,其算法步骤为:
1) 先计算图像的直方图,即将图像所有的像素点按照0~255共256个bin,统计落在每个bin的像素点数量
2) 归一化直方图,也即将每个bin中像素点数量除以总的像素点
3) i表示分类的阈值,也即一个灰度级,从0开始迭代
4) 通过归一化的直方图,统计0~i 灰度级的像素(假设像素值在此范围的像素叫做前景像素) 所占整幅图像的比例w0,并统计前景像素的平均灰度u0;统计i~255灰度级的像素(假设像素值在此范围的像素叫做背景像素) 所占整幅图像的比例w1,并统计背景像素的平均灰度u1;
5) 计算前景像素和背景像素的方差 g = w0*w1*(u0-u1) (u0-u1)
6) i++;转到4),直到i为256时结束迭代
7)将最大g相应的i值作为图像的全局阈值

代码片段和文件信息
function [IDXsep] = otsu(In)
%OTSU Global image thresholding/segmentation using Otsu‘s method.
% IDX = OTSU(IN) segments the image I into N classes of Otsu‘s
% N-thresholding method. OTSU returns an array IDX containing the cluster
% indices (from 1 to N) of each point. Zero values are assigned to
% non-finite (NaN or Inf) pixels.
%
% IDX = OTSU(I) uses two classes (N=2 default value).
%
% [IDXsep] = OTSU(...) also returns the value (sep) of the separability
% criterion within the range [0 1]. Zero is obtained only with data
% having less than N values whereas one (optimal value) is obtained only
% with N-valued arrays.
%
% Notes:
% -----
% It should be noticed that the thresholds generally become less credible
% as the number of classes (N) to be separated increases (see Otsu‘s
% paper for more details).
%
% If I is an RGB image a Karhunen-Loeve transform is first performed on
% the three RGB channels. The segmentation is then carried out on the
% image component that contains most of the energy.
%
% Example:
% -------
% load clown
% subplot(221)
% X = ind2rgb(Xmap);
% imshow(X)
% title(‘Original‘‘FontWeight‘‘bold‘)
% for n = 2:4
% IDX = otsu(Xn);
% subplot(22n)
% imagesc(IDX) axis image off
% title([‘n = ‘ int2str(n)]‘FontWeight‘‘bold‘)
% end
% colormap(gray)
%
% Reference:
% ---------
% Otsu N A Threshold Selection Method from Gray-Level Histograms
% IEEE Trans. Syst. Man Cybern. 9:62-66;1979
%
% See also GRAYTHRESH IM2BW
%
% -- Damien Garcia -- 2007/08 revised 2010/03
% Visit my % href=“matlab:web(‘http://www.biomecardio.com/matlab/otsu.html‘)“>website for more details about OTSU
error(nargchk(12nargin))
% Check if is the input is an RGB image
isRGB = isrgb(I);
assert(isRGB | ndims(I)==2...
‘The input must be a 2-D array or an RGB image.‘)
%% Checking n (number of classes)
if nargin==1
n = 2;
elseif n==1;
IDX = NaN(size(I));
sep = 0;
return
elseif n~=abs(round(n)) || n==0
error(‘MATLAB:otsu:WrongNValue‘...
‘n must be a strictly positive integer!‘)
elseif n>255
n = 255;
warning(‘MATLAB:otsu:TooHighN‘...
‘n is too high. n value has been changed to 255.‘)
end
I = single(I);
%% Perform a KLT if isRGB and keep the component of highest energy
if isRGB
sizI = size(I);
I = reshape(I[]3);
[VD] = eig(cov(I));
[tmpc] = max(diag(D));
I = reshape(I*V(:c)sizI(1:2)); % component with the highest energy
end
%% Convert to 256 levels
I = I-min(I(:));
I = round(I/max(I(:))*255);
%% Probability distribution
unI = sort(unique(I));
nbins = min(length(unI)256);
if nbins==n
IDX = ones(size(I));
for i = 1:n IDX(I==unI(i)) = i; end
sep = 1;
return
elseif nbins IDX = NaN(si
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 6046 2018-01-26 13:54 otsu.m
相关资源
- 高灵敏度GPS接收机MATLAB仿真,附捕获
- 基于MATLAB的质点弹道计算与外弹道优
- 阵列天线的matlab仿真
- MATLAB 经典程序源代码大全
- MATLAB小波软阈值去噪代码33473
- 天线阵的波束形成在MATLAB仿真程序及
- 非线性SVM算法-matlab实现
- 《MATLAB 智能算法超级学习手册》-程序
- 组合导航matlab程序
- 读取txt文件内容matlab代码实现
- Matlab实现基于相关的模板匹配程序
- matlab优化工具箱讲解
- 基于MATLAB的快速傅里叶变换
- 光纤传输中的分布傅立叶算法matlab实
- 基于matlab的图像处理源程序
- matlab 椭圆拟合程序
- 算术编码解码matlab源代码
- optical_flow 光流法 matlab 实现程序
- 引导图像滤波器 Matlab实现
- 分形几何中一些经典图形的Matlab画法
- OFDM系统MATLAB仿真代码
- SVM工具箱(matlab中运行)
- 图像小波变换MatLab源代码
- LU分解的MATLAB实现
- 冈萨雷斯数字图像处理matlab版(第三
- 替代数据法的matlab程序
- 用matlab实现的多站定位系统性能仿真
- 通过不同方法进行粗糙集属性约简m
- k近邻算法matlab实现
- matlab识别系统
评论
共有 条评论