ColorCalibration not working as expected


PTeam Member
Nov 2, 2016
La Palma, Canary Islands
Hi Juan,

the user magnusl got weird results from the ColorCalibration process ( ). I guess this is a bug.

I took his integration (in his thread in post #3) after cropping (left -180) as the starting point. Then I applied CC (default parameters except for Background Reference/Upper limit 0.0220). As he also noted, the resulting image has a strong orange color. The console output is:

ColorCalibration: Processing view: A
Evaluating background: done
* Background reference:
B_R : 1.91299e-02
B_G : 1.57293e-02
B_B : 7.90538e-03
Extracting structures: done
Calculating color correction: done
* White reference:
W0_R : 9.58892e-03
W0_G : 8.45353e-03
W0_B : 5.01187e-03
* White balance factors:
W_R : 1.0000e+00
W_G : 1.1343e+00
W_B : 1.9132e+00
Applying color calibration: done

These calculated parameters are all correct: the background references B_X are the subtractive correction factors and the white balance factors W_X are the multiplicative correction factors of the corresponding channel (X = R, G and B). So CC should be able to produce a well color calibrated image with a neutral mean background in one step, without the need of preliminarily executing BN.

I made up a PixelMath equation which subtracts B_X from each channel, multiplies with W_X, then adds the minimum of the minimum values of the channels (in this case: the minimum of the blue channel) and rescales the result. Instance source code:
var P = new PixelMath;
P.expression = "($T-B_R)*W_R+min(min(min($T[0]),min($T[1])),min($T[2]))";
P.expression1 = "($T-B_G)*W_G+min(min(min($T[0]),min($T[1])),min($T[2]))";
P.expression2 = "($T-B_B)*W_B+min(min(min($T[0]),min($T[1])),min($T[2]))";
P.expression3 = "";
P.useSingleExpression = false;
P.symbols = "B_R=0.0191299, B_G=0.0157293, B_B=0.00790538, W_R=1.0, W_G=1.1343, W_B=1.9132";
P.generateOutput = true;
P.singleThreaded = false;
P.use64BitWorkingImage = false;
P.rescale = true;
P.rescaleLower = 0;
P.rescaleUpper = 1;
P.truncate = true;
P.truncateLower = 0;
P.truncateUpper = 1;
P.createNewImage = true;
P.showNewImage = true;
P.newImageId = "PM";
P.newImageWidth = 0;
P.newImageHeight = 0;
P.newImageAlpha = false;
P.newImageColorSpace = PixelMath.prototype.SameAsTarget;
P.newImageSampleFormat = PixelMath.prototype.SameAsTarget;
* Read-only properties
P.outputData = [ // globalVariableId, globalVariableRK, globalVariableG, globalVariableB
Applying this PixelMath operation to his cropped integration resulted in a neutral background (the gradient is of course still present). In fact it produces the same result as applying BN first and CC subsequently. So apparently there is a bug in the ColorCalibration process.


Juan Conejero

PTeam Member
Sep 2, 2004
Valencia, Spain
Hi Bernd,

There is no bug here, just the expected behavior. ColorCalibration does not subtract the background reference values; they are only used to apply the white balance factors more accurately:

v' = (v - b)*w + b

where v is a pixel value, b is the corresponding background reference, w is the white balance factor, and v' is the calibrated pixel value. We did this on purpose when we designed the CC tool, many years ago, to separate multiplicative and additive transformations into different tools. In other words, BackgroundNeutralization should always be used before ColorCalibration.