You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
crop the image(show in axses)
1 view (last 30 days)
Show older comments
see this image:
i want to crop the face and then show it in next axes7..how can i display the detected face in next axse7..help me me using matlab r2013a
Accepted Answer
Image Analyst
on 2 Jun 2014
I already answered this in http://www.mathworks.com/matlabcentral/answers/131970#answer_139045 and my answer here wouldn't be any different. You made a comment with code there but didn't ask a question so I don't know how to respond to that. If it worked, mark it at Accepted, and let me know if this question is not applicable anymore and I can delete it.
By the way, you have a bunch of questions that you've never accepted , and I still have a question for you in http://www.mathworks.com/matlabcentral/answers/131985-display-text-in-next-line-in-edit-box#comment_217169 Please finish up your old posts.
34 Comments
Image Analyst
on 2 Jun 2014
Attach your binary image with the blobs and I'll show you how to use the function
%--------------------------------------------------
% Extract the largest area using our custom function ExtractNLargestBlobs().
% This is the meat of the demo!
biggestBlob = ExtractNLargestBlobs(binaryImage, 1);
%-----------------------------------------------------
to extract the largest blob.
Image Analyst
on 4 Jun 2014
Why didn't you just use the function as I defined it? You defined your own version with the same name but no input arguments and no output arguments. So naturally it doesn't do anything.
reema
on 5 Jun 2014
Edited: reema
on 5 Jun 2014
sir you define this function as:
function ExtractBiggestBlob()
in your code (ExtractBiggestBlob.m)..now tell me how me to define and which input out arguments require to define this plz...how can i define the function
Image Analyst
on 5 Jun 2014
reema, note that I did not define the function like that. In my m-file the function definition begins like this :
function binaryImage = ExtractNLargestBlobs(binaryImage, numberToExtract)
and if you use that and follow the instructions for the input arguments, it will work for you. If you remove the arguments, like you did, then it won't work obviously. Attach some simple demo code that shows how you're using it on a binary image if you need more help.
reema
on 6 Jun 2014
Edited: reema
on 6 Jun 2014
see sir the code which me apply see me apply right or not?
function pushbutton4_Callback(hObject, eventdata, handles)
function binaryImage = ExtractNLargestBlobs(binaryImage, numberToExtract)
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;
binaryImage=im2bw(im);
%---------------------------------------------------------------------------
% Extract the largest area using our custom function ExtractNLargestBlobs().
% This is the meat of the demo!
biggestBlob = ExtractNLargestBlobs(binaryImage, 1);
%---------------------------------------------------------------------------
axes(handles.axes3);
imshow(biggestBlob);
title('Binary Image','Color','black','FontSize',11,'FontWeight','bold');
guidata(hObject, handles);
axis equal;
axis tight;
axis off;
check sir wich mistake mee doingg..if you say then me send you my (.m) file iff you didn't understand my point
Image Analyst
on 6 Jun 2014
No, that is not right. First of all pushbutton4_Callback() is doing nothing because there is no code in the body of the function.
Secondly, you define ExtractNLargestBlobs() and call ExtractNLargestBlobs() inside of the definition, so it's going to be calling itself. This means it's recursive. Not what you want.
If you want all that code to be inside pushbutton4_Callback() then just delete this line
function binaryImage = ExtractNLargestBlobs(binaryImage, numberToExtract)
which immediately follows the pushbutton4_Callback() line.
reema
on 7 Jun 2014
Edited: reema
on 7 Jun 2014
now i remove the line u suggest now my code is like that:
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;
now the error shows when me click on pushbutton4_callback button:
>> face Undefined function 'ExtractNLargestBlobs' for input arguments of type 'double'.
Error in face>pushbutton4_Callback (line 249) biggestBlob = ExtractNLargestBlobs(binary, 1);
Error in gui_mainfcn (line 96) feval(varargin{:});
Error in face (line 42) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)face('pushbutton4_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback:
now tell me where me doingg mistake..can i send you my whole coding file (.m)file
Image Analyst
on 7 Jun 2014
You need to have the function ExtractNLargestBlobs defined in your m-file or else in a separate m-file on the search path. All you're doing is calling it, you have not defined it anywhere.
Image Analyst
on 7 Jun 2014
Just add this code onto the end of your m-file: Because you don't know how to do that I strongly suggest you read the part of the documentation about creating functions.
%==============================================================================================
% Function to return the specified number of largest or smallest blobs in a binary image.
% If numberToExtract > 0 it returns the numberToExtract largest blobs.
% If numberToExtract < 0 it returns the numberToExtract smallest blobs.
% Example: return a binary image with only the largest blob:
% binaryImage = ExtractNLargestBlobs(binaryImage, 1)
% Example: return a binary image with the 3 smallest blobs:
% binaryImage = ExtractNLargestBlobs(binaryImage, -3)
function binaryImage = ExtractNLargestBlobs(binaryImage, numberToExtract)
try
% Get all the blob properties. Can only pass in originalImage in version R2008a and later.
[labeledImage, numberOfBlobs] = bwlabel(binaryImage);
blobMeasurements = regionprops(labeledImage, 'area');
% Get all the areas
allAreas = [blobMeasurements.Area];
if numberToExtract > 0
% For positive numbers, sort in order of largest to smallest.
% Sort them.
[sortedAreas, sortIndexes] = sort(allAreas, 'descend');
elseif numberToExtract < 0
% For negative numbers, sort in order of smallest to largest.
% Sort them.
[sortedAreas, sortIndexes] = sort(allAreas, 'ascend');
% Need to negate numberToExtract so we can use it in sortIndexes later.
numberToExtract = -numberToExtract;
else
% numberToExtract = 0. Shouldn't happen. Return no blobs.
binaryImage = false(size(binaryImage));
return;
end
% Extract the "numberToExtract" largest blob(a)s using ismember().
biggestBlob = ismember(labeledImage, sortIndexes(1:numberToExtract));
% Convert from integer labeled image into binary (logical) image.
binaryImage = biggestBlob > 0;
catch ME
errorMessage = sprintf('Error in function ExtractNLargestBlobs().\n\nError Message:\n%s', ME.message);
fprintf(1, '%s\n', errorMessage);
uiwait(warndlg(errorMessage));
end
Image Analyst
on 8 Jun 2014
Simply pass it in the input argument list
output = RecognitionProcess(binaryImage, rgbImage)
I included the original image because face recognition will require more than just a binary image of a big blob. Of course RecognitionProcess() is the function that you must write.
Image Analyst
on 8 Jun 2014
The documentation is in there, isn't it? I always document my demos extensively with comments. Is there a comment you don't understand? For documentation about bwlabel, regionprops, or any of the MATLAB functions, see the help.
reema
on 8 Jun 2014
sir me define my problem which me said want to pass the detected face to the next GUI's axes: 1. sir me done this work till now:
now i want the face which is shows in axes7(the detected face).. i want to pass this image in next GUI'first axes..where the heading is detected face:
now tell me how can i pass this ..which code me going to usee...can i explain myy problem well??
Image Analyst
on 11 Jun 2014
I had real work to do. Volunteering here is not my full time job.
There is no axes with a heading "Detected Face" on that GUI. But in general, you should pass the image or filename via the input argument list to your new figure. Then display it with axes() and imshow() like you did with the images in the first GUI.
Image Analyst
on 8 Jul 2014
In gui1(), when you go to call gui2(), call it this way
gui2(yourImageArray);
needless to say, replace "yourImageArray" with the actual name of the image array variable that you are using. I just used yourImageArray because I don't know what you called your variable.
reema
on 13 Jul 2014
sir i have another Question: see this GUI:
sir me detect the face and i have database which hold different viewpoints image of one person face..now tell me using PCA how can i recognized it..i need code help..if you say then me send you the (.m )file of this GUI for better understanding.. give me code of PCA or any better advice how can i recognized it..
Image Analyst
on 13 Jul 2014
I don't know how to do that. Anyway, that would be a major project that I just can't afford to spend the time developing the project for you for free.
reema
on 14 Jul 2014
sir i want just hint ..you don not give mee the ful my project codee..just givee me codic help, any example or just sample of related work.i want to perform recogniton .want to match one picture with database.and tell the uesr that you are recognized... i want just any hint
Image Analyst
on 14 Jul 2014
Here's code I got from Spandan, one of the developers of the Image Processing Toolbox at the Mathworks:
Here some quick code for getting principal components of a color image. This code uses the pca() function from the Statistics Toolbox which makes the code simpler.
I = double(imread('peppers.png'));
X = reshape(I,size(I,1)*size(I,2),3);
coeff = pca(X);
Itransformed = X*coeff;
Ipc1 = reshape(Itransformed(:,1),size(I,1),size(I,2));
Ipc2 = reshape(Itransformed(:,2),size(I,1),size(I,2));
Ipc3 = reshape(Itransformed(:,3),size(I,1),size(I,2));
figure, imshow(Ipc1,[]);
figure, imshow(Ipc2,[]);
figure, imshow(Ipc3,[]);
In case you don’t want to use pca(), the same computation can be done without the use of pca() with a few more steps using base MATLAB functions.
Hope this helps.
-Spandan
reema
on 19 Jul 2014
its works but how can i embed this with my code..see my codee: behind detected face button :after detection i want to perform recognition:
I=double(handles.I);
N=(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);
%--------------------------------------------------------------------------
s=[0 1 0; 1 1 1 ; 0 1 0];
dil=imerode(biggestBlob,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('Outlines, from bwboundaries()');
%axis square;merrii awazz nii aa rahii
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.)
allBlobAreas = [blobMeasurements.Area];
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
for k = 1 : numberOfPeople % Loop through all blobs.
% Find the bounding box of each blob.
thisBlobsBoundingBox = blobMeasurements(k).BoundingBox; % Get list of pixels in current blob.
% Extract out this coin into it's own image.
subImage = imcrop(N, thisBlobsBoundingBox);
% Display the image with informative caption.
% figure(k);imshow(subImage);
end
axes(handles.axes9);
imshow(subImage);
title('Detected Face','Color','black','FontSize',11,'FontWeight','bold');
guidata(hObject, handles);
axis equal;
axis tight;
axis off;
i want to mathch this detected face with database using PCA...plz help meee how can i do this..
reema
on 25 Jul 2014
sir i want to matchtwo iamgesin if statement me usee the code is given below:
h=subImage;
h1=imread('14.jpg');
A=rgb2gray(h);
A1=rgb2gray(h1);
% axes(handles.axes10);
% imshow(I);
% figure, imshow(A);
J=imhist(A);
J1=imhist(A1);
figure, imshow(J1);
E_distance= sqrt(sum((J-J1).^2));
if E_distance == 0
figure, imshow('14.jpg');
else E_distance == 1
figure, imshow('dar.jpg');
% w=imread('6.jpg');
% figure;
% imshow(w);
end
guidata(hObject, handles);
axis equal;
axis tight;
axis off;
the ans in cammand window is 0, but show the the pic which is in else block.. check my codee plzz
Image Analyst
on 26 Jul 2014
I already answered that in your duplicate question.
More Answers (0)
See Also
Categories
Find more on Image Data Workflows in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)