首页 > 代码库 > MATLAB 提取头发(可以去除背景)

MATLAB 提取头发(可以去除背景)

 1 I= imread(2.jpg);
 2 figure(1), imshow(I)
 3 R=I(:,:,1);
 4 G=I(:,:,2);
 5 B=I(:,:,3);
 6 [m,n]=size(r);
 7 mask=zeros(m,n);
 8 for i = 1:m
 9    for j = 1:n
10        if r(i,j)<70 && g(i,j)<70 && b(i,j)<70
11             mask(i,j)=1;
12         end
13     end
14 end
15 figure(2),imshow(mask)
16 [L,num]=bwlabel(mask,8);%l·μ????áDμ?×?′óêy£?num×?′óêy??ó|μ?áDêy£¨×?′óêy????£?
17 x=zeros(1,num);
18 for ii=1:num
19    x(ii)=sum(sum(L==ii));
20 end
21 [m,ind]=max(x);
22 out=(L==ind);%á?L=indμ??μ?a1
23 figure(3),imshow(out)

 

 

技术分享

 

MATLAB 提取头发(可以去除背景)