# Thread: Pixel Transform: Cartesian to Polar

1. Member
Join Date
Mar 2015
Location
A Place With Windows
Posts
71
Rep Power
0

## Pixel Transform: Cartesian to Polar

Hey guys, I'm working on a project where I need to transform a traditional image into a polar image (Rectangular|--->Circular).

Suggestions? Anyone have experience with this type of idea? It's my assumption there is some known algorithm that I could apply here, or some method that I am unaware of.

-Thanks!

2. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
6,226
Rep Power
13

## Re: Pixel Transform: Cartesian to Polar

If you want to rotate the image a certain number or radians you can apply a rotational transform to a graphics instance.

Regards,
Jim

3. Member
Join Date
Mar 2015
Location
A Place With Windows
Posts
71
Rep Power
0

## Re: Pixel Transform: Cartesian to Polar

Not to rotate, but instead mutate/transform.... I want to go from an image that is rectangular to circular. [ ] ----> ( )

4. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
6,226
Rep Power
13

## Re: Pixel Transform: Cartesian to Polar

Originally Posted by MattTuck
Not to rotate, but instead mutate/transform.... I want to go from an image that is rectangular to circular. [ ] ----> ( )
That doesn't really tell me much. going from (x,y) to (r, theta) doesn't change the image, only the manner in which one references a given point. If you want to morph your image somehow, you might apply a home grown implementation of AffineTransformOp.

Regards,
Jim

5. Member
Join Date
Mar 2015
Location
A Place With Windows
Posts
71
Rep Power
0

## Re: Pixel Transform: Cartesian to Polar

Something like this

6. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
6,226
Rep Power
13

## Re: Pixel Transform: Cartesian to Polar

I have never done that before (it looks similar to an anamorphic projection). Here is a link I found which has some code (not Java). It may offer some help.

Polar To/From Rectangular Transform of Images - File Exchange - MATLAB Central

Regards,
Jim

7. ## Re: Pixel Transform: Cartesian to Polar

Rectangular coordinates (x,y) can be written in polar form as (r*sin(phi), r*cos(phi); you want coordinates (r, phi); note that r^2 == x^2+y^2 and phi == atan(y/x)

kind regards,

Jos

8. Member
Join Date
Mar 2015
Location
A Place With Windows
Posts
71
Rep Power
0

## Re: Pixel Transform: Cartesian to Polar

Assuming I wrote it that way, all of my pixles will stay in the same place...they'll just be described in a polar form where r^2=x_max^2+y_max^2 and phi ranges from [0,90].

I want to actually mutate the image. To move the pixel in (0,0)Java-cart(note: (0,0) is in the top left corner) to (r_max,0)polar

9. ## Re: Pixel Transform: Cartesian to Polar

Originally Posted by MattTuck
Assuming I wrote it that way, all of my pixles will stay in the same place...
That is beyond me ... in my math those points don't stay at the same place.

kind regards,

Jos

10. Member
Join Date
Mar 2015
Location
A Place With Windows
Posts
71
Rep Power
0

## Re: Pixel Transform: Cartesian to Polar

It seems to me that is I preserve the height of y-axis as the radius then all I have to do is "bend" the x-axis 360°. But in doing so I'd have gaps in my image, and I'm not sure how to handle that gradience.

11. Moderator
Join Date
Feb 2009
Location
New Zealand
Posts
4,717
Rep Power
17

## Re: Pixel Transform: Cartesian to Polar

If I understand correctly you want to take each pixel in your source image and interpret its y-coordinate as r and its x-coordinate as phi. (You would scale the x-coordinate by 2*pi/width so that phi ends up going from 0->2*pi. You might also want to scale the y-coordinate to keep the final radius a reasonable size.). In other words your source image is telling you the colour of each pixel (r,phi) in the destination image.

The tricky bit is that the pixels in the destination image don't lie *exactly* at places (r,phi) for integer r and phi.

I can imagine two ways of dealing with this: The first is to simply round values. So, for each value in the destination image (1) calculate what r and phi is associated with that pixel, (2) scale these values if desired, (3) round the result to a pair of integers, (4) look up the value for the pixel in the original image.

The more complicated way recognises that each pixel of the destination image really represents a region of the source image. Take the (weighted) mean of all the pixels in this region and use this for the colour of the target image pixel.

---

As an aside CAT scanners face a similar problem. The values from the scanner are 1-d fourier transformed and assembled to make a 2-d image (whose pixel values are given for polar positions ie regularly spaced values of r and phi). This 2-d image is then inverse 2-d fourier analysed to reveal a section of the patient's inside. The problem is that the inverse transform wants the values at cartesian positions (ie regularly spaced values of x and y).

[Edit: from a computational standpoint it makes no difference whether you view the problem as the mutation of an image or merely as a change of coordinate system.]
Last edited by pbrockway2; 10-07-2015 at 03:45 AM.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•