How to convert matrix indexes to cartesian coordinates

조회 수: 28 (최근 30일)
Tchilabalo
Tchilabalo 2019년 8월 24일
댓글: Tchilabalo 2019년 8월 25일
Capture.JPG
Given a matrix a shown above, i want to convert the cell indexes into cartesian coordinates. I am trying to figure out what these indexes represent: is it the center of the cell? or the left corner of the cell? Thanks.
  댓글 수: 2
TADA
TADA 2019년 8월 24일
It's both, it's neither... If this is for visualization, I'd prefer the center of the cell But generally its up to you to decide
Tchilabalo
Tchilabalo 2019년 8월 25일
Thanks TADA.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2019년 8월 24일
Matrices are just arrays of values and there is no inherent Cartesian coordinates associated with them. They have rows and columns, not x and y.
If you use imshow() or image() or imagesc() to display an image, then you have the option to control how rows and columns map into data units. The default is a 1:1 mapping. The default for all three functions is that X=1 Y=1 will correspond to the center of the bottom left pixel and that X=columns Y=rows maps to the center of the upper-right pixel. Because the center are being referred to, the image would cover from (1/2,1/2) to (columns+1/2, rows+1/2)
There are other possibilities, such as georefferencing through the Mapping Toolbox, which provides some flexibility as to what coordinates mean, possibly including nonlinear projections. In such cases the person who created the dataset should have documented the transformation.
It is common for people to get confused with images and think that there should be a way to convert pixels into real world coordinates. Sometimes there are ways, but unless you are using a calibrated device such as MRI or confocal microscope, even if image has the appropriate headers then the headers are typically pretty wrong.

추가 답변 (1개)

David Hill
David Hill 2019년 8월 24일
n=3;%nxn matrix
a=1:n^2;
x=floor((a-.1)/n)+1;
y=mod(a,n);
y(find(y==0))=n;
plot(x,y,'LineStyle','none','Marker','o',"Color",'b');

카테고리

Help CenterFile Exchange에서 Modify Image Colors에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by