0

Ok, this might be a little dumb to ask but I'm really having a hard time understanding the image coordinates in Matlab.

So, in a mathematical equation, f(x,y) f is the image function where x and y are the coordinates of the image. For example, in matlab code, we can:

img = imread('autumn.tif');
img(1,4); %f(x,y)

where img(1,4) is equivalent to the function f(x,y). Now, in Matlab, there is an option to convert the cartesian coordinate (x,y) to polar coordinate (rho,theta) with cart2pol() function.

Now, here's where I don't understand. Is it possible to apply f(rho,theta) which is the polar coordinates instead of the cartesian coordinate in Matlab?

I tried doing something like:

img(2.14,1.5) 

But I get the error message saying about array indexing is only supported with integers or logical values.

Could anyone clear up my understanding on this? Because I'm required to apply f(rho,theta) instead of the conventional f(x,y).

Maxxx
  • 3,688
  • 6
  • 28
  • 55
  • 1
    It's not possible to use the polar coordinates directly. You would have to convert to cartesian coordinates, usually with `pol2cart()`, and then perform some sort of interpolation as the results will likely be non-integers. Depending on the number of queries, you *might* consider transforming the entire image, but then again you would have to interpolate non-integers. – beaker Aug 31 '19 at 14:10

1 Answers1

1

An image in Matlab is basically just an 2D array (if you consider just a greyscale image). Therefore you also need integer indices, just as for all other arrays, to access the pixels of the image.

% i,j integers, not doubles, floates, etc.
pixel = img(i,j);

The polar coordinates from yor last question (theta, rho) can therefore not be used to access the image array. That is also the exact reason for the error message. At least you'd need to round them or find some other way to use them as indices (e.g. convert them back to cartesian coords. would be best, due to matrix indexing)

Regarding your application: As far as I have found out, these polar coordinates are used as parameters for the Zernike polynomials. So why would you use them to access the image?

avermaet
  • 1,543
  • 12
  • 33
  • yes, in fact in the wikipedia page that you linked, if you take a look at the definitions section of "radial polynomials", the image f(x,y) will be mapped(inner product) onto the radial polynomial, but the problem is that f(x,y) is integer, where as the radial polynomial is double, hence the product is not possible unless i do something like double(f(x,y)) which works but I'm having a doubt if it is right since it wasn't mentioned in the pseudocode of a paper I'm analysing. – Maxxx Aug 31 '19 at 14:18
  • I'm sorry but I don't find f(x,y) there. I think you just build the polynomial and if you display/evaluate it for some region, you can derive the images depicted. `R_n^m(rho)` can be build without the image and I think also `Z_n^m(rho,theta)`. Please elaborate further ... – avermaet Aug 31 '19 at 14:30