darktable-org / darktable

darktable is an open source photography workflow application and raw developer
https://www.darktable.org
GNU General Public License v3.0
9.77k stars 1.14k forks source link

Function to use JPG embedded in RAW for color calibration in darktable #15225

Open pd3 opened 1 year ago

pd3 commented 1 year ago

Is your feature request related to a problem? Please describe.

My camera (Canon EOS R5) does a great job with colors for the embedded JPG, but I am unable to achieve similar colors (mainly skin tones) when processing the RAW version of the image in darktable.

I was wondering that it must be algorithmically possible to use the embedded JPG to adjust the color profile automatically. Is there a function for this in darktable? I was not able to find it.

Describe the solution you'd like

A function to preview and use the camera's automatic color profile from the embedded JPG on the RAW image.

rekcodocker commented 1 year ago

That would be a cool function. Theoretically, the color calibration could search the scale for the closest match in colors. It could be a binary search so it would home in very quickly. And it would only have to calculate the distance in RGB on the size of the embedded thumbnail.
Additionally perhaps a few modules could follow suit to match the colors even more closely - Contrast, exposure and color balance could be candidates.

I agree. The camera usually does a very good job in JPG, which would be a great starting point for Raw editing.

MStraeten commented 1 year ago

Is there a function for this in darktable? I was not able to find it.

because there’s no match-embedded-jpg function in darktable.

You can use camera white balance setting via disabling color calibration and use whitebalance module ‚as shot‘

Donatzsky commented 1 year ago

As I understand it, in the scene-referred workflow there's no color profile as such, only the basic camera matrix.

What you can probably do is use the spot mapping feature to tell color calibration to match a specific color in the image and automatically adjust the others accordingly. Not sure how well this works if taking the color from a JPEG, though. Exposure also has a spot mapping function.

HSUfineprint commented 1 year ago

I will love this function. It's a kind of auto color calibration, but the target is embedded JPG. Even that would not be the correct colors, but most people can get a good start point.

MStraeten commented 1 year ago

Don’t expect more than something you can also do with spot color matching here. All that secret sauce the camera manufacturers use in their jpg processing isn’t reproducible using an arbitrary raw/jpg pair.

todd-prior commented 1 year ago

@pd3 For now you should give DT chart a try... if you have a color checker... you can use your jpg as the reference image... It works by creating a style that has a tone curve and a clut preset... You might not want the tone curve and often it is quite subtle but you can use the clut module to impact color.. You could try it in its default position or after filmic and see how you judge the results....

pd3 commented 1 year ago

Hello, I was wondering if there was any progress or more thoughts on this? I am repeatedly facing the same problem, the embedded jpeg just looks better and I am unable to reproduce it with the tools available in darktable. It's usually the skin tones that come out as too yellow.

MStraeten commented 1 year ago

Canon didn‘t provide their raw to jpg recipes yet …

todd-prior commented 1 year ago

And that wouldn’t really help too much as its not like you can go down the recipe checklist and move the corresponding slider on DT 😊

From: Martin Straeten @.> Sent: Monday, October 23, 2023 4:57 PM To: darktable-org/darktable @.> Cc: Prior,Todd @.>; Comment @.> Subject: Re: [darktable-org/darktable] Function to use JPG embedded in RAW for color calibration in darktable (Issue #15225)

Caution: External email.

Canon didn‘t provide their raw to jpg recipes yet …

— Reply to this email directly, view it on GitHubhttps://github.com/darktable-org/darktable/issues/15225#issuecomment-1776007971, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AKS2ES322IWH5TRF3RMYXMDYA3K2NAVCNFSM6AAAAAA4SCJAZ6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZWGAYDOOJXGE. You are receiving this because you commented.Message ID: @.**@.>>

todd-prior commented 1 year ago

Hello, I was wondering if there was any progress or more thoughts on this? I am repeatedly facing the same problem, the embedded jpeg just looks better and I am unable to reproduce it with the tools available in darktable. It's usually the skin tones that come out as too yellow.

Do you have a colorchecker?? If you do there are a few things you can do. If not well I think most people will have a hard time getting good colors in almost any software. RT has a sort of chase the embedded JPG feature in the automatch tone curve but it really isn't a great "match" for the jpg much of the time and in a way similar to when DT had all of the color preservation modes in filmic, if you pick one of the different curve models you get very different results even with this approach. RT does support DCP files so in theory you can get something close to LR out of the gate if you grab the DCP files for your camera from an install of DNG convertor. DT doesn't support them. It only uses ICC profiles so you need to tweak your ICC profile to calibrate your camera and you could also use DT chart to get a lut to help but you need a colorchecker for both of these. Have you also tried using legacy WB, and maybe even basecurve and or tone curves... These generally produce more JPG like results at the expense of using the scene-referred modules to the greatest extent.

THere are some new tools as well ... the primaries module makes it very easy with a small hue rotation on the primaries to impact skin and it might even be a shift that is fairly consistent and easy to use.

What is the issue with the skin tones...

Finally I think many will say that if the gold standard is the camera jpg then why spend all the effort to develop the raw. The raw is not a super jpg waiting to happen that will somehow look just like it but somehow better because it was a raw capture. It is really just more data without the recipe of your camera altering the data so you have more control and more data to use to lift shadows or change lighting and you control the tonemapping and some other steps often before the data are constrained into the display transform.

In any case as a tool I think DT is more focused on trying to edit with the notion of keeping light from the scene intact as captured by the sensor and creating tools to best work with that and as such little to no effort trying to match camera recipes though many things can be done in the software by the user to work towards that if indeed that is the desired workflow...

MStraeten commented 1 year ago

And that wouldn’t really help too much as its not like you can go down the recipe checklist and move the corresponding slider on DT 😊

a programmer doesn’t need to move sliders ;)

