Matlab实现图像分割 分类: 图像处理 2014-06-14 21:31 662人阅读 评论(1) 收藏

下面使用极小值点阈值选取方法,编写MATLAB程序实现图像分割的功能。

极小值点阈值选取法即从原图像的直方图的包络线中选取出极小值点,

并以极小值点为阈值将图像转为二值图像


clear all;
close all ;
G=imread('rabbit.png');
figure();
subplot(2,2,1);
imshow(G);
subplot(2,2,2);
imhist(G);
subplot(2,2,3);
imhist(G);
[h,x]=imhist(G);
h=smooth(h,7);
plot(x,h)
%求出阈值T
df1=diff(h);%一阶差分
df2=diff(df1);%二阶差分
[m,n]=size(df2);
T=0;
for i=1:m
if(abs(df1(i+1))<=0.15 && df2(i)>0)
    T=x(i+2)%确定阈值
    break;
end
end
G=im2bw(G,T/255);%转为二值图像
subplot(2,2,4);
imshow(G);


版权声明:本文为博主原创文章,未经博主允许不得转载。

posted @ 2014-06-14 21:31  xiaoluo91  阅读(934)  评论(0编辑  收藏  举报