# Undo The Twirl

I work in image analysis. The major advantage of this is that when I criticise shows like 24 and Spooks for their utterly preposterous image enhancement software I can do so with a vague air of authority. But it's not usually very exciting; not the kind of science that they can make a CSI style show about (although I thought that about maths, and they went ahead and made Numb3rs anyway*). So I was glad to see a forensic image analysis story in the Times today. It is the story of a very stupid paedophile who photographed himself sexually abusing young boys and put the photos on the internet. To prevent his arrest, he fired up some art package or other and distorted his face until you couldn't tell who it was.

He used a fairly standard distortion that most packages call "twirl" or "whirlpool". This was not smart. Had he used "blur", he'd still be loose. Had he used "pixellate", he'd be on the streets. Those effects destroy image information. But he used "twirl". The thing about "twirl" is that it's technically a transform: it doesn't remove any information from the picture, and that means you can reconstruct the original, with a little patience and preferably a copy of MATLAB. Unfortunately, my laptop with MATLAB installed is currently not working, so I can't fire it up and show you how to do this, but I can explain it. First, here's the image he released and the image the police reconstructed from it:

Image source: AFP

The effect is pretty simple, and you've probably already figured out how it's done, but to make it explicit, here it is in mathematical terms. Working in polar coordinates, you shift the image in θ, where the shift (which we should call Δθ) depends on R. (If you're not familiar with the notation, R is the distance from the centre of the swirl and θ is the angle that distance is at.) For full nerd points, here's the equation:

θf = θi + S × f(R)

More generally it should be θf = θi + f(S, R), but the art package designers probably didn't set out to make this difficult. They probably didn't expect it would be used in this way.

I've used S as the strength of the effect that you get to choose. The simplest way to undo this effect is to simply apply the same distortion in the other direction: subtract S × f(R) and you get θi back. First we need to know where the centre of the swirl is, but that's relatively simple. The patterning behind him shows us the edge of the circle, so finding the centre isn't too hard, and that's led to people (such as what is at the moment the only commenter on the Times article above) saying that this should have been an easy fire-up-PhotoShop-and-press-twirl fix. Problem is that all paint programmes use a slightly different f(R). So really you're just left playing around with something like MATLAB to find a f(R) that works. That's why the reconstructed image above still looks a bit like he's hypnotising you with his Scary Eye.

My preferred approach would be to knock up a MATLAB interface that let me draw a f(R) on a pair of axes and then showed me the image it resulted in. I reckon I could detwirl that image to a recognisable whole in an afternoon. And yet...

The hunt began three years ago when German police discovered about 200 photos on the internet of a man sexually abusing young Asian boys. But the man's face had been digitally scrambled and it was only 11 days ago that German police were finally able to reconstruct an identifiable image of the man who had eluded them for so long.
I can't imagine how you could spend three years on that. If you can't do it to a good approximation in a week then it's probably impossible, and if you can then I don't see how there could be three years of work in it.

There are 200 images, of course, but it's safe to assume he's used the same software to do each one. There aren't many distorts that don't destroy the image information, so probably many of those images were useless. The rest, you can reconstruct in the same way. They'll use the same f(R).

It's not as simple as it looks at first glance, but... I just can't see three years' work in that. Doing it in a couple of months would have got him caught much sooner. Also now, of course, they have to computer-graphically age the image three years.

Well. Perhaps if my laptop is mended I shall have a go and see how hard it actually is, and then I'll be able to say properly. But probably by the time my laptop gets fixed I shall be too distracted by the flying pigs and so forth.

Still, it could happen.

*I'm given to understand that the maths in Numb3rs was mostly pretty good, although they did approximate e to three.

• ## Dr Aust

I always giggle at the image enhancement in movies and TV shows too, Andrew. Especially when images with a few large grey pixels turn in seconds into nice clear mugshots. Fired by my microscopist's experience of tinkering with digital images, when I first got a mobile with a grotty camera on it I tried enhancing the pictures with Photozoom Pro. The results were so utterly unimpressive that I was left with the inescapable conclusion "garbage in, garbage out".
1
• ## Videogamer555

Actually it's not that simple either. Even Gimp which allows for full control of the effect (center coordinates, radius, and strength as measured in degrees of rotation are all controllable) I found it impossible to fully decrypt this image. Setting the radius and center of the effect is done with the rectangle select tool. The twirl effect control panel then gives fine tuning of the radius, as well as allowing adjusting of the strength. This should allow a full decrypt of the image, but I couldn't. That does seem strange so I'm guessing that as you said there's additional parameters to this that aren't directly controllable in image software. I'm guessing that the program used was Photoshop, so the parameters for the twirl would probably be best found in Photoshop. Unfortunately centering the effect will be difficult in photoshop as the center of the selection box does not have a crosshair. Another factor is was the effect centered at the boundary between pixels in the center of a 4 pixel square (all 4 center pixels would be effected) or was it centered on 1 pixel (the center pixel would not be effected). Having the center placed with subpixel accuracy is necessary as the effect deviates dramatically near the edge of the effect if the center of the effect is off by even 1 pixel.
2
• ## Videogamer555

I'm guessing that the police, INTERPOL, FBI, CIA, etc have really cool "autodetect all parameters of the twirl" software that without any human interaction involving setting parameters, could decrypt that twirled picture, software that is so top secret that they'd have to shoot any civilian who discovered its existence.
3
• ## Andrew

It could be even worse than that, in fact: if the images were resized at any point then the centre could be anywhere within a pixel. That said, for any given candidate centre point, the yellow line on the hanging behind him pretty much gives you the edges of the transform.
4
• ## Volunteer

Or maybe it took the police a month or two to realize they couldn't untwirl the image, then a couple of years to write the untwirling software.
5