rekcodocker commented 11 months ago

Canon didn‘t provide their raw to jpg recipes yet …

I imagine more something like a tuning where some kind of autotuning tries to move sliders on a few specific modules to approach the JPG as much as possible.

Move the contrast-slider to the left... image difference increases. Move slider to the right - difference decreases. Move more to the right, difference increases -> Ok, move it back to the last position. Then do color calibration. Move slider left and right until the difference with the embedded JPG is at a minimum.

Just a few basic modules, just to get you in the same area as the camera-Jpeg.

Then you have a very nice place to start further editing.

pd3 commented 10 months ago

I still dream about this function at nights. Would it be very hard to implement? I would be happy to help...

todd-prior commented 10 months ago

There are lots of tools to extract these if you want them…

I am sure it could also be introduced with a lua script… depending on the raw sometimes the jpgs are very small not really worth editing… other times they can be larger …

From: Petr Danecek @.> Sent: Sunday, December 31, 2023 2:28 PM To: darktable-org/darktable @.> Cc: Prior,Todd @.>; Comment @.> Subject: Re: [darktable-org/darktable] Function to use JPG embedded in RAW for color calibration in darktable (Issue #15225)

Caution: External email.

I still dream about this function at nights. Would it be very hard to implement? I would be happy to help...

— Reply to this email directly, view it on GitHubhttps://github.com/darktable-org/darktable/issues/15225#issuecomment-1873022022, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AKS2ES4ODV7JLT2LJVUZR7LYMG4DTAVCNFSM6AAAAAA4SCJAZ6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZTGAZDEMBSGI. You are receiving this because you commented.Message ID: @.**@.>>

MStraeten commented 10 months ago

no one provided the math to do so, so it’s hard to implement if you don’t have an idea of the math …

pd3 commented 10 months ago

I can imagine writing an algorithm that creates a mapping between two color spaces - from darktable's interpretation of raw file to whatever we observe in the embedded jpg. However, I have no idea how to integrate it. If you could propose an API, I could give it a try.

Donatzsky commented 10 months ago

@pd3 You can start by reading the section in the RawTherapee manual on DCP profiles. While I don't know exactly how RT does the mapping, I expect it's in a similar manner.

https://rawpedia.rawtherapee.com/Color_Management#DCP

Good luck fitting that into the scene-referred workflow of darktable.

pd3 commented 10 months ago

Just to make sure: when you say "good luck fitting that into the scene-referred workflow of darktable", do you mean you think it would be difficult?

I have no knowledge of darktable internals. Unless someone knowledgeable would be motivated to work on it with me, there is little chance I could make a meaningful contribution.

todd-prior commented 10 months ago

Just to make sure: when you say "good luck fitting that into the scene-referred workflow of darktable", do you mean you think it would be difficult.

DT has a core set of modules designed to complement each other based on a workflow that sets middle gray as the anchor and then builds the image from there so that tone and color are managed around that. Creating a module to replicate the JPG and trying to figure out how and where to place it so that it will integrate into that workflow might be tricky. I guess you could see it as an enhancement to the display referred workflow

Donatzsky commented 10 months ago

Just to make sure: when you say "good luck fitting that into the scene-referred workflow of darktable", do you mean you think it would be difficult?

In RT it's relatively straight-forward, since it's using a display-referred reference (the JPEG) to adjust a display-referred signal. In DT, however, there's a fundamental impedance mismatch, in that you would be using the same display-referred SDR reference to adjust a scene-referred HDR signal. That is, in RT the adjustment is part of, and after, the tone-mapping (tone curve), whereas in DT it would be entirely before the tone-mapping (filmic or sigmoid). Is there a way of doing it? Probably, but I suspect it requires a decent knowledge of image manipulation algorithms.

As @todd-prior alludes to, starting with figuring out how to map middle grey (with exposure) would likely be the first required step.

sg456 commented 10 months ago

I think a module like this would be a useful feature, but like many others I'm no coder so... It's usually not that hard to do it manually though, with sigmoid, rgb primaries and maybe color balance rgb.

@pd3 would you like to perhaps make a Play Raw post over on discuss.pixls.us ? Or even send me a RAW+jpg pair that shows the issue privately? It can't be too hard to get close - if I could I could make you a style to apply perhaps. And yes, I may be overoptimistic!

pd3 commented 9 months ago

@sg456 I will send you a file offline. Can you contact me by email? The address is on my profile page.

sg456 commented 9 months ago

@sg456 I will send you a file offline. Can you contact me by email? The address is on my profile page.

Sent. :-)

github-actions[bot] commented 7 months ago

This issue has been marked as stale due to inactivity for the last 60 days. It will be automatically closed in 300 days if no update occurs. Please check if the master branch has fixed it and report again or close the issue.