# ImageTransformation: polar to cartesian

I am working on something that requires the polar transformation of some images. I implemented this transformation with ImageTransformation:

img = Import["https://i.sstatic.net/9cV4T.jpg"]


{center, radius} = ComponentMeasurements[MorphologicalComponents[img, 0.2],
polar = ImageTransformation[img, center + {Cos[#[[1]]], Sin[#[[1]]]}*#[[2]] &,
PlotRange -> {{0, 360 \[Degree]}, {1, radius}}]


After some processing I would like to transform the image back into the original coordinate system. This step is where I ran into problems. The transformation of the coordinates isn't really the problem but I couldn't figure out how to center the transformation properly and what PlotRange I have to provide.
So the question is how to reverse the transformation:

ImageTransformation[img, center + {Cos[#[[1]]], Sin[#[[1]]]}*#[[2]] &,
PlotRange -> {{0, 360 \[Degree]}, {1, radius}}]


One of my failed attempts:

ImageTransformation[imgNorm, {0, Pi radius} + {Sqrt[#[[1]]^2 + #[[2]]^2],


This seems to work:

ImageTransformation[polar,
DataRange -> {{-180 \[Degree], 180 \[Degree]}, {1, radius}},

• Don't call ArcTan[y/x]. You'd only get an angle between -90°..90°. There's an overload ArcTan[x,y] that returns an angle from -180°..180°
• Somewhat unintuitively, PlotRange->Full isn't the same as PlotRange->(* dimensions of output image*), it uses the input image's dimensions. If in doubt, give explicit ranges.
• Thanks this is exactly what i was looking for. Replacing the 1 in the DataRange option with 0 gets rid of the black dot in the middle.
• @paw: The black dot is there because the polar image contains no data for that location. If you use 0 in the DataRange of the inverse transform, but used 1 in the PlotRange of the polar transform, the result will be slightly skewed (by 1 pixel at the center). You can either use 0 for both, or use Padding -> "Fixed" to get rid of the black dot in the center. Commented Aug 31, 2014 at 11:11
• @paw and @nikie : Thanks a lot for both of your code examples that are very helpful to me. However, could you please explain why ({x,y} + {Cos[#[[1]]], Sin[#[[1]]]}*#[[2]] &) does what it is doing in ImageTransormation? Because I tried to understand the transformation by using a list of pixel positions, e.g. {{1,1},{1,2},...,{2,1},{2,2}...} and the transformed pixel positions on which I applied the above equation and displayed the results using ListPlot. Thanks a lot! Commented Dec 22, 2016 at 22:08
• @paw and @nikie : My motivation is that I want to use an arbitrary vector center={x,y}` about which to tranform the image in polar coordinates. But I get problems with the settings I need to use for PlotRange in order to display the whole transformed image. Thank you! Commented Dec 22, 2016 at 22:18