final improved view of mountains with no lens flare

Sometimes a great shot involves pointing your camera in the direction of the sun. Even if it isn't actually present in the field-of-view, direct sunlight can still cause distortions in the image called lens flare. Fortunately, darktable provides some powerful tools for correcting these aberrations.

Both of these are nice images but the lens flare ruins them:

first image lens flare

second image lens flare

Let's look at 3 darktable modules you can work to correct lens flare.

Retouch

showing the retouch module fixing a simple case of lens flare

In some cases, such as against a solid background like the sky, it's easy to use the retouch module to simple replace the area with the lens flare with a good sample from elsewhere. However, this technique doesn't work if the lens flare is in front of some important details or would distract from the composition. Let's look at two more ways to work with lens flare.

Colorize

lens flare on trees corrected with the colorize module
lens flare on trees before using colorize module

In this photo, the area under the lens flare distortion is lighter than it should be. This is pretty easy to correct using the colorize module. This module allows you to overlay a color on top of an area and then adjust the saturation and lightness. You'll need to experiment with the settings to find exactly what works best for your image. Adjusting the blend mode from the default value of normal to lightness may improve the correction if the lens flare is just washing out the image and not introducing a color shift:

mask and first colorize settings to correct lens flare

Moreover, you might need to use multiple instances of the module if the distortion affects some areas differently:

mask and second colorize settings to correct lens flare

Let's look at another example:

Mountain with colorize partially correcting the color
Mountain with lens flare before adding colorize module

You may also need to add color in to the affected area to match its surroundings. In this case, the mountains are clearly dark blue but the saturation present in the area behind the lens flare was distorted. You can use the color picker module on surrounding pixels to get an idea of the colors that are present there verses the affected area, and then add in the difference in the R, G, and B channels to set the correct ratio between the channels or the correct values (amount of saturation) in each channel:

color picker differences before any correction

We can then add in a darker blue as needed:

colorize module mask and settings

While this gets us closer to the goal, additional color-related adjustments are necessary using color balance rgb.

Color Balance RGB

Mountain with lens flare corrected using different colors for the shadows and midtones
Mountain with lens flare before adding different colors to the shadows and highlights using color balance rgb

As seen in the "before" image above, using only the colorize module results in the area still appearing washed out. Sometimes you need to adjust the color differently for the shadows, midtones, and highlights which is possible using the 4 ways tab on the color balance rgb module:

mask and color balance rgb settings to correct lens flare

As you can see, the shadows needed a deeper blue correction whereas the midtones needed a lighter purplish blue.

Conclusion

Here are the final corrected images:

first image after correcting lens flare
first image before correcting lens flare
second image after correcting lens flare
second image before correcting lens flare

Sometimes lens flare is hard to avoid; darktable provides a flexible and powerful set of tools for correcting these aberrations. Remember that a combination of parametric and drawn masks with feathering and opacity adjustments will let you target the effect just to the desired area. Moreover, it's fine to use multiple copies of a module to make variances in the adjustments as needed.


Support Us and Access The XMP File

If you found this article helpful, please subscribe to our newsletter or support us on Patreon and get access to bonus features including the RAW file and XMP used in this article!

Questions? Comments?

Do you have questions or comments about this article? Please contact us via Mastodon or Email - we want to hear from you!