MATLAB Answers

0

How to caculate x,y coordinates in a contoured region

Asked by Muhammad on 6 Sep 2013
Hello All
Hope yopu are all good. i have a question i used the code below. i contoured the region by imfreehand tool. i want to calculate the coordinates( x, y,z) in this region which i contourd. i can calculate the coordinates on the line which is made by imfreehand by ginput. but i need the coordinates which are in the contoured region.
% Display a file
I = imread('cat.jpg');
imshow(I);
zoom on; % use mouse button to zoom in or out
% Press Enter to get out of the zoom mode. % CurrentCharacter contains the most recent key which was pressed after opening % the figure, wait for the most recent key to become the return/enter key
waitfor(gcf,'CurrentCharacter',13) zoom reset zoom off imfreehand
% the figure, wait for the most recent key to become the return/enter key
imfreehand(gca,'closed',0) end
Any help is appreciated in advance.

  0 Comments

Sign in to comment.

1 Answer

Answer by Image Analyst
on 6 Sep 2013
 Accepted Answer

Explain why you think you need the (x,y) coordinates of all the pixels inside the hand drawn region, rather than just the boundary coordinates. I've never needed them and suspect you don't really need them either. I know how to get them, but I don't want to send you down an unproductive path for no reason.

  16 Comments

Dear Respected Dr., i tried but i did not understand. now i am reached at this point.when i contour some part of image then i cannot find the coordinates [Y,X]on the workspace. i cant find any thing on the workspace.my code is given below for creat excel sheet. i want that when i press Excelpushbutton then allthe [Y,X] values will come on the excel sheet or spreadsheet. also what will be the unit of these [Y,X] coordinates?is thes mm or cm? i have thickness between the slice is 0.18mm,which is my z coordinate. am i right?
if true
function ExcelPushbutton_Callback(hObject, eventdata, handles)
imshow(handles.maskedImage)
[Y, X] = find(handles.maskedImage ~= 0);
data=[Y,X];
end
hoping for early response. Isa
Not sure what you want to do. I'm not sure what "will come on the excel sheet" means. Instead of "come on" do you mean "come from" or "go to"? Call xlsread() if you want to retrieve values from a workbook. Call xlswrite() if you want to send values to a workbook.
when i applies the below code on a image like cat image then i can find [Y,X] coodinates on spread sheet with name of data that contains 2 arrays having Y and X values. X and Y seprately also available as a spread sheet in workspace. these values are the coordinates of each pixel inside the contoured region. but when i made interface then i cant find that spread shee on work space.
if true
I = imread('cat.jpg');
imshow(I);
% image;
zoom on; % use mouse button to zoom in or out
% Press Enter to get out of the zoom mode.
% CurrentCharacter contains the most recent key which was pressed after opening
% the figure, wait for the most recent key to become the return/enter key
waitfor(gcf,'CurrentCharacter',13)
zoom reset
zoom off
% imfreehand
% the figure, wait for the most recent key to become the return/enter key
h=imfreehand(gca,'closed',0);
pos = getPosition(h);
sz = size(I);
maskedImage = poly2mask(pos(:,1), pos(:,2), sz(1), sz(2));
[Y, X] = find(maskedImage ~= 0);
data=[Y,X];
end
Now i think you will better understand. thnaks in advance.

Sign in to comment.