# How to minimize the artefact of a cartesian to polar transform followed by a polar to cartesian transform?

I'm transforming cartesian images into polar images. (x,y) => (angle, radius)

I fill the polar image by iterating on each of its pixels and filling them by doing the reverse polar transform. For a given (angle, radius) pair, I'm interpolating in the source cartesian image at the following location:

xcartesianpoint = cos( angle ) * radius + center.x;
ycartesianpoint = sin( angle ) * radius + center.y;


(I do some computation with the polar image)

Then I transform back the polar image in cartesian coordinates. Again, I'm filling the destination image by doing the inverse transformation. For a given (x,y) point, I'm interpolating the value from the polar image point located at:

angle  = atan2(ycartesianPxl, xcartesianPxl) + M_PI;

xpolarpoint = angle /_angleStep; // give the index in the polar image corresponding to the angle


The points indexes are floating point values that I use to interpolate in the source image of the given transformation.

This code works well but give artifacts like those (first image is the source, second is the transformed source in polar transformed back in cartesian. The artifacts are more apparent on the pixels far from the center):

Edit

What I do with my polar images:

I'm polar transforming the source image with the goal of blurring it. This is done to get zoom/spiral like blurs. The blurring is done by doing an FFT of the polar image which is transformed back. The artifact wouldn't be a problem if the whole image was blurred, but it is possible for the user to specify a gain matte that modulates the blur radius for each pixel. So, some pixels may be fully blurred and others not at all.

• The artifact is not apparent to me. Can you point it out? Jul 27 '14 at 16:55
• You can see them in the second image. They are the more apparent the further you are from the center. Look at the black line at the end of the trump. Jul 28 '14 at 15:45
• Did I just get elephant-rolled?
– k20
Jul 28 '14 at 23:52

Since the underlying grid for your polar representation becomes coarser in the circumference as you go further from the center, it's not surprising you get artifacts there. My simplest suggestion then would be to just use many more pixels in the polar representation.

It's not clear to me how you are "interpolating" from the code you provided. Are you simply taking the value from the nearest pixel? A least-squares interpolation would likely be better - for a given pixel you want to find the color for, find the 4 surrounding pixels of the previous image and compute an average weighted by the inverse of their distance.

I can think of three options:

1. Significantly increase the resolution of your polar representation.
2. Instead of a linear interpolation, create spectral representations of the images (e.g. by FFT). This will be considerably more accurate.
3. Apply a blurring/gaussian filter to the final image or anti-aliasing. This won't actually improve the quality of the transformation, but it will get rid of the jagged border edges.
• To create the second image, I used a polar image 4 times the resolution (width x 2 X height x 2) of the source image. I used a linear interpolation (by using neighbors top/down right/left) to get the pixels values of my polar images as well as my cartesian image. I guess this makes less sense for the polar to cartesian transformation as the reverse lookup can fit entirely in one polar pixel for pixels far from the center. Jul 29 '14 at 0:28
• See my edit above. Even 4x resolution probably won't cut it, because you end up with very coarse cells in the circumferential direction far from the centroid. Jul 29 '14 at 14:29
• Thanks for the answer. I really need to have a result that is as close as possible to the source, so option 3 isn't possible in my case (I can have images with a high level of details and this wouldn't make it). With option one, even with intermediate image 25 times bigger than the source I still get, less noticeable, artifacts. I'm very interested by option 2. How can spectral representations of the images help? (see the edit for more information on what I do with the polar image). Jul 29 '14 at 23:20
• A spectral representation will allow you to create a much more accurate interpolation than you can with a linear interpolation between points. Jul 30 '14 at 0:15