資源簡介
碩士期間自己編寫的邊緣提取程序。以CMU步態(tài)庫中的圖像為例,提取人的輪廓。包括形態(tài)學(xué)運(yùn)算、孔洞填充、平滑、標(biāo)簽等一系列操作,每個步驟均有注釋,程序可讀性強(qiáng)。
以下是代碼片段:
% imclose the image
se=strel('disk',3);
f6=imclose(f5,se);
figure(4);
imshow(f6);
% fill the image
f8=imfill(f6);
figure(5);
imshow(f8);
% smooth the image
f9=double(f8)/255;
f10=medfilt2(f9,[3 3]);
figure(6);
imshow(f10,[]);
% add label to the image
bw1=im2bw(f10);
[x,num]=bwlabel(bw1,4);
...

代碼片段和文件信息
clc;
clear?all;
%reading?and?showing
f1=imread(‘foreground.jpg‘);
%converting?color?image?to?grayimage
f2=rgb2gray(f1);
figure(1)imshow(f2);
%reading?and?showing
f3=imread(‘background.jpg‘);
%converting?color?image?to?grayimage
f4=rgb2gray(f3);
figure(2)imshow(f4);
%background?subtracting
f5=abs(double(f2)-double(f4));
[M?N]=size(f5);
T=20;
for?i=1:M
???for?j=1:N
??????if?f5(ij)>T
?????????f5(ij)=255;
??????else
?????????f5(ij)=0;
??????end
???end
end
f5=uint8(f5);
figure(3);
imshow(f5);
%?imclose?the?image
se=strel(‘disk‘3);
f6=imclose(f5se);
figure(4);
imshow(f6);
%?fill?the?image
f8=imfill(f6);
figure(5);
imshow(f8);
%?smooth?the?image
f9=double(f8)/255;
f10=medfilt2(f9[3?3]);
figure(6);
imshow(f10[]);
%?add?label?to?the?image
bw1=im2bw(f10);
[xnum]=bwlabel(bw14);
%?calculate?the?number?of?pixels?of?each?labeled?area
long=1:num;
for?i=1:num
[rc]=find(x==i);
rc=[r?c];
long(i)=size(rc1);
end
%?display?the?number?of?pixels?of?each?labeled?area
for?j=1:num
????disp(long(j));
end
%?calculate?which?area?has?the?biggest?number?of?pixels
max=0;
for?k=1:num
????if(long(k)>max)?
????????max=long(k);
????????m=k;
????end
end
%?the?label?of?the?biggest?area
m
%?the?number?of?pixels?of?the?biggest?area
max
%?get?the?image?of?the?biggest?area?
[row?column]=size(x);
for?i=1:row
????for?j=1:column
????????if(x(ij)==m)
????????????x(ij)=m;
????????else?x(ij)=0;
????????end
????end
end
se=strel(‘disk‘2);
x=imerode(xse);
%?display?the?image
figure(7)imshow(x);
%?get?the?edge?of?the?image
y=edge(x‘canny‘);
figure(8)imshow(y);
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2009-05-04?21:35??CMU\
?????文件???????43648??2001-04-06?20:25??CMU\background.jpg
?????文件????????1645??2005-05-30?18:18??CMU\edge1.asv
?????文件????????1663??2008-03-01?09:56??CMU\edge1.m
?????文件???????47037??2001-04-06?19:17??CMU\foreground.jpg
評論
共有 條評論