I'm trying to do a polar transform on the first image below and end up with the second. However my result is the third image. I have a feeling it has to do with what location I choose as my "origin" but am unsure.



radius = sqrt(width**2 + height**2)
nheight = int(ceil(radius)/2)
nwidth = int(ceil(radius/2))
for y in range(0, height):
for x in range(0, width):
t = int(atan(y/x))
r = int(sqrt(x**2+y**2)/2)
color = getColor(getPixel(pic, x, y))
setColor( getPixel(radial,r,t), color)
There are a few differences / errors:
This is the code combining my suggested improvements. It's not massively efficient, but it should hopefully work :)
In particular, it fixes the above problems in the following ways:
dx = x - width / 2as a measure of distance from the centre, and similarly withdy. We then use these in replace ofx,ythroughout the computation.rsatisfying0 <= r <= sqrt( (width/2)^2 +(height/2)^2 ), and ourteventually satisfying0 < t <= 2 piso, I create the appropriate scale factors to putrandtalong thexandyaxes respectively.atancan only distinguish based on gradients, and is computationally unstable near vertical lines... Instead,atan2(see http://en.wikipedia.org/wiki/Atan2) solves both problems, and accepts(y,x)pairs to give an angle.atan2returns an angle-pi < t <= pi, so we can find the remainder modulo2 * math.pito it to get it in the range0 < t <= 2piready for scaling.Any questions, just ask!