Sunday, 1 September 2013

MATLAB CODE FOR SKIN DETECTION IN RGB COLOR SPACE

%detecting skin in hsv color space
clear all;
clc;

img=imread('i1.jpg');
out=img;
r=double (img(:,:,1));
g=double (img(:,:,2));
b=double (img(:,:,3));

%....................................................................
%avg=mean(r(:))+mean(g(:))+mean(b(:));
%R=r/avg;
%G=g/avg;
%B=b/avg;
%image formed from normalised rgb values
%img(:,:,1)=R;
%img(:,:,2)=G;
%img(:,:,3)=B;
%...................................................................

[row col]= find(b>0.79*g-67 & b<0.78*g+42 & b>0.836*g-14 & b<0.836*g+44 );
num=size(row,1);

for i=1:num
    out(row(i),col(i),:)=0;
end

figure
imshow(img);
figure
imshow(out);

No comments:

Post a Comment