フィルターのクリア

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.

4 ビュー (過去 30 日間)
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.

回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 8 月 10 日
[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 件のコメント
Lukas Bystricky
Lukas Bystricky 2015 年 8 月 11 日
When you say "points" what exactly do you mean?
Walter Roberson
Walter Roberson 2015 年 8 月 11 日
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

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImport, Export, and Conversion についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by