I have one jpg file. I want to get all the points in (x,y) coordinate format in excel sheet. What is the command required for it.

I have one jpg file. I want to get all the points in (x,y) coordinate format in excel sheet. What is the command required for it.

Answers (1)

[X, Y] = meshgrid(1:size(YourMatrix,2), 1:size(YourMatrix,1));
XY = [X(:),Y(:)];
now the coordinates are in the 2-D column vector XY, which you can xlswrite()
Are you sure you didn't want to write out the values of the locations rather than the coordinates?
JPEG files are always truecolor files, never indexed or grayscale, so each location is associated with 3 values, the red, green, and blue components. How would you like to deal with that?

3 Comments

I did not understand your explanation. How to get the "YourMatrix" from image file. Suppose I have jpg file that contains a boundary of brain segmentation. I want to get the matlab function which can read the image file and give the matrix which contains (x,y) coordinates of all points present in the image file.
YourMatrix = imread('YourImageFileName.jpg');
[X, Y] = meshgrid(1:size(YourMatrix,2), 1:size(YourMatrix,1));
XY = [X(:),Y(:)];
xlswrite('TheOutputFile.xls', XY);
By the way, it is not a good idea to use JPEG files to store data such as you have. The JPEG format is inherently "lossy" and will smear the boundaries that you have created. You should use a TIFF or PNG file.
I suspect, though, that you would be much happier with finding only the non-zero content if your image rather than all points in your image.
threshold = 0.01; %adjust as needed
YourMatrix = imread('YourImageFileName.jpg');
image_gray = rgb2gray(im2double(YourMatrix));
[Y,X] = find(image_gray > threshold); %not [X,Y] !
XY = [X(:),Y(:)];
xlswrite('TheOutputFile.xls', XY);
Note the [Y,X] output of find() rather than [X,Y]. find() returns row then column, but row corresponds to Y rather than X

Sign in to comment.

Categories

Find more on Convert Image Type in Help Center and File Exchange

Products

Asked:

on 10 Aug 2015

Commented:

on 11 Aug 2015

Community Treasure Hunt

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

Start Hunting!