Maxxx
Maxxx

Reputation: 3768

Indexing image according to polar coordinates?

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).

Upvotes: 0

Views: 257

Answers (1)

avermaet
avermaet

Reputation: 1593

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?

Upvotes: 1

Related Questions