Reverse Input Image coordinates
9 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(3 个)
Guillaume
2016-5-13
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.
0 个评论
Azzi Abdelmalek
2016-5-13
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 个评论
Guillaume
2016-5-13
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.
Walter Roberson
2016-5-13
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.)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!