Clear Filters
Clear Filters

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

1 view (last 30 days)
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

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 7 Sep 2014
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

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!