Fixing White Balance (Color) Flicker in Timelapse Videos with a Python Script for darktable

Hello,

over the last one or two years a gathered some experience with Open Source Timelapse Post-Processing. While I don’t have the time to write a How-To (yet) I want to share a Python script which I wrote to significantly improve the results. Note, that the script works in combination with darktable, so if you don’t want to or can’t use darktable you can stop reading now. :slight_smile:

First, a bit of background information of why I wrote this script and how it works. Generally, if you look around, everyone (even the “gurus”) recommend shooting Timelapses with a fixed White Balance (e.g. a concrete value or “daylight”). This will, however, give to cold or to warm colors when the color temperatures shift during sunrise or sunset.
For that reason I started to shoot in AWB or automatic white balance mode. This works surprisingly well (at least on my Sony cameras), except if there are clouds moving through the picture and especially when those clouds get lit up by city lights. In that case you will get the odd frame where the WB is totally off, resulting in a nasty “color flicker” in the final video.
The fix is quite easy: All you need is to apply some data smoothing, where well know and studied approaches are available. I picked a Savitzky-Golay filter, because it’s readily available for Python and I understood how to use it :grin:

More technical description:
The script reads the White Balance coefficients (*) from the RAW files. The RAW files are only opened for reading, so that should be safe. Then, the Savitzky-Golay filter is applied to smooth out the value. After that, the coefficients are written to the XMP files as new Temperature element on top of the stack. Again, the new element is added, nothing should be replaced or even deleted.

The filter parameters can be freely tuned, with a handy plot option to see how the curve will behave to achieve the best possible smoothing.

I have tested this script multiple times now and it has not (yet) failed me. However, I take no liability if it eats your RAWs, your XMPs or spills your coffee. Make backups, at least until you are sure that you know what you’re doing and until you have some experience using this script.

If you start editing a batch of Timelapse photos I recommend fixing the WB first, because it might have a huge impact on how you edit your colors. If you do a daylight-only shot, you might not need it. Make it a case by case decision. On the other hand, it should be save to use it for every sequence.

And now, grab it, while it’s hot:

Jochen Keil / dtlapse · GitLab

(*) The WB coefficients are four values which are translated to the WB temperature value we all know and use. I didn’t understand the translation or calculation entirely, apparently there are different algorithms. Luckily, darktable does this translation internally and stores the coefficients in the XMP files

9 Likes

That’s awesome, thanks for sharing!

1 Like

Neat script! Your description makes one start to consider other scripting opportunities…

Actually, on the captured image itself, it’s the other way around: temp/tint from the user interface is converted to R, G, and B multipliers that are then inflicted upon each pixel’s corresponding R, G, and B values. Temperature and tint are really about the light in the scene; once you capture the scene, the relevant activity is about making R=G=B for something that’s supposed to be ‘neutral’, of which ‘white’ is s subset.

Softwares provide a temp/tint UI abstraction because that’s how a lot of photographers want to continue thinking about it after the image is captured. Me, I’ve never been able to use them effectively, but i can easily read a histogram and come up with a set of RGB multipliers to do WB… :stuck_out_tongue_closed_eyes:

That’s what I meant to say, sorry if I expressed myself unclear!

The camera RAWs contain a quadruple of coefficients. Darktable converts those values to a temperature for the UI (and the user), but stores them as quadruples in the XMP again.

1 Like

No worries, I wrote it as much to put it out there for others to consider. Sometimes, I think the UI part of raw processing is an impediment to really learning the basics…

Hi Jochen,
cool script, thanks for sharing! Time to learn python :wink:
Greets
Jürgen