Matlab實現圖像切割


以下使用極小值點閾值選取方法,編寫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);



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM