matlab分割背景与物体

[name,path]=uigetfile('*.jpg;*.png;*.bmp','选择一张图片');
f=imread([path name]);
count = 0;
T = mean2(f);
done = false;
while ~done
countcount = count + 1;
g = f > T;
Tnext = 0.5*(mean(f(g)) + mean(f(~g)));
done = abs(T - Tnext) < 0.5;
T = Tnext;
end
g = im2bw(f, T/255);
subplot(121);
imshow(f)
subplot(122);
imshow(g);

posted on 2015-01-21 20:16  豆芽的博客  阅读(1756)  评论(0编辑  收藏  举报