Struggling to white balance an image (Darktable)

I do not now, thanks to yourself and, before that, @Ofnuts

https://discuss.pixls.us/t/channel-mixer-output-not-same-as-manual-predicts/43751/3

Off-topic but we can sometimes obsess over relatively small differences in color appearance …

Look at the degree of correction needed by early Foveon sensors to get anywhere near correct XYZ values:

For example luminance (Y): camG is multiplied by a big number compared to channel mixers and quite big chunks of camR and camB are subtracted!

By comparison, getting bothered about why a channel mixer output is 100, not 120 is rather pedantic even if a difference in color appearance can be seen, eh?

That was an interesting explanation by Ofnuts.

In my mind, this really does take me full circle back to how I reformed the question earlier on. Ignoring all the maths, matricies, colour spaces, gamma encoding and everything in between, how do you really use the channel mixer in an intuitive way. I am fairly sure nobody gets a pen and paper and actually works out the maths. Boris and others seem to have a feel for this tool that I just can’t get.

If I have (for example) what looks like a subtle green cast to my photo, and as a learning exercise I want to fix it with channel mixer, what do I do? (And importantly, why?).

I feel like a bit of a time waster asking again, but truthfully, I can’t do it.

Well, yes I would agree it is likely pedantic. But if I don’t know how to use the tool intuitively, then what am I meant to do?

However, if it is pedantic to obsess over such a small difference then that at least indicates that small differences don’t matter and maybe points towards the reality that the numbers don’t matter on an artistic level, it’s the effect of the changes that matter. To that end, I really am trying to get a feel for this but it is just not happening.

This I think was some of the motivation for the rgb primaries and also the incorporation of similar tools in the sigmoid module… ie to make such changes a bit more intuitive… Using that tool with the vectorscope is much easier than the channel mixer for most people I would surmise. I think no one ever uses the channel mixer for this purpose by dialing in actual numbers… As noted now so many variables can change that final math by the time the image is fully processed that its only valid and accurate at the output of the channel mixer module and so if you can not control the pipeline or order of operations say with layers then you simply use the channel mixer to invoke predictable changes to a certain output channel until you achieve the desired effect.

I’m not an expert but say a subtle green cast you might add some red and some blue to the green input of both of those output channels and maybe drop the green in the green channel to match those increases… if your cast is biased to green then shifting it away from the green in a ratio that neutralizes it would likely work… But you could use other combinations as well… Personally I find rotating the hue and tweaking purity along with the tint slider in rgb primaries an easier thing to visualize and control…

So when I increase the green slider of the red output channel, is that decreasing the amount of green in the red channel, or is it increasing the amount of red in the red channel? Are the predominently red pixels becoming more red, or are they having green removed? Can you see how I am trying to get a basic visualisation of whats happening?

Okay think of it this way… HTH…

In the channel mixer you see three groupings… First the red then the green and finally the blue… These are the output channels …one group for each channel… Within each group any change you make involves only that channel…so first group anything you do only impact the red value of a given pixel…

So again these groups are output… the only thing changed in each group by moving the r g or b slider is say for example red in the first group… green in the second and blue in the third…

So you move any slider in the first group it only changes the red value of your image pixels…

Now in front of each of the sliders within a group imagine any pixel value in rgb… for example 120 60 200…

WRT the first group you could put those values in front of each related slider so 120 in front of the red “input” slider 60 in front of the green and 200 in front of the blue input slider… You would repeat this for the other two groups… these are your input values …

In the first group the red slider will change red by 120 x slider, the green slider will change red by 60 x the slider, the blue slider will change red by 200 x the slider. You can repeat this same logic for the green outputs now and then the blue outputs… So these groups define the transition from input to output … In this case the strongest impact on red of that pixel is actually by moving the blue slider in that group…

So think of the input sliders as the rgb value of the pixel you are trying to change and then think of a curly bracket on the other side of the group and the sum of the slider changes in a group will produce the resultant output value of the new pixel …one value for each group to give you the new rgb value of the pixel…

You are adding red proportional to the amount of green… if green were zero in any pixel…moving the slider would have no effect on that pixel.

I think that you need to know what the scene colors should be in terms of RGB values in your review image. The best example is of course a neutral color where everybody and his dog knows that R=G=B.

Less easy to guess is a flower color, for example (groan) yellow. But still, most of us know yellow is R=G and the amount of B determines the shade of yellow, right? With a green cast are you able intuitively to guess the unwanted degree of green-ness as a ratio (which is what we play with in the mixer).

In the following green-casted image, the green I measured as being off by about +10%. Is that obvious to your eye?

ColorCheckerKoren-G cast

Not obvious to me, but my screen color-picker says the mid-gray patch is 132 145 130 with green 10% to 12% higher than it should be. So intuitively I would take maybe 0.15 away from each green input in each channel in the GIMP mixer. If the mid-gray color comes close enough to R=G=B then maybe the cast was fixed.

I suggest that taking an equal percentage of green off of each channel setting moves the output RGB color towards “balanced” from whence it came.

Time now to consider what to do if the cast is not a pure color … what say you?

From how you say this you are always using the green input and with the same slider setting so all you will do is lower all the values still leaving green higher… unless I misunderstand you. I think you would rather drop the blue and red input sliders about the same in the green out put channel. This will drop the green to match red and blue which are close to 128

That’s not a correction, it’s a transformation.
For example, to convert Rec 2020 (another RGB colour space) to XYZ, you’d have something like:

0.636953507, 0.144619185,  0.168855854
0.262698339, 0.678008766,  0.0592928953
0,           0.0280731358, 1.06082723

