Dan Snyder
Dan Snyder

Reputation: 1519

Convert Polar Image to a Cartesian Image

I am attempting to convert an image in polar coordinates (axes are angle x radius) to an image in cartesian coordinates (axes are x and y).

This is simple enough in matlab using pcolor() but the issue is that I must do this in a mex file (c++ interface to Matlab). This seem's easy enough except that Matlab ONLY uses array containers so I can't think of a clever or eloquent way of doing this.

I do have access to the image dimensions and I can imagine a very messy way of repackaging the input image array as a matrix in C++ and carying out the conversion but this would be messy and problematic.

Also, I need to be able to interpolate gaps between points in the xy plain.

Any ideas?

Upvotes: 0

Views: 2684

Answers (1)

Chris A.
Chris A.

Reputation: 6887

This is reasonably standard in image processing, particularly in registration. However, it takes some thought and isn't "obvious". It wasn't obvious to me the first time either.

I'm assuming you have two images, in different "domains", in your case a source image in polar coordinates and a target image in Cartesian coordinates. I'm assuming you know the region in the target image you want to populate.

The commonly known best thing to do in image processing is to loop over coordinates in the known area of the target image that you want to populate. For each of these positions (x,y), you'll have some conversion to polar. It's probably r = sqrt(x*x+y*y) and theta = atan2(y,x) or something like that. Then you sample from that position in the polar coordinate position with interpolation.

Among choices of interpolation are:

  1. Nearest neighbor - you just round to the nearest r and theta and choose the value of that.
  2. Bilinear -
  3. Bi-cubic
  4. ...

Of course you should take care of boundary conditions and what happens if your r and theta go out of your image.

This procedure also is similar (looping over the target image and sampling from the source image, and doing lookups based on the reverse transform) for all kinds of coordinates transformations. The nice thing is that you don't leave holes where your source imagine is relevant.

Hope this helps with the image part.

As for the mex part, here's some links: Mex tutorial Mex tutorial

Can you be more specific about what you need about the mex part?

Upvotes: 3

Related Questions