# Twirl Image Transformation

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):

Into this:

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.

• Do you care more about speed or quality?
– Jens
Jun 7, 2013 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. Jun 7, 2013 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... Jun 7, 2013 at 7:54
• That would be great, but your answer is definitely pretty close. Jun 7, 2013 at 22:42

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]


• +1 Nicely done. You could define f[{x_,y_}]:= and then just use f in the ImageTransformation. Jun 6, 2013 at 21:07
• @simon thanks! This was some old code from last year - I've learnt a bit more since then... Jun 6, 2013 at 21:17

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["https://i.sstatic.net/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"]


• Definitely a lot nicer looking. Jun 7, 2013 at 0:54