Displacement Magick #

As previously mentioned, I'm going to be evaluating the Thor system by taking a set of simple drawings, distorting them to get N variants per shape, and then seeing how well the system does precision/recall when all the variants are considered to be part of the same class. The Mori paper uses the TPS (no, not the reports, thin-plate splines) model to generate these distortions. I'm not completely sure what they are, but I definitely feel like I don't have the time to completely replicate their work.

Fortunately I've found an approach that works nearly as well and is well within my reach. Back in my KPT-reading, "let's try every filter in Photoshop" days (version 2.0/2.5 era) I came across the "Displace" filter. It takes a second image (a displacement map) as an input and uses it to distort the current image (displacements are based on pixel intensities of the displacement map, with the red and green channels being used as the X and Y components respectively). I whipped up a quick displacement map by applying a lot of noise to a blank image and then blurring it slightly (so that distortion amounts didn't change suddenly from one pixel to the next) and applied it to one of the sketches. The results were very encouraging, and by having more than one of these displacement maps I could generate as many variants as I wanted.

The only thing left to do was to apply these displacement maps to all 249 test images. Photoshop supports scripting, but I didn't feel like learning yet another object model and/or dealing with another language. The simplest solution was to use ImageMagick (Mac OS X package) controlled by a Perl script (I know that there's a CPAN module for using ImageMagick more directly within Perl, Image::Magick, but again I felt like setting that up and learning to use it would take too much time). I needed two basic commands, one to add some padding to the image (since the map can displace pixels to beyond the boundaries of the original image) and one to actually apply the displacement. The former was done by convert -mattecolor white -frame 50x50+0+0 input file output file while the latter can be accomplished with composite -displace 50x50 displacement map input file output file. After letting the script chug along for 30 minutes, I now have a dataset of 249 x 20 = 4980 images.

Post a Comment