Automating the color mapper module with a lua script

Hello,

As my first post to this list let me thank all the developers, etc. for producing darktable. It’s been fun to learn and while all software has its rough edges one cannot complain about darktable’s powerful features for the cost.

I’ve been using darktable on and off since 2019 or so and one thing that’s disappointed my is how the colors of my Nikon NEF images look after editing. I find the colors of the embedded jpeg pleasing to my eye and have had much difficulty replicating that as a starting point for further editing. For several years I would actually just use the jpegs and leave it at that. There’s no question that in certain situations editing the raw is for more powerful and also no question darktable has progressed over the years to the point that last year I decided to give it a shot as my primary editing tool and DAM. But still, even with the progress darktable has made I still find the out of camera colors more pleasing, especially blue skies. I’m not really looking for a lecture in color science concepts as interesting as that is (would just go over my head anyway) I just want to enjoy my hobby. The sigmoid default often gets me close and I’ve also tried the recent Nikon styles options (I’m assuming it tries to mimic the auto or standard Nikon picture profile? I prefer neutral or even flat on occasion. And I’m not sure why those styles use filmic as opposed to sigmoid when the latter has become the default but that’s another topic), yet still I prefer the colors from the camera. I recently stumbled across the color mapper module and it pretty much does what I want for the most part. However, it can be rather time consuming extracting the embedded jpeg and applying the map to the associated raw file. I thought maybe this could be done via a lua script. I’ve kludged a few darktable lua scripts now but nothing this potentially involved. Not a coder really, why I got into UNIX/Linux infrastructure support and not software development.

At a very high level.

  • Load the raw file into darkroom
  • Have a lua script automatically run to extract the embedded jpeg via exiftool
  • Apply the color mapping from the extracted jpeg file to the raw file
  • Discard the jpeg
  • Continue on with editing

Not knowing the lua api very well (I know, RTFM) but to save a little time I thought I’d ask the experts if the above scenario is even possible via lua.

Sorry if my posting etiquette isn’t whats expected. Always grateful for any information.

Regards,
Grano

1 Like

You could give this a try…

1 Like

How do you propose to get the color mapping?

The Lua documentation is at darktable lua documentation - Home. The best way to learn darktable lua scripting is by reading the existing scripts and seeing how they did it.

I’ve written some scripts that run when an image is loaded into darkroom and do a sequence of preprocessing so I can give you some pointers.

1 Like

I have created a style for my Canon R7 and it produces colors, exposure and contrast that are close to what my cameras jpg look like. It involved not only setting white balance but saturation and specifically saturation/chroma for colors which were more dull than the JPG.

Why not put a out of camera JPG sample in play raw with the RAW file supplied and request people to create a style that approximates the cameras JPG.

Hi, thanks for the reply.

Color mapping via this module darktable 3.8 user manual - color mapping. It’s changed a bit but it’s still there in 5.2. at least for now.

I’ll look at the lua docos. Was just wondering how feasible it was before digging into it too much. Since retiring from IT I tend to eschew the details if possible, been there - done that :wink: Anyway, perhaps a winter project.

Hi, thanks for the idea.

Yeah, I’ve kinda messed with that also. Even modified the styles that ship with darktable these days as a starting point but not much success here so far. I’ll try again though considering your success and experience.

Grano

Very interesting option, I’ll try exploring this.

Thanks!

The way I created a style was to open the JPG and take a snap shot. I then used the snapshot as a comparison for the raw file. The first setting was working out the exposure slider position to match the raw exposure to the JPG. I then worried about the contrast slider in Sigmoid to closer match the JPG. The white balance was already close when the color calibration module was set to as shot in camera. However, I had to tweak saturation levels in the color balance RGB module. I also found that applying local contrast and the shadows and highlight modules helped. I applied denoise profiled and basic sharpening. I then noticed that my neural grey tones were a good match but my skin tones were not as warm and pleasant as the JPG so I lifted the chroma for the warmer tones using the color zones module. I now had a result that was close to the jpg without being a perfect match. In fact the picture was sharper, had more detail in the shadows and had a similar color to the cameras JPG. This gives me a nice starting point going forward. Over a few weeks I did some small changes to the style to further improve it.

This process was for my Canon R7. I have also done one for my Canon G16, but am yet to do one for my Nikon D7100. The styles that are offered in DT use filmic and therefore don’t suit my work flow but they did inspire me to make my own.

Thanks for taking the time to reply! I’ll try some of those suggestions.

Regards

Anything you can assign a shortcut to (i.e. color mapping->aquire-source and acquire-target) can be called from a lua-script using darktable.gui.action(). So, yes it’s possible to automate with a lua-script.

Ah, thank you much. Very good to know, now time to dust off my lua for dummies book :wink: