How to caculate x,y coordinates in a contoured region

7 views (last 30 days)
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.

Accepted Answer

Image Analyst
Image Analyst on 6 Sep 2013
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
Image Analyst
Image Analyst on 16 Sep 2013
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.
Muhammad
Muhammad on 16 Sep 2013
Edited: Muhammad on 16 Sep 2013
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.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!