阈值分割之迭代选择阈值法
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)
这是处理之前图片
![](https://images0.cnblogs.com/blog2015/706484/201505/142256080019459.jpg)
处理之后为
![](https://images0.cnblogs.com/blog2015/706484/201505/142257008762607.jpg)
很明显,此次阈值分割失败。
尝试用最大类间方差法,程序为:
I = imread('a.jpg');
level = graythresh(I);
BW = im2bw(I,level);
figure, imshow(BW)
结果为
依然错误。
posted on 2015-05-14 23:02 nataliebky 阅读(1693) 评论(0) 编辑 收藏 举报