I am not getting proper output for the following skin detection program.Where am I wrong??

I am doing Face detction using skin color segmentation.
For this image,No output is shown for figure 4 and figure 5
For this Image,the same type of error occurs.
For this totally different output is showing
This is the program I used.
clc;
clear all;
currentimg=imread('Bush.jpg'); %capture the image of interest
figure(1)
subplot(421);
imshow(currentimg);
%Read the image, and capture the dimensions
VidImage = currentimg;
height = size(VidImage,1);
width = size(VidImage,2);
%Initialize the output images
out = VidImage;
bin = zeros(height,width);
%Convert the image from RGB to YCbCr
img_ycbcr = rgb2ycbcr(VidImage);
Cb = img_ycbcr(:,:,2);
Cr = img_ycbcr(:,:,3);
subplot(422);
imshow(img_ycbcr);
%Detect Skin
[r,c,v] = find(Cb>=77 & Cb<=127 & Cr>=133 & Cr<=173);
numind = size(r,1);
%Mark Skin Pixels
for i=1:numind
out(r(i),c(i),:) = [0 0 255];
bin(r(i),c(i)) = 1;
end
binaryImage=im2bw(bin,graythresh(bin));
binaryImage=~binaryImage;
subplot(423);
imshow(binaryImage);
B = bwboundaries(binaryImage);
disp(B);
binaryImage = imfill(binaryImage,'holes');
subplot(424);
imshow(binaryImage);
% Remove tiny regions.
binaryImage = bwareaopen(binaryImage, 5000);
subplot(425);
imshow(binaryImage);
%---------------------------------------------------------------------------
% Extract the largest area using ImageAnalyst's custom function
ExtractNLargestBlobs().
biggestBlob = ExtractNLargestBlobs(binaryImage, 1);
% Display the image.
subplot(426)
imshow(biggestBlob, []);
title('Final Image');
%--------------------------------------------------------------------------
[labeledImage, numberOfBlobs] = bwlabel(biggestBlob, 8);
% Get all the blob properties.
blobMeasurements = regionprops(labeledImage, 'BoundingBox','Area');
allBlobAreas = [blobMeasurements.Area];
% Display the original gray scale image.
subplot(427);
imshow(currentimg, []);
% Loop through all blobs, putting up Bounding Box.
hold on; % Prevent boxes from blowing away the image and prior boxes.
for k = 1 : numberOfBlobs
boundingBox = blobMeasurements(k).BoundingBox; % Get box.
x1 = boundingBox(1);
y1 = boundingBox(2);
x2 = x1 + boundingBox(3) - 1;
y2 = y1 + boundingBox(4) - 1;
verticesX = [x1 x2 x2 x1 x1];
verticesY = [y1 y1 y2 y2 y1];
plot(verticesX, verticesY);
end

4 Comments

please edit your post,
the code is not readable,
use the preview session beneath your edit area.
Insert 2 blanks before the first character in the first line of code and then eliminate the spaces between...the two blanks on line turn it to the coding format...
http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup. I see that after your edit, you still couldn't figure out how to format, so I did it for you (this time).

Sign in to comment.

 Accepted Answer

It looks like it should work. We can't know because you didn't explain why the output doesn't look "proper" nor did you attach the image so we could try it, nor did you even attach screenshots. Read this: http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer

8 Comments

I have edited my above post! Please reply me as soon as possible.
It all comes down to this line:
[r,c,v] = find(Cb>=77 & Cb<=127 & Cr>=133 & Cr<=173);
While those thresholds may have worked for some image, they don't work for all images and you need to come up with some algorithm to find those values automatically as the image changes. You might look here in VisionBib for successful algorithms that were published and use one of those. http://www.visionbib.com/bibliography/contentspeople.html#Face%20Recognition,%20Detection,%20Tracking,%20Gesture%20Recognition,%20Fingerprints,%20Biometrics
But ,Whatever the image is I am getting output for 3rd image which is the output of that [r,c,v] = find(Cb>=77 & Cb<=127 & Cr>=133 & Cr<=173) The problem is with the 4th and 5th images For some images it's deleting the main blobs (which is the skin pixels) and for some images it's including it!!
So is the original binary image good? Why are you doing all that nonsense with find(), bin, and out and im2bw()??? It's all unnecessary. You already have the binary image so just use it
binaryImage = Cb>=77 & Cb<=127 & Cr>=133 & Cr<=173;
Then continue on with imfill(), etc.
Using that bin and out only am creating the black and white image !! Removing that doesn't make any sense!! Can you please update the code and post it here????
Of course it makes sense. What you're doing is to create the binary image, then get the coordinates of the binary image with find(), then recreating a brand new binary image with the coordinates, and it will end up being the same as the binary image you created inside your call to find(). No need to go through all that when you already have the binary image in the beginning.
I may help to fix your code if you include (attach) one of the full sized images.

Sign in to comment.

More Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!