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 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Walter Roberson
le 10 Août 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 commentaires
Walter Roberson
le 11 Août 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
Voir également
Catégories
En savoir plus sur Import, Export, and Conversion dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!