Darktable 4.2.1 lens correction

So, I’ve been wondering about this for a while and am hoping someone could offer an explanation.

When I apply the Lens Correction module in Darktable 4.2.1, the pre-correction image always contains more data (image) around the edge of the frame than it does post-correction. It’s as if lens correction applies a subtle crop to the original photo. The question is “Why?” and “Why is considered desirable”? I get the need for lens correction but it bugs me that what I’m left with isn’t what I captured… Thanks.

If one doesn’t crop, one would end up w/ these black/gray (whatever the fill color is) patches of undefined pixels outside the image area after the correction. See e.g. What is "lens geometric distortion"?

You get the same “problem” w/ rotation btw, perspective correction, etc.

Thanks. The geometric distortion correction was always apparent but it never made sense that I’d actually wind up with less in the image after lens correction than before. I always presumed it was a ‘good thing’ but didn’t understand why. I’ve never noticed any grey/black patches when I didn’t lens correct but I can’t say I was looking for any artifacts, either. Thanks for the explanation and for the link to the explanation. I’ll check it out.

I did say after, like here.

1 Like

Gotcha. Thank you.

If you compare the out of camera JPG with lens correction applied in the camera to the image displayed from the RAW file you will also notice that cropping has taken place. So this is not unique to DT. Luckily most viewfinders and displays in the camera do not show 100% of the capture so it will rarely cause a problem.

It’s never been much of a problem per se. More a curiosity. The amount lost is rarely significant though there have been a few cases where I composed so tightly that something post correction wound up closer to the edge than I liked. As pointed out, the geographic correction was always apparent and I always preferred the corrected image to the pre correction version except for the ‘cropping’. Always something to learn! =^)

Hi James,
In the days of film I photographed weddings. As a wedding photographer we always wanted to have the final crop done in the camera as it was expensive and painful to crop individual images when printing orders. However, that was film. Now with digital cameras I have to crop a lot of the time. So with film the best practice was tight compositions in the camera but with digital giving a little bit of room for cropping during processing is ‘arguably’ the best practice. This is especially true when you know that you may use lens correction or even more so with perspective correction. I allow for a generous crop when photographing architecture or other subjects that will require perspective correction.

BTW, lens correction can be undesirable with some shots where people are close to the camera as they can become distorted and get egg heads. For this reason I would never blindly apply it to all shots.

And darktable 4.6 awaits you!

1 Like

Hi, Terry. Aside from a gig here and there over the years, I never tried to go pro but I’ve been shooting in earnest since the early 70s. Back then, I cropped in camera and I still do with digital. The usual exceptions are when I need to draw attention to a bird or rabbit or squirrel or some such. Then I take advantage of my Z7ii’s digital images and crop as need be. Old habits die hard. Yes. I’ve noticed the lens correction sometimes kind of takes over and can be objectionable. The module is part of my standard work flow but it’s nice to know ignoring it from time to time can be beneficial. I look forward to Darktable releases and will take on 4.6 as soon as it appears in my Debian/Devuan repos.

I’m also trying to warm up to the “Ansel” appimage install. I’m looking forward to trying it but would prefer a deb package. There’s always source, of course.

Hi James,
I tried Ansel and I am not trying to knock it, but it deliberately has removed or not included many of the modules I use or love in darktable. For instance, I use the sigmoid module in preference to filmic 99% of the time. Ansel forked from darktable a while ago as the developer had his own viewpoint about the direction that darktable should follow so he went his own way with Ansel.

The crop associated with lens distortion correction deserves explanation.

The image processing primitive used for lens distortion correction is call “warp”, indicative of the particular damage it does to an image. Essentially, using a non-linear polynomial equation, warp translates a pixel on a radial vector from the image center at a particular radius to another radius, hope that is intuitive. Changing the radial distance from the image center of each pixel “warps” the image. All the pixels are subject to this transform of location, so the resulting image loses its “rectangular” shape. Here’s a lens-corrected image, without benefit of cropping back to rectangular:

Looks like your old TV, no?

Lensfun has an autocrop option, where it’ll figure out the largest rectangular image to be extracted from such a warped rendition. Enabled, here’s that result:

There, all “squared up”, to re-purpose a machining term…

1 Like

Ansel’d be just another tool. I’m eager to try it but would rather not go the appimage route (I know I needn’t). Can’t have too many great free software choices.

Your examples are right in line with what I’ve seen on this end, Glenn. I’ve had few reasons to complain about the module except the cropping and now that I know what’s going on there and have an idea when not to use it, I’m good.

1 Like

For completeness, you can get mainly two forms of lens distortion:

  • pincushion distortion: parallel lines in the scene are “pulled apart” when you move away from the center, and
  • barrel distortion: parallel lines in the scene appear “squeezed together” when you move away from the center of the mage.

Real-life lenses can show both types of distortion, zoom lenses can change from one to the other when you move through the zoom range…

@ggbutcher showed what happened when you correct pincushion distortion. Correcting barrel distortion would have the opposite effect: the final corrected image would look like a pincushion, and you lose some pixels in the corners when cropping to a rectangle. But you wouldn’t lose edge pixels in that case.

Another question is whether you always need to correct lens distortion. For me that is mostly when I have straight lines in the image (that I want to keep straight).

3 Likes