Or, the Fuji XT-5 matrix:

		<ColorMatrices>
			<ColorMatrix planes="3">
				<ColorMatrixRow plane="0">11809 -5358 -1141</ColorMatrixRow>
				<ColorMatrixRow plane="1">-4248 12164 2343</ColorMatrixRow>
				<ColorMatrixRow plane="2">-514 1097 5848</ColorMatrixRow>
			</ColorMatrix>
		</ColorMatrices>

Dividing those by 16384 (just a guess):

 0.72076, -0.327026, -0.06964
-0.259277, 0.74243,   0.14301
-0.031372, 0.06696,   0.35693

So if the RGB sliders in each channel only affect that channel (which is true, I am not questioning it) then why on earth not just have one slider in each output channel ? If we can’t guess the amount that a cast is off (which is true, I am not questioning it) then why does it matter that we adjust an output channel proportionally to 3 input channels? We could just adjust the output channel until it looked right, couldn’t we?

Gentlemen, your patience with me has been greatly appreciated, and I am jealous of your flair for this module. The maths is easy to understand, I can write it down and work it out and I get it, but I look at a photo and I have no intuition at all on how to put it into practice.

I will admit defeat and move on. Thanks to everyone who spent time trying to educate me.

I don’t understand this. You are mixing 3 input channels for each output channel.
Therefore, each output (red, green, blue) needs 3 input sliders (how much of the original pixel’s red, green and blue value to mix so you get the output red, green or blue value). This is perhaps best visible on the Gimp screenshots that Ted posted.
All those matrixes are just the mixing instructions, without labels.

1, 0, 0
0, 1, 0
0, 0, 1

is the ‘identity matrix’, pass-through: take the input red, but not the green and blue, to get the output red, and then the same for the others.

But why?

Say input red is 135. It goes through the channel mixer using whatever values you end up setting for the r g b sliders of the output red channel, and red comes out as 178. Why not just increase red to 178? Honestly, I am not understanding why is has to be a mixture.

With 9 sliders across 3 channels there are an infinite amount of ways that the matrix can be set, and it is just not intuitive to me. It isn’t. I cannot seem to grasp the concept.

Everyones contribution to this conversation has been absolutely brilliant, but I concede. I will stick with basic WB, it will have to be good enough.

OK. Look at the degree of transformation needed by early Foveon sensors to get anywhere near correct XYZ values.

You are making the color model too simple. RGB is a 3D space but your simple example covers only red-to-red transformations.

Voila the full model:

and:

3D manipulations require 3x3 matrices. Of course, you can adjust only one color path in what is known as a diagonal matrix (all zero coefficients except on the diagonal) as shown in the identity matrix, where out=in:

1 0 0
0 1 0
0 0 1

So for 135 red to 178 red

the above in the GIMP would be 178/135, i.e.

1.319 0 0
0 1 0
0 0 1

If that’s all you need and assuming that pink neutrals are OK, then all is well!

Now suppose you take a dislike to patch #2 194 149 128 and would prefer a more healthy-looking 221 134 130

Sure, a diagonal matrix of

1.139 0 0
0 0.899 0
0 0 1.016

would look OK but how would the sky look?

Cyan 6 133 161 becomes 7 119 164

yellow flower 231 199 31 becomes 255 179 31

All the above ignoring the ‘gamma’ factor revealed by @Ofnuts .

Not to suggest that you don’t pursue your understanding and use of the channel mixer but there are several tools that will help you and they are perhaps a more straightforward application… We have the rgb primaries in their own module and as an enhancement of sigmoid which itself helps to a degree with color casts… Also the RGB color balance is excellent for this…so for example in your first image… just adding the module…going to the mask tab and setting both of the fulcrum sliders with the autopicker and then using the correction pickers in the 4-way tabs… Generally doing highlights and shadows will produce a decent result that you can further tweak if needed… so in the case of your image I just did a big range in the background highlights and one in the dark background and the vectorscope which shows the strong yellow green cast to start…

image

becomes more balanced after that treatment with color balance…

image

You can easily dial this back with opacity or make it stronger with the sliders in the 4-way tabs…

So this which is a bit improved already by the application of sigmoid…

Goes to this… ready for further editing without the cast…

1 Like

A gray patch is better for that, I reckon.

He may be actually talking about this… sometimes in the past it has been found that the D65 reference values provided by the WB module in DT which are then used by the CC module using a CAT to correct to scene neutral are not that good and could be better… Using a calibrated monitor and a white image it can be possible to generate a better set…

https://docs.darktable.org/usermanual/development/en/module-reference/processing-modules/color-calibration/#caveats

It’s just a possibility. That’s why it’s called a mixer.
It’s also OK to adjust only red-in-red, green-in-green, blue-in-blue:

r 0 0 
0 b 0
0 0 g

That’s called white balancing, and it takes you from

to

But suppose you have this beautiful, perfectly white-balanced photo of a yellow and a red flower on neutral background (so already white-balanced):

However, the yellow flower is too orange. We should reduce red, or increase green, to make it yellow. However, if I use the channel mixer to only decrease red or increase green, , I’ll skew the white balance, and also affect the other flower:

or

In both cases, brightness was also changed, since in one case we removed energy (red), in the other we added some (green). Let’s ignore that for now.

However, you could say: ‘decrease red where there is also green’

That still skews the white balance, since the grey background originally had red = green = blue; we kept its green and blue intact but reduced red, so there’s more green and blue there than red. If we increase red, we are back to where we started from, but we could use the fact that the yellow has mostly green and red, but not blue, so if we add the blue channel to the red, we won’t affect the yellow, only the grey:

By activating preserve luminosity (in darktable, normalize channels has a similar function), Gimp will try to keep brightness intact by scaling the end result, while respecting the ratios we specified:

You could be more precise with the numbers, but that’s the general idea.

1 Like

I gave up to soon, frustration got the better of me (apologies).

I am going to work my way through this again, see if I can get a “feel” for it.