0

So I'm trying to transform an image coordinate which is the ordinary square x,y coordinate to a circular coordinate as shown below.

enter image description here

In order to do so, the center of the square image must be the origin which is 0 in the circular coordinate system.

In Matlab they have a function called 'cart2pol' where:

cart2pol(x,y)

However, the x,y argument are the circular coordinates hence before using cart2pol, how do i convert the ordinary square coordinate system to a circular one?

Maxxx
  • 3,688
  • 6
  • 28
  • 55
  • https://stackoverflow.com/questions/20924085/python-conversion-between-coordinates andy help from this ? Its in python, still you can easily transform the code to matlab ? – venkata krishnan Aug 28 '19 at 02:34
  • 1
    `However, the x,y argument are the circular coordinates` - no they're not. They're the cartesian (square) coordinates. Is there still a question after correcting this misapprehension? – Will Aug 28 '19 at 11:12
  • 1
    "_However, the x,y argument are the circular coordinates_" ... not at all, actually the opposite: in the full form `[theta,rho] = cart2pol(x,y);`, `x` and `y` are the **cartesian** coordinates (inputs), and the function will return `theta` and `rho` as **polar** coordinate (in output). This is exactly what you are asking. – Hoki Aug 28 '19 at 11:13
  • "the center of the square image must be the origin which is 0 in the circular coordinate system"... So subtract the center from the Cartesian coordinates like `[i - floor(N/2), j - floor(N/2)]` before calling `cart2pol`. – beaker Aug 28 '19 at 15:16

1 Answers1

0

I think you should be able to use cart2pol(x,y), which gives you the polar (2d) or cylinder (3d) coordinates for some cartesian inputs x and y (and z for cylindrical).

Coordinates in your 1st image: i, j. Coordinates in your 2nd image: theta, rho.

N = 400; % example: 400x400 pixels

% shift origin into center
% Matlab uses 1 to N indexing not 0 to N-1
xo = (N)/2; % center of image
yo = (N)/2;

% Define some sample points in the image (coords from top-left of image)
% 0 deg, 90 deg, 180 deg, 270 deg
i = [350 200 50 200];
j = [200 1 200 350];

% get polar coordinates from cartesian ones (theta in radians)
% -(j-yo) due to opposite direction of j to mathematical positive direction of coord.system
[theta, rho] = cart2pol(i-xo, -(j-yo));
rho = rho/(N/2); % scaling for unit circle

theta is in the range -pi to pi, so if you need 0 to 2pi or 0 to 360 you still need to do a mapping.

avermaet
  • 1,543
  • 12
  • 33
  • thank you. Looking at line 84 up to 89 in https://github.com/amirtahmasbi/matlab-zernike-moments/blob/master/classes/%40zernike/zernike.m i notice that he predefine the range of x and y at line 85 and 86. Now, if my M and N are both 8, and i print line 85 and 86, why are the range as so? – Maxxx Aug 29 '19 at 11:12
  • i do know however, he's trying to squeeze the range between -1 and 1, but is there any reason to stick with the formula -1+1/M:2/M:1-1/M; and -1+1/N:2/N:1-1/N;? – Maxxx Aug 29 '19 at 11:14
  • I think this formula was just used for a linear spacing between -1:1. And I assume also a different spacing in this region will work. But I have no experience with these polynomials, so can't say for sure. – avermaet Aug 29 '19 at 19:37