function [Ibw, thres] = autoThreshold(I)
% 迭代法自动阈值分割
%
% 输入:I - 要进行自动阈值分割的灰度图像
% 输出:Ibw - 分割后的二值图像
% thres - 自动分割采用的阈值
thres = 0.5 * (double(min(I(:))) + double(max(I(:)))); %初始阈值
done = false; %结束标志
while ~done
g = I >= thres;
Tnext = 0.5 * (mean(I(g)) + mean(I(~g)));
done = abs(thres - Tnext) < 0.5;
thres = Tnext;
end;
Ibw = im2bw(I, thres/255); % 二值化
I=imread('a.jpg');
[Ibw,thres]=autoThreshold(I);
imshow(Ibw)这是处理之前图片处理之后为很明显,此次阈值分割失败。尝试用最大类间方差法,程序为:
I = imread('a.jpg');
level = graythresh(I);
BW = im2bw(I,level);
figure, imshow(BW)
结果为
依然错误。
转载于:https://www.cnblogs.com/natalie/p/4504753.html
相关资源:MATLAB迭代法对基于阈值的图像分割
转载请注明原文地址: https://win8.8miu.com/read-1499865.html