フィルターのクリア

How to convert an image to the cartesian X,Y coordinates?

23 ビュー (過去 30 日間)
George
George 2013 年 6 月 19 日
編集済み: John Kelly 2014 年 5 月 27 日
I have a grayscale image and i want to convert to the cartesian X,Y coordinates
  2 件のコメント
Matt J
Matt J 2013 年 6 月 19 日
編集済み: Matt J 2013 年 6 月 19 日
Here is a small 3x3 example of a grayscale image
>> A=diag(randi(255,1,3))
A =
233 0 0
0 162 0
0 0 25
What would be the result of the "conversion" you are looking for in the case of this image.
George
George 2013 年 6 月 19 日
1 1 233
1 2 0
1 3 0
2 1 0
2 2 162
2 3 0
3 1 0
3 2 0
3 3 25

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

採用された回答

Matt J
Matt J 2013 年 6 月 19 日
編集済み: Matt J 2013 年 6 月 19 日
[x,y]=meshgrid(1:size(A,1), 1:size(A,2));
result=[x(:),y(:),A(:)];
  3 件のコメント
Matt J
Matt J 2013 年 6 月 19 日
編集済み: Matt J 2013 年 6 月 19 日
Read in as type double
A=double(imread('moon.tif'));
and then,
result=[x(:),y(:),A(:)];
>> max(result)
ans =
537 358 253
George
George 2013 年 6 月 19 日
thank you very much Matt J!!!

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

その他の回答 (2 件)

Alex Taylor
Alex Taylor 2013 年 6 月 19 日
編集済み: John Kelly 2014 年 5 月 27 日
If what you are trying to do is reference a 2-D image to a cartesian coordinate system, you should look at the class imref2d that ships with the Image Processing Toolbox as of R2013a
For example, if you want to reference the image A that Matt mentioned to the default (Intrinsic) coordinate system used by MATLAB in which the center of the first pixel is located at position (1,1) and each pixel has an extent of one unit, you could use the following syntax of imref2d:
A=diag(randi(255,1,3));
imref2d(size(A))
ans =
imref2d with properties:
XWorldLimits: [0.5000 3.5000]
YWorldLimits: [0.5000 3.5000]
ImageSize: [3 3]
PixelExtentInWorldX: 1
PixelExtentInWorldY: 1
ImageExtentInWorldX: 3
ImageExtentInWorldY: 3
XIntrinsicLimits: [0.5000 3.5000]
YIntrinsicLimits: [0.5000 3.5000]
imref2d also provides other construction syntaxes and writable properties if you want to reference your image to some other cartesian system.
imref2d provides various methods for converting two and from image subscripts and locations in a continuous cartesian system:
>> methods(imref2d)
Methods for class imref2d:
contains intrinsicToWorld worldToIntrinsic
imref2d sizesMatch worldToSubscript

Jeff E
Jeff E 2013 年 6 月 19 日
編集済み: Jeff E 2013 年 6 月 19 日
Unimaginative solution below, possibly with extra computational overhead than a direct solution using reshape and some simple calculations for the X,Y cooridnates.
A=diag(randi(255,1,3))
A =
10 0 0
0 226 0
0 0 233
>> B = true(size(A))
B =
1 1 1
1 1 1
1 1 1
stats = regionprops(B, A, 'PixelValues' , 'PixelList');
PixelListValues = cat(2, [stats.PixelList] , [stats.PixelValues])
PixelListValues =
1 1 10
1 2 0
1 3 0
2 1 0
2 2 226
2 3 0
3 1 0
3 2 0
3 3 233
  1 件のコメント
George
George 2013 年 6 月 19 日
A=imread('moon.tif');
B = true(size(A));
stats = regionprops(B, A, 'PixelValues' , 'PixelList');
PixelListValues = cat(2, [stats.PixelList] , [stats.PixelValues])
x,y counting stop to 255

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

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by