MATLAB Answers

0

Coordinate system of matlab

Asked by Stewart Tan on 18 Aug 2019
Latest activity Commented on by Matt J
on 18 Aug 2019
I drew a visualization below (sorry for bad drawing)
Capture.PNG
and its an 800x533 rectangle. Correct me if I'm wrong, but in Matlab, the image would be 533x800 when read in, so i assume that it is of form [row, column] where row = 533 and column = 800. However, i read that Matlab uses two types of coordinate systems which i find really frustrating and confusing at the same time.
Normally, the coordinate system is (x,y) where x is the axis along the row(horizontal) and y is the axis along the column(vertical), but i read that Matlab coordinate system is actually (y,x)? Does it mean that instead of [row,column], its [column,row] instead?
I've drawn a tiny blue indicator on the red blocks in the image, if i want to find the coordinate of the top-left corner of each red block(blue indicator), would it be as so:
for i=1: num_block_row
for j=1: num_block_col
coor = [j,i]; %instead of i,j
disp(coor)
end
end
Also, I'm not sure if indices can actually be used as coordinates of each blocks in the image, so do inform me if I'm wrong.

  0 Comments

Sign in to comment.

1 Answer

Matt J
Answer by Matt J
on 18 Aug 2019
Edited by Matt J
on 18 Aug 2019
 Accepted Answer

However, i read that Matlab uses two types of coordinate systems which i find really frustrating and confusing at the same time.
The different toolboxes of Matlab are written to support different technical fields and different technical fields will inevitably have different coordinate conventions. The 2 different coordinate systems you are refering to are particular mainly to the Image Processing Toolbox (and maybe also the Computer Vision Toolbox) and are explained in more detail here,
Does it mean that instead of [row,column], its [column,row] instead?
The way data in a matrix variable is accessed in Matlab is a property of the variable type. If, as is normal, you use one of Matlab's basic matrix variable types to represent an image, A, then the data in A is always accessed by subscripting expressions of the form A(row, column). This form is the common convention in linear algebra. It is not common in image processing, but Matlab has no idea that you want to use the matrix to represent an image until you start giving A as input to Image Processing Toolbox functions.
Conceivably, you could define your own image variable type, whose subscripting syntax is A(column, row), but then you would have to write your own tools and functions to analyze these custom image variables, because the Image Processing Toolbox functions expect your input images to be of one of Matlab's native matrix types.
if i want to find the coordinate of the top-left corner of each red block(blue indicator), would it be as so:
You haven't said what the red blocks represent. Individual pixels? Sub-blocks of pixels? ...
If you want the intrinsic coordinates (x,y) of the upper left corner of pixel A(i,j), this would be
x=j-0.5;
y=i-0.5;
Note also that you can attach whatever world spatial coordinate system to an image that you want using an imref2d object. These objects have methods that let you convert back and forth between pixel subscripts, intrinsic coordinates, and world spatial coordinates, e.g.,
Robject=imref2d(size(A));
[i,j] = Robject.worldToSubscript(x,y);
[x,y] = Robject.intrinsicToWorld(j,i);

  2 Comments

@Matt J thank you and yes, it would be individual pixels.
Matt J
on 18 Aug 2019
You're welcome but please Accept-click the answer if it addressed your question.

Sign in to comment.