crop the image(show in axses)
1 次查看(过去 30 天)
显示 更早的评论
reema
2014-6-2
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
采纳的回答
Image Analyst
2014-6-2
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 个评论
reema
2014-6-2
SIR,its another question..i want to crop the face which is show in axes6 and show the cropped face in next axes7...can you understand?
reema
2014-6-2
and i accept the answer if i get the solution....if i don't get the ans then how can i accept the ans?
Image Analyst
2014-6-2
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.
reema
2014-6-4
sir tell me now about the function ..me embed this with my code but have error ..
Undefined function 'ExtractNLargestBlobs' for input arguments of type 'double'.
reema
2014-6-4
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?
Image Analyst
2014-6-4
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.
Image Analyst
2014-6-5
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
2014-6-6
编辑:reema
2014-6-6
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
2014-6-6
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
2014-6-7
编辑:reema
2014-6-7
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
2014-6-7
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
2014-6-7
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
reema
2014-6-8
sir now i want to pass the detected face to the next GUI's axes for recognition processs..how can i pass it teell me
Image Analyst
2014-6-8
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.
reema
2014-6-8
sir give me the documentation about ExtractNLargestBlobs()..i want too study about this function.
Image Analyst
2014-6-8
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
2014-6-8
sir me read your comment i undesatnd the comments and working of that funation..but i want too knw who define this function..if its a algorithm then who is the inventor of this algorithm
reema
2014-6-8
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
2014-6-11
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.
reema
2014-7-8
sirr can youu givee me the code of passing the image from one GUI to the other GuI's axes?
Image Analyst
2014-7-8
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
2014-7-13
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
2014-7-13
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
2014-7-14
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
2014-7-14
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
2014-7-19
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
2014-7-25
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)