Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

img = Import["http://i.stack.imgur.com/9cV4T.jpg"]

enter image description here

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

enter image description here

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]] &, 
    {2 Pi radius, radius}, DataRange -> Full,
    PlotRange -> {{0, 360 \[Degree]}, {1, radius}}]

One of my failed attempts:

ImageTransformation[imgNorm, {0, Pi radius} + {Sqrt[#[[1]]^2 + #[[2]]^2], 
    ArcTan[#[[2]]/#[[1]]]} &, {2 radius, 2 radius}, DataRange -> Full]
share|improve this question

1 Answer 1

up vote 9 down vote accepted

This seems to work:

ImageTransformation[polar, 
 {ArcTan @@ (radius - #), Norm[# - radius]} &, 
 {2 radius, 2 radius}, 
 DataRange -> {{-180 \[Degree], 180 \[Degree]}, {1, radius}}, 
 PlotRange -> {{0, 2 radius}, {0, 2 radius}}]

Notes:

  • 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.

Result

share|improve this answer
1  
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 Aug 30 at 7:52
    
@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. –  nikie Aug 31 at 11:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.