Reverse Input Image coordinates

6 vues (au cours des 30 derniers jours)
Cyrus
Cyrus le 13 Mai 2016
Why does MATLAB get input image coordinates as (Y,X), but shows that as (X,Y), I don't get the reason of that. Isn't it better to keep consistency?

Réponses (3)

Guillaume
Guillaume le 13 Mai 2016
That's because Mathworks couldn't stick to just one coordinate system, and that's very maddening.
Because an image is a matrix and matrices in matlab use (row, column), in that order, this is what you use for adressing pixels in images. However, traditionally, people use X and Y to refer to image coordinates with X being the horizontal coordinate and Y the vertical (pointing down), so mathworks decided to use that coordinate system for the output/input of some of their functions. The two systems differ in the ordering of the dimension.
I don't know why they couldn't stick to one. It's completely absurd in my opinion and very confusing when you combine output of functions that don't use the same system (e.g. bwboundaries returns (row, column) coordinates, regionprops returns (x,y) coordinates)
I would advise you to always name your variables (row, column) never (y, x), it makes more sense in matlab.
And for fun have a look at the code of regionprops, mathworks is constantly swapping the 1st and 2nd column of their coordinate matrix because of that.

Azzi Abdelmalek
Azzi Abdelmalek le 13 Mai 2016
Im=imread('Your_image')
imshow(Im)
Matlab reads your image and displays it as it is displayed by any images editor. Matlab reads the matrix representing your image. The coordinates (1,1) in a Matrix is located in the left top, and the coordinate (end,end) is in the right botom of your matrix. What is the problem with that?
  2 commentaires
Cyrus
Cyrus le 13 Mai 2016
Thanks for your response, the problem is that if I want to make the coordinate x= 20, y = 30 as a white pixel on a bw image I should use this command: I(30, 20) = 1, but If I use impixelinfo and move the mouse over it, it shows (20, 30) 1
Guillaume
Guillaume le 13 Mai 2016
The problem is that many functions in matlab will return a 2 column matrix of coordinates where the 1st column is x and the 2nd is y. If you want to then use these coordinates to index the image you've got to swap them around, since matlab indexing uses (row, column)
It's an illogical step. Sticking to one coordinate system would make a lot more sense.

Connectez-vous pour commenter.


Walter Roberson
Walter Roberson le 13 Mai 2016
ginput() and all the other functions that deal with coordinates use the x, y order.
However, indexing of arrays uses the y, x order.
There are two major ways to express indexing of arrays in computer programming. One of them, "row major order", says that the first index should refer to the distance "across", which is the column number, and the second index should refer to the distance "down", which is the row number. C and C++ use "row major order". The other major way, "column major order", says that the first index should refer to the distance "down", which is the row number, and the second index should refer to the distance "across" which is the column number. MATLAB uses "column major order".
There is no right or wrong about using row major order or column major order in designing a programming language. Historically, MATLAB was developed around FORTRAN, which was column major order, so MATLAB uses that.
Humans use both for different purposes. For tables of data, humans tend to use column major order. For example if there was a database of names and addresses and ages, then people looking up "Mohammad Taheri" would tend to go to the row for "Mohammad Taheri" and from there would look across to the age, instead of finding the column for ages and then trace down from there until they found the row for "Mohammad Taheri" -- doing so is less thinking effort for everything other than the first column (which is typically the sort column.)

Catégories

En savoir plus sur 3-D Volumetric Image Processing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by