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.
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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.
0 Commenti
Risposte (1)
Walter Roberson
il 10 Ago 2015
[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 Commenti
Walter Roberson
il 11 Ago 2015
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
Vedere anche
Categorie
Scopri di più su Import, Export, and Conversion in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!