Question about coordinate system in matlab
1 次查看(过去 30 天)
显示 更早的评论
Hi, i'm a beginner in Matlab and currently is doing a project related to image processing. For some reason, i have encountered many problems from the coodinating system in Matlab due to not very familiar with it. Is there anyone is kind enough to explain about it?
I would like to know more about few topic as listed below: pixel coordinate in image, [x,y] coordinate in image, row colunmn in image,
And how to do conversion between them
Thank you in advance.
0 个评论
回答(4 个)
Guillaume
2014-11-6
This page out of matlab's doc explains most of it.
Personally, I think that Mathwork royally screwed up on this. You basically have two different coordinate systems and some functions work in one and some in the other. There may even be some functions that take inputs in one and return output in the other.
You have a set of function that use the [row, column] system (e.g. find). Origin is top-left corner. row increases as you go down, column as you go right. The other set of functions (e.g. mesghrid) use [x, y] with origin in the top left corner, x goes right and y goes down. You convert from one to the other by swapping the order of the two.
Then, you have the absurdity that is regionprops bounding box, whose coordinates of the corners are fractional (always integer + 0.5) because mathworks differentiate between the centre of a pixel (integer coordinates) and its corner.
Regardless of the coordinate system returned in the output of a function, you always access pixels with the [row, column] system.
0 个评论
Image Analyst
2014-11-6
Since youi're just starting, please see my tutorials in my File Exchange, particularly the one on image segmentation.
You always need to be careful about row,column and x,y. It's a very common mistake because MATLAB uses both everywhere, not just in image processing. People often get some coordinate in the form (x,y) and then try to access the pixel in their array using grayImage(x,y). As the others pointed out, that won't work because the first index is the row, and x is not the row. So if you want that (x,y) pixel you'll have to do grayImage(y, x) NOT grayImage(x,y).
To get pixel coordinates in real world coordinates (like cm or meters) you'll need to do a spatial calibration. See my attached demo.
0 个评论
Youssef Khmou
2014-11-6
You can start inspecting the x,y values in sample, to get an idea try :
>>imshow('circuit.tif')
Then go to Tools in menu bar of the figure, then click on Data Cursor, when you click on point in the image the (x,y,intensity) is shown .
0 个评论
MR. W
2014-11-7
3 个评论
DGM
2023-2-20
The problem here is the misuse of plot(). The first two arguments to plot should be x and y, not point1 and point2.
FWIW, this is one way to approach this sort of thing.
% an image
inpict = imread('peppers.png');
% it's often convenient to specify points in normalized coordinates
% by having all the points in the same array, the code stays neat ...
points = [0 0.5; % [y x]
1 0.5];
% denormalize to get image coordinates
sz = size(inpict);
points = points.*(sz(1:2)-1) + 1;
% plot things
imshow(inpict); hold on
plot(points(:,2),points(:,1),'c'); % ... and it's easy to split x and y
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!