Matlab图像分割(二)局部阈值分割

matlab局部阈值分割代码

I=imread(image); %读取图片
imshow(I),title('原图');
f=im2double(I);%数据类型转换
T=0.5*(min(f(:))+max(f(:)));
done=false;
while ~done
	g=f>=T;
	Tn=0.5*(mean(f(g))+mean(f(~g)));
	done = abs(T-Tn)<0.1;
	T=Tn;
end
display('Threshold(T)-Iterative');%显示文字
T
r=im2bw(f,T);
Th=graythresh(f);%阈值
display('Global Thresholding- Otsu''s Method');
Th
s=im2bw(f,Th);
se=strel('disk',10);
ft=imtophat(f,se);
Thr=graythresh(ft);
display('Threshold(T) -Local Thresholding');
Thr
l1 = im2bw(ft,Thr);
figure,imshow(l1),title('局部阈值分割');

Matlab图像分割(二)局部阈值分割_第1张图片
Matlab图像分割(二)局部阈值分割_第2张图片

你可能感兴趣的:(Matlab图像分割(二)局部阈值分割)