AWB non-raw file fixes (for 5.10) (#6940)

* Improve Itcwb with non-raw files

* Change pre-dev builds wbrefinement

* Change template in pre-dev

* Improvment improccordinator.cc

* Forgotten observer convert

* Reenable wbauto autogrey as 5.8

* Remove wrong code

* Missing getrgbloc references

* Fixed bug due to bias in queu with temperaure correlation issue 6911

* Simpleprocess queue compatibility tif-jpg

* Preserve AWB edits from 5.9

In 5.9 for non-raw files,
   1. RGB grey uses the unit multipliers with temperature bias applied.
   2. Temperature correlation uses the equivalent of temperature 5000,
      green 1, and red/blue equalizer 1.

* Refactor temperature correlation AWB code

* Fix inaccurate RGB grey WB preview after using ITC

The RGB grey automatic white balance algorithm caches the multipliers.
Temperature correlation automatic white balance also caches results to
the same location, but never uses it. This causes the RGB grey method to
produce incorrect results in the editor. Removing the temperature
correlation cache fixes the issue and does not have side-effects.

---------

Co-authored-by: U-PCSPECIALIST01\jdesm <jdesmis@gmail.com>
This commit is contained in:
Lawrence37
2024-02-01 22:41:56 -08:00
committed by GitHub
parent 0509313547
commit f06e756c20
20 changed files with 561 additions and 468 deletions

View File

@@ -275,7 +275,7 @@ private:
if (params.wb.method == "autitcgreen" && flush) {
imgsrc->getrgbloc(0, 0, fh, fw, 0, 0, fh, fw, params.wb);
}
const bool autowb = params.wb.method == "autitcgreen";
const bool autowb = (params.wb.method == "autitcgreen" && imgsrc->isRAW() && flush);
ColorTemp autoWB;
int dread = 0;
int bia = 1;
@@ -295,233 +295,60 @@ private:
if (!params.wb.enabled) {
currWB = ColorTemp();
} else if (params.wb.method == "Camera") {
} else if (params.wb.method == "Camera" || (params.wb.method == "autitcgreen" && params.wb.compat_version >= 2 && !imgsrc->isRAW() && flush)) {//Use also Camera settings for Temperature correlation and TIF/Jpg
currWB = imgsrc->getWB();
} else if (params.wb.method == "autold") {//for Auto RGB
double rm, gm, bm;
imgsrc->getAutoWBMultipliers(rm, gm, bm);
if (params.wb.compat_version == 1 && !imgsrc->isRAW()) {
// RGB grey compatibility version 1 used the identity
// multipliers plus temperature bias for non-raw files.
rm = gm = bm = 1.;
} else {
imgsrc->getAutoWBMultipliers(rm, gm, bm);
}
currWB.update(rm, gm, bm, params.wb.equal, params.wb.observer, params.wb.tempBias);
} else if (autowb && flush) {//for auto Itcwb - flush to enable only when batch
} else if (autowb) {//for auto Itcwb - flush to enable only when batch only with Raw files
//code similar to that present in improccoordinator.cc
float tem = 5000.f;
float gre = 1.f;
double tempref0bias = 5000.;
tempitc = 5000.f;
bool autowb1 = true;
double green_thres = 0.8;
{
currWBitc = imgsrc->getWB();
double greenref = currWBitc.getGreen();
double tempref0bias0 = currWBitc.getTemp();
if (greenref > green_thres && params.wb.itcwb_prim == "srgb") {
forcewbgrey = true;
}
if (!forcewbgrey && (tempref0bias0 < 3300.f) && (greenref < 1.13f && greenref > 0.88f)) { //seems good with temp and green...To fixe...limits 1.13 and 0.88
if (settings->verbose) {
printf("Keep camera settings temp=%f green=%f\n", tempref0bias0, greenref);
}
autowb1 = true;
kcam = 1;
}
if (autowb1) {
//alternative to camera if camera settings out, using autowb grey to find new ref, then mixed with camera
// kcam = 0;
params.wb.method = "autold";
double rm, gm, bm;
tempitc = 5000.f;
greenitc = 1.;
currWBitc = imgsrc->getWB();
tempref0bias = currWBitc.getTemp();
double greenref = currWBitc.getGreen();
bool pargref = true;
bool pargre = true;
if ((greenref > 1.5f || tempref0bias < 3300.f || tempref0bias > 7700.f || forcewbgrey) && kcam != 1 && !params.wb.itcwb_sampling) { //probably camera out to adjust...
imgsrc->getAutoWBMultipliersitc(extra, tempref0bias, greenref, tempitc, greenitc, temp0, delta, bia, dread, kcam, nocam, studgood, minchrom, kmin, minhist, maxhist, 0, 0, fh, fw, 0, 0, fh, fw, rm, gm, bm, params.wb, params.icm, params.raw, params.toneCurve);
imgsrc->wbMul2Camera(rm, gm, bm);
imgsrc->wbCamera2Mul(rm, gm, bm);
ColorTemp ct(rm, gm, bm, 1.0, currWB.getObserver());
tem = ct.getTemp();
gre = ct.getGreen();
if (gre > 1.3f) {
pargre = false;
}
if (greenref > 1.3f) {
pargref = false;
}
double deltemp = tem - tempref0bias;
if (gre > 1.5f && !forcewbgrey) { //probable wrong value
tem = 0.3 * tem + 0.7 * tempref0bias;//find a mixed value
gre = 0.5f + 0.5f * LIM(gre, 0.9f, 1.1f);//empirical formula in case system out
} else {
if (!forcewbgrey) {
gre = 0.2f + 0.8f * LIM(gre, 0.85f, 1.15f);
tem = 0.3 * tem + 0.7 * tempref0bias;//find a mixed value
nocam = 0;
} else {//set temp and green to init itcwb algorithm
double grepro = LIM(greenref, green_thres, 1.15);
gre = 0.5f * grepro + 0.5f * LIM(gre, 0.9f, 1.1f);//empirical green between green camera and autowb grey
if (abs(deltemp) < 400.) { //arbitraries thresholds to refine
tem = 0.3 * tem + 0.7 * tempref0bias;//find a mixed value between camera and auto grey
if (deltemp > 0.) {
nocam = 1;
} else {
nocam = 2;
}
} else if (abs(deltemp) < 900.) { //other arbitrary threshold
tem = 0.4 * tem + 0.6 * tempref0bias;//find a mixed value between camera and auto grey
if (deltemp > 0.) {
nocam = 3;
} else {
nocam = 4;
}
} else if (abs(deltemp) < 1500. && tempref0bias < 4500.f) {
if ((pargre && pargref) || (!pargre && !pargref)) {
tem = 0.45 * tem + 0.55 * tempref0bias;//find a mixed value between camera and auto grey
}
if (pargre && !pargref) {
tem = 0.7 * tem + 0.3 * tempref0bias;//find a mixed value between camera and auto grey
}
if (!pargre && pargref) {
tem = 0.3 * tem + 0.7 * tempref0bias;//find a mixed value between camera and auto grey
}
nocam = 5;
} else if (abs(deltemp) < 1500. && tempref0bias >= 4500.f) {
if ((pargre && pargref) || (!pargre && !pargref)) {
tem = 0.45 * tem + 0.55 * tempref0bias;//find a mixed value between camera and auto grey
}
if (pargre && !pargref) {
tem = 0.7 * tem + 0.3 * tempref0bias;//find a mixed value between camera and auto grey
}
if (!pargre && pargref) {
tem = 0.3 * tem + 0.7 * tempref0bias;//find a mixed value between camera and auto grey
}
nocam = 6;
} else if (abs(deltemp) >= 1500. && tempref0bias < 5500.f) {
if (tem >= 4500.f) {
if ((pargre && pargref) || (!pargre && !pargref)) {
tem = 0.7 * tem + 0.3 * tempref0bias;//find a mixed value between camera and auto grey
}
if (pargre && !pargref) {
tem = 0.8 * tem + 0.2 * tempref0bias;//find a mixed value between camera and auto grey
}
if (!pargre && pargref) {
tem = 0.3 * tem + 0.7 * tempref0bias;//find a mixed value between camera and auto grey
}
nocam = 7;
} else {
tem = 0.3 * tem + 0.7 * tempref0bias;//find a mixed value between camera and auto grey
nocam = 8;
}
} else if (abs(deltemp) >= 1500. && tempref0bias >= 5500.f) {
if (tem >= 10000.f) {
tem = 0.99 * tem + 0.01 * tempref0bias;//find a mixed value between camera and auto grey
nocam = 9;
} else {
if ((pargre && pargref) || (!pargre && !pargref)) {
tem = 0.45 * tem + 0.55 * tempref0bias;//find a mixed value between camera and auto grey
}
if (pargre && !pargref) {
tem = 0.7 * tem + 0.3 * tempref0bias;//find a mixed value between camera and auto grey
}
if (!pargre && pargref) {
tem = 0.3 * tem + 0.7 * tempref0bias;//find a mixed value between camera and auto grey
}
nocam = 10;
}
} else {
tem = 0.4 * tem + 0.6 * tempref0bias;
nocam = 11;
}
}
}
tempitc = tem ;
extra = true;
if (settings->verbose) {
printf("Using new references AWB grey or mixed Enable Extra - temgrey=%f gregrey=%f tempitc=%f nocam=%i\n", (double) tem, (double) gre, (double) tempitc, nocam);
}
}
}
params.wb.method = "autitcgreen";
}
float greenitc_low = 1.f;
float tempitc_low = 5000.f;
{
double rm, gm, bm;
greenitc = 1.;
currWBitc = imgsrc->getWB();
currWBitc = currWBitc.convertObserver(params.wb.observer);//change the temp/green couple with the same multipliers
double tempref = currWBitc.getTemp() * (1. + params.wb.tempBias);
double greenref = currWBitc.getGreen();
greenitc = greenref;
if ((greenref > 1.5f || tempref0bias < 3300.f || tempref0bias > 7700.f || forcewbgrey) && autowb1 && kcam != 1 && !params.wb.itcwb_sampling) { //probably camera out to adjust = greenref ? tempref0bias ?
tempref = tem * (1. + params.wb.tempBias);
greenref = gre;
} else {
}
if(params.wb.itcwb_sampling) {
greenitc_low = greenref;
tempitc_low = tempref;
}
if (settings->verbose && params.wb.method == "autitcgreen") {
printf("tempref=%f greref=%f tempitc=%f greenitc=%f\n", tempref, greenref, tempitc, greenitc);
}
imgsrc->getAutoWBMultipliersitc(extra, tempref, greenref, tempitc, greenitc, temp0, delta, bia, dread, kcam, nocam, studgood, minchrom, kmin, minhist, maxhist, 0, 0, fh, fw, 0, 0, fh, fw, rm, gm, bm, params.wb, params.icm, params.raw, params.toneCurve);
params.wb.temperature = tempitc;
params.wb.green = greenitc;
if(params.wb.itcwb_sampling) {
params.wb.temperature = tempitc_low;
params.wb.green = greenitc_low;
}
currWB = ColorTemp(params.wb.temperature, params.wb.green, 1., params.wb.method, params.wb.observer);
currWB.getMultipliers(rm, gm, bm);
autoWB.update(rm, gm, bm, params.wb.equal, params.wb.observer, params.wb.tempBias);
}
double rm;
double gm;
double bm;
imgsrc->getAutoWBMultipliersItcGreen(
params,
forcewbgrey,
kcam,
greenitc,
extra,
temp0,
delta,
bia,
dread,
nocam,
studgood,
minchrom,
kmin,
minhist,
maxhist,
fh,
fw,
currWB,
0,
0.,
false,
autoWB,
rm,
gm,
bm);
currWB = autoWB;
} else if (params.wb.method == "autitcgreen" && params.wb.compat_version == 1 && !imgsrc->isRAW() && flush) {
// ITCWB compatibility version 1 used 5000 K and observer 10 degrees
// for non-raw files.
currWB = ColorTemp(5000., 1., 1., params.wb.method, StandardObserver::TEN_DEGREES);
currWB.convertObserver(params.wb.observer);
params.wb.temperature = currWB.getTemp();
params.wb.green = currWB.getGreen();
params.wb.equal = currWB.getEqual();
}
//end WB auto