Skin Detection in images

This is a simple program used to detect the skin region from an RGB image. The algorithm simply uses the constraints on the RGB values of each pixel in the image to identify the skin regions. Does not work for grayscale images.




%Function to identify the skin region in a RGB image. Does not work for a
%grayscale image. works very well for rgb images
%USAGE: face(img)
% where img = handle of a RGB image from imread

function face(img)
final_image = zeros(size(img,1), size(img,2));
if(size(img, 3) > 1)
for i = 1:size(img,1)
for j = 1:size(img,2)
R = img(i,j,1);
G = img(i,j,2);
B = img(i,j,3);
if(R > 95 && G > 40 && B > 20)
v = [R,G,B];
if((max(v) - min(v)) > 15)
if(abs(R-G) > 15 && R > G && R > B)
%it is a skin
final_image(i,j) = 1;
end
end
end
end
end
figure, imshow(final_image);
end

No comments:

Post a Comment

 
;