how to apply vision function

i have a problem me want when face detect on the bases of skin color only face is in frame mee want to use vision function(Viola-Jones Algorithm). but am unable to do this i want to use vision function behaind the detetion buttion and only face is detected. see the image i hope understand my problem well
see in this image on detection part in 6th axes frame is on neck also ..me want only frame on face just using vision function ..can any one help me??? mee using matlab r2013a

 Accepted Answer

Image Analyst
Image Analyst on 1 Jun 2014
Try using imclose() to join small gaps. Then take the largest blob. If the neck is separated from the face, the face will be larger and you will extract only the face. bwconvhull() may also be of interest to you. See my attached demo for taking the N largest or smallest blobs.

9 Comments

my code behaind face detection button is:
function pushbutton2_Callback(hObject, eventdata, handles)
I=double(handles.I);
[hue,s,v] =rgb2hsv(I);
%a=rgb2hsv(I);
cb = 0.148* I(:,:,1) - 0.291* I(:,:,2) + 0.439 * I(:,:,3) + 128;
cr = 0.439 * I(:,:,1) - 0.368 * I(:,:,2) -0.071 * I(:,:,3) + 128;
[w h]=size(I(:,:,1));
for i=1:w
for j=1:h
if 140<=cr(i,j) && cr(i,j)<=165 && 140<=cb(i,j) && cb(i,j)<=195 && 0.01<=hue(i,j) && hue(i,j)<=0.1
segment(i,j)=1;
else
segment(i,j)=0;
end
end
end
im(:,:,1)=I(:,:,1).*segment;
im(:,:,2)=I(:,:,2).*segment;
im(:,:,3)=I(:,:,3).*segment;
binary=im2bw(im);
s=[0 0 0; 1 1 1 ; 0 0 0];
%s=[0 1 0; 1 1 1 ; 0 1 0];
dil=imerode(binary,s);
new12=im2bw(handles.I,0.15);
%Filling The Holes.
binaryImage = imfill(dil, 'holes');
%subplot(3,3,7); imshow(binaryImage);
binaryImage = bwareaopen(binaryImage,1890);
%subplot(3,3,8);imshow(binaryImage);
labeledImage = bwlabel(binaryImage, 8);
blobMeasurements = regionprops(labeledImage, 'all');
%******
numberOfPeople = size(blobMeasurements, 1);
axes(handles.axes4);
imshow(handles.I);
title('Face Detection','Color','black','FontSize',11,'FontWeight','bold');
%title('Outlines, from bwboundaries()');
%axis square;
hold on;
%boundaries = bwboundaries(binaryImage);
%for k = 1 : numberOfPeople
%thisBoundary = boundaries{k};
%plot(thisBoundary(:,2), thisBoundary(:,1), 'r', 'LineWidth', 2);
%end
% hold off;
axes(handles.axes4);
imshow(handles.I);
hold on;
%title('Original with bounding boxes');
%fprintf(1,'Blob # x1 x2 y1 y2\n');
for k = 1 : numberOfPeople % Loop through all blobs.
% Find the mean of each blob. (R2008a has a better way where you can pass the original image
% directly into regionprops. The way below works for all versionsincluding earlier versions.)
blobArea = blobMeasurements(k).Area;
if blobArea>2000
thisBlobsBox = blobMeasurements(k).BoundingBox; % Get list of pixels in current blob.
x1 = thisBlobsBox(1);
y1 = thisBlobsBox(2);
x2 = x1 + thisBlobsBox(3);
y2 = y1 + thisBlobsBox(4);
% fprintf(1,'#%d %.1f %.1f %.1f %.1f\n', k, x1, x2, y1, y2);
x = [x1 x2 x2 x1 x1];
y = [y1 y1 y2 y2 y1];
%subplot(3,4,2);
plot(x, y, 'LineWidth', 3);
end
end
guidata(hObject, handles);
axis equal;
axis tight;
axis off;
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
how can i embed this (extractbiggestblobe.m)code? how can i apply this
I'll show you how if you attach an image and make the above code into a script that opens the image and does the rest of your code. Then I'll add the code I gave you to extract the biggest blob. What I'll add is this code:
%--------------------------------------------------------
% Extract the largest area using our custom function ExtractNLargestBlobs().
% This is the meat of the demo!
biggestBlob = ExtractNLargestBlobs(binaryImage, 1);
%-------------------------------------------------
right after you got your binary image to make the binary image have only the largest blob and not any others.
reema
reema on 4 Jun 2014
Edited: reema on 4 Jun 2014
sir i embed this code with my binary image code
%---------------------------------------------------------------------------
% Extract the largest area using our custom function ExtractNLargestBlobs().
% This is the meat of the demo!
biggestBlob = ExtractNLargestBlobs(binaryImage, 1);
%---------------------------------------------------------------------------
then this error show:
Undefined function 'ExtractNLargestBlobs' for input arguments of type 'double'.
me embed your recommended code like that check its right::
function pushbutton4_Callback(hObject, eventdata, handles)
I=double(handles.I);
[hue,s,v] =rgb2hsv(I);
%a=rgb2hsv(I);
cb = 0.148* I(:,:,1) - 0.291* I(:,:,2) + 0.439 * I(:,:,3) + 128;
cr = 0.439 * I(:,:,1) - 0.368 * I(:,:,2) -0.071 * I(:,:,3) + 128;
[w h]=size(I(:,:,1));
for i=1:w
for j=1:h
if 140<=cr(i,j) && cr(i,j)<=165 && 140<=cb(i,j) && cb(i,j)<=195 && 0.01<=hue(i,j) && hue(i,j)<=0.1
segment(i,j)=1;
else
segment(i,j)=0;
end
end
end
im(:,:,1)=I(:,:,1).*segment;
im(:,:,2)=I(:,:,2).*segment;
im(:,:,3)=I(:,:,3).*segment;
binary=im2bw(im);
%---------------------------------------------------------------------------
% Extract the largest area using our custom function ExtractNLargestBlobs().
% This is the meat of the demo!
biggestBlob = ExtractNLargestBlobs(binary, 1);
%---------------------------------------------------------------------------
axes(handles.axes3);
imshow(biggestBlob);
title('Binary Image','Color','black','FontSize',11,'FontWeight','bold');
guidata(hObject, handles);
axis equal;
axis tight;
axis off;
sir tell me how to define the function ExtractNLargestBlobs()?????
in the start of code of this button(binaryimage).me define:
function ExtractNLargestBlobs()
now no error show in command windaw but result not show..nothing done ..axes is empty .. tel me what the issue?
Again, the same answer as your duplicate question. I wish I didn't have to answer in two places. You defined your own function and did not use mine. Your has no input or output arguments so of course it does nothing. Use the function I gave you.
reema
reema on 5 Jun 2014
Edited: reema on 5 Jun 2014
sir tell me then how to define the function which me used..me used your recommended code
%---------------------------------------------------------------------------
% Extract the largest area using our custom function ExtractNLargestBlobs().
% This is the meat of the demo!
biggestBlob = ExtractNLargestBlobs(binary, 1);
%---------------------------------------------------------------------------
axes(handles.axes3);
imshow(biggestBlob);
thenthis error show :
Undefined function 'ExtractNLargestBlobs' for input arguments of type 'double' now tell me how to define it ..sorry sir i didn't get your point plz elabrate
OK, let's end this thread . I don't want to keep answering the same thing in two different threads.
okay sir me remove this one

Sign in to comment.

More Answers (0)

Asked:

on 1 Jun 2014

Commented:

on 6 Jun 2014

Community Treasure Hunt

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

Start Hunting!