New essay: Defishing fisheye images
Mar. 4th, 2007 02:11 amThis article grew out of my recent acquisition of a Zenzanon PE 30mm f/3.5 fisheye, and my subsequent attempts to de-fish its resulting images. To cut a long story short: it isn't easy, but it's worth it.
Fisheye images
Original Image
Fisheye lenses characteristically have a very wide field of view, though typically with considerable barrel distortion. The above image (of my kitchen in Mountain View) demonstrates the effect very clearly. Vertical lines are rendered as curves, looking a bit like what you might get if you'd printed the image onto the outside of a barrel, then photographed the barrel close-up. Sometimes, this kind of distortion is, artistically speaking, exactly what you want. However, often (usually?) images look better when straight lines are rendered as-such.
In recent years, rectilinear ultrawide lenses have appeared that have optics specifically designed to counter barrel distortion. Personally, I'd love to get my hands on such a lens for my medium format gear (I do have a large format rectilinear ultrawide, a Schneider 47mm Super Angulon, but currently don't have a lens board for it unfortunately), but no one ever made one for the Bronica ETRS mount. Indeed, extreme wide angle lenses for medium format tend to be extremely rare, with or without barrel distortion, so I was pleased to pick up a 30mm fisheye on eBay recently. As fisheyes go, the barrel distortion isn't too extreme, but I'd always intended to use it in conjunction with some de-fishing software or other.
In search of a de-fishing package
Photoshop CS2 Lens Correction Filter
My first port-of-call was the lens correction filter in Photoshop CS2. I have to say, I was really rather disappointed in the results -- it was clearly intended for correcting very mild distortion in conventional lenses, and I think it did a very poor job of de-fishing. I had to run the filter three times in sequence, with a couple of crops in between and another at the end, resulting in an image that lost way too much sharpness to be usable. The final image wasn't bad, but it clearly wasn't quite right -- the image had been remapped almost right, but the perspective was just a bit, well, wrong. And it was a royal pain to process.
So, strike 1.
PTLens
Googling for defishing software returns quite a few hits, though much of it points to software that either wasn't very relevant or (worse) not really very good.
I tried the well-known PTLens package first. This is a bit of fairly cheap shareware -- I installed the trial version without too much difficulty. The first problem I found was that I couldn't seem to make the plugin work, so I had to use its standalone shell instead. I wasn't too impressed -- the first big no-no for me was that it seemed to insist on source and destination images in JPEG format, which just isn't good enough for critical use. OK, I'm being picky, and a couple of years ago I wouldn't have thought of caring about this, but though it did an extremely good job of defishing the test image, the saved version was spoiled by JPEG artefacts to the extent of not really being usable.
Strike 2.
Adobe Photoshop Lightroom
OK, I thought. Commercial stuff might be worth a look, even though it will probably come along with a certain amount of sticker shock in with the deal. My first thought was Adobe Photoshop Lightroom, but their trial version download site was offline.
Strike 3.
DxO Optics Pro
Firstly, though probably not exactly unexpectedly, my camera, back and lens were nowhere to be found in their download information list, so I chose a 1 dsII and some random L series wideangle just so I could get to the download menu. I found the downloader, set it going, then busied myself reading some of the online documentation. I looked at the FAQ. No Windows Vista support. Ah. Cancel download.
Strike 4.
(Yes, I know that the baseball analogy just broke, but bear with me anyway)
Panorama Tools
By this time, I was starting to doubt that I was going to be able to manage this, at least in the short term anyway. I found myself thinking, 'well, I know enough about affine transforms and suchlike to probably be able to write my own, but getting the right curve will be very tricky.' Thankfully, I didn't need to reach for my C++ compiler this time around because I happened upon the (genuinely free) Panorama Tools package. This turns out to be a collection of rather high-powered, though rather clunky, tools aimed at the creation of high quality stitched panoramas. I missed this first time around because I wasn't really looking for a pano stitcher, but within itself it actually turns out to have a rather deeply buried though extremely high quality de-fisher.
Installing Panorama Tools can be a bit tricky, and is not really for the faint hearted -- though there is a binary distribution, there's no install program, so you're at least partly on your own. However, taking things a step at a time, it's not too difficult. You need to download and install the Java Runtime Environment in order to be able to run some of the tools, but the main thing you need to do is copy a DLL into the Windows/System directory and then copy a bunch of plugins into the Photoshop plugins directory. All of this was pretty straightforward -- after stopping and restarting CS2, I had a new menu option on the Filter menu, 'Panorama Tools'.
The first issue I found was the menu item being greyed out, which turned out to be a consequence of my using a monochrome source image. Converting this to RGB mode solved the problem trivially, which then gave access to four menu options, Adjust, Correct, Perspective and Remap. After a bit of blind prodding around, I found that Remap did what I wanted.
Again, after a bit more trial and error, I found that the above settings pretty much perfectly corrected the barrel distortion in the source image.
Conclusions
De-fished image
The final version of the image looked pretty good. I find that using Smart Sharpen or Unsharp Mask in CS2 turned way up can be a very useful way to spot any unwanted artefacts in an image, and I honestly couldn't find any problems at all.
By way of an example, here's a 100% crop from the final frame:
I found that pretty impressive -- the bottles are about 15 feet away, and as you can see, they were very small in the original frame. I think I can take it as proven that the fisheye itself is extremely sharp, and also that Panorama Tools has managed to preserve this extremely well. Three stars and a tick.