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 looking to reproduce the functionality of Photoshop's "Twirl" filter, which twists an image that originally looks like this (pulled from this page):

enter image description here

Into this:

enter image description here

Ideally, I'd like it to approximate the way the Photoshop Twirl filter behaves as much as possible, or at least be flexible enough to be able to reproduce the way the filter works.

share|improve this question
    
Do you care more about speed or quality? –  Jens Jun 7 '13 at 0:57
    
Both! Although it shouldn't take tremendously long to run. Primarily I was just interested in the form of the ImageTransformation, which @cormullion nicely shows. –  Guillochon Jun 7 '13 at 0:59
    
I hope another answer will be able to make the twirl start within the boundaries of the image, so that the edges of the original appear mostly unaffected. I've no idea... –  cormullion Jun 7 '13 at 7:54
    
That would be great, but your answer is definitely pretty close. –  Guillochon Jun 7 '13 at 22:42
add comment

2 Answers

up vote 20 down vote accepted

A slightly better one:

f[x_, y_] := With[
   {r = N@Sqrt[(x )^2 + (y)^2], a = ArcTan[y, x ]},
   { 0.6 r (Sin[(a + 12  r)]), 0.6 r (Cos[(a + 12 r)])}];
ImageTransformation[i, f[#[[1]], #[[2]]] &, 350, 
 DataRange -> {{-1, 1}, {-1, 1}}, Padding -> None]

enter image description here

share|improve this answer
    
+1 Nicely done. You could define f[{x_,y_}]:= and then just use f in the ImageTransformation. –  Simon Woods Jun 6 '13 at 21:07
    
@simon thanks! This was some old code from last year - I've learnt a bit more since then... –  cormullion Jun 6 '13 at 21:17
add comment

Upsampling prior to the transformation, followed by downsampling after gives you a higher quality image. This requires more computational expense.

Based on @cormullion's excellent work

i = Import["http://i.stack.imgur.com/Di28d.png"]

f[x_, y_] := 
  With[{r = N@Sqrt[(x)^2 + (y)^2], 
    a = ArcTan[y, x]}, {0.6 r (Sin[(a + 12 r)]), 
    0.6 r (Cos[(a + 12 r)])}];

ImageResize[
 ImageTransformation[ImageResize[i, 1000, Resampling -> "Gaussian"], 
  f[#[[1]], #[[2]]] &, 1000, DataRange -> {{-1, 1}, {-1, 1}}, 
  Padding -> None], 500, Resampling -> "Gaussian"]

enter image description here

share|improve this answer
    
Definitely a lot nicer looking. –  Guillochon Jun 7 '13 at 0:54
add comment

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.