0

I am new to Matlab. I have an image (the size is mxnx3) with a few human-selected points on the image. For example:

p1 = [267,79];

p2 = [96,372];

These points are image coordinates with (1,1) at the top left. I'm trying to convert this to Cartesian coordinates with (0,0) on the bottom left. How can I do this? Thanks in advance!

Luis Mendo
  • 110,752
  • 13
  • 76
  • 147
user3006887
  • 71
  • 1
  • 8

2 Answers2

1

If I understand correctly: just use

axis xy

From axis doc:

AXIS XY puts MATLAB into its default "Cartesian" axes mode. The coordinate system origin is at the lower left corner. The x axis is horizontal and is numbered from left to right. The y axis is vertical and is numbered from bottom to top.

Luis Mendo
  • 110,752
  • 13
  • 76
  • 147
  • Definitely the right way to flip the axes, but I don't understand the (1,1) -> (0,0) thing in the question. I guess that's a typo? – chappjc Nov 19 '13 at 01:27
  • not a typo! i'm studying this webpage for 2d rigid registration, but i'm not understanding the code for flipping the coordinates: http://dominionsw.com/wordpress/?p=111 – user3006887 Nov 19 '13 at 15:43
0

If you need to directly translate your co-ordinates in code, you could make a simple anonymous function:

img2cart = @(p) [p(1), img.size(2) - p(2)];
q1 = img2cart(p1);
q2 = img2cart(p2);
paddy
  • 60,864
  • 6
  • 61
  • 103
  • I'm sorry if this is a dumb question. I'm a beginner! I'm still confused by the function. Can you please explain:[p(1), img.size(2) - p(2)]?? Thanks! – user3006887 Nov 19 '13 at 15:39
  • If i understand correctly, this means that the original image x is used as the cartesian x. then the y value is determined by subtracting y from the number of image rows. – user3006887 Nov 19 '13 at 15:56
  • Yep, you've got it. Also, because `img` is not a parameter to the function, its current value at the time the function was created is sort of "burned-in" to the function. If you want something more general, define the function with `@(p,img)` *ie* pass `img` as the second parameter whenever you call it. – paddy Nov 19 '13 at 20:46