further cleanups and speedups for ItcWB/getrgbloc

This commit is contained in:
Ingo Weyrich
2020-03-01 11:50:58 +01:00
parent 95b238ca5d
commit d0034c880b
6 changed files with 36 additions and 107 deletions

View File

@@ -123,7 +123,7 @@ public:
virtual ColorTemp getWB () const = 0; virtual ColorTemp getWB () const = 0;
virtual ColorTemp getSpotWB (std::vector<Coord2D> &red, std::vector<Coord2D> &green, std::vector<Coord2D> &blue, int tran, double equal) = 0; virtual ColorTemp getSpotWB (std::vector<Coord2D> &red, std::vector<Coord2D> &green, std::vector<Coord2D> &blue, int tran, double equal) = 0;
virtual void WBauto(double &tempref, double &greenref, array2D<float> &redloc, array2D<float> &greenloc, array2D<float> &blueloc, int bfw, int bfh, double &avg_rm, double &avg_gm, double &avg_bm, double &tempitc, double &greenitc, float &studgood, bool &twotimes, const procparams::WBParams & wbpar, int begx, int begy, int yEn, int xEn, int cx, int cy, const procparams::ColorManagementParams &cmp, const procparams::RAWParams &raw) = 0; virtual void WBauto(double &tempref, double &greenref, array2D<float> &redloc, array2D<float> &greenloc, array2D<float> &blueloc, int bfw, int bfh, double &avg_rm, double &avg_gm, double &avg_bm, double &tempitc, double &greenitc, float &studgood, bool &twotimes, const procparams::WBParams & wbpar, int begx, int begy, int yEn, int xEn, int cx, int cy, const procparams::ColorManagementParams &cmp, const procparams::RAWParams &raw) = 0;
virtual void getrgbloc(bool local, bool gamma, bool cat02, int begx, int begy, int yEn, int xEn, int cx, int cy, int bf_h, int bf_w) = 0; virtual void getrgbloc(int begx, int begy, int yEn, int xEn, int cx, int cy, int bf_h, int bf_w) = 0;
virtual double getDefGain () const virtual double getDefGain () const
{ {

View File

@@ -391,7 +391,7 @@ void ImProcCoordinator::updatePreviewImage(int todo, bool panningRelatedChange)
if (todo & (M_INIT | M_LINDENOISE | M_HDR)) { if (todo & (M_INIT | M_LINDENOISE | M_HDR)) {
if (params->wb.method == "autitcgreen") { if (params->wb.method == "autitcgreen") {
imgsrc->getrgbloc(false, false, false, 0, 0, fh, fw, 0, 0, fh, fw); imgsrc->getrgbloc(0, 0, fh, fw, 0, 0, fh, fw);
} }
} }
@@ -411,8 +411,7 @@ void ImProcCoordinator::updatePreviewImage(int todo, bool panningRelatedChange)
} }
} }
bool autowb = false; const bool autowb = (params->wb.method == "autold" || params->wb.method == "autitcgreen");
autowb = (params->wb.method == "autold" || params->wb.method == "aut" || params->wb.method == "autosdw" || params->wb.method == "autedgsdw" || params->wb.method == "autitcgreen" || params->wb.method == "autedgrob" || params->wb.method == "autedg" || params->wb.method == "autorobust");
if (settings->verbose) { if (settings->verbose) {
printf("automethod=%s \n", params->wb.method.c_str()); printf("automethod=%s \n", params->wb.method.c_str());
} }

View File

@@ -3407,7 +3407,7 @@ void RawImageSource::HLRecovery_blend(float* rin, float* gin, float* bin, int wi
constexpr float trans[ColorCount][ColorCount] = { { 1, 1, 1 }, { 1.7320508, -1.7320508, 0 }, { -1, -1, 2 } }; constexpr float trans[ColorCount][ColorCount] = { { 1, 1, 1 }, { 1.7320508, -1.7320508, 0 }, { -1, -1, 2 } };
constexpr float itrans[ColorCount][ColorCount] = { { 1, 0.8660254, -0.5 }, { 1, -0.8660254, -0.5 }, { 1, 0, 1 } }; constexpr float itrans[ColorCount][ColorCount] = { { 1, 0.8660254, -0.5 }, { 1, -0.8660254, -0.5 }, { 1, 0, 1 } };
float minpt = min(hlmax[0], hlmax[1], hlmax[2]); //min of the raw clip points float minpt = rtengine::min(hlmax[0], hlmax[1], hlmax[2]); //min of the raw clip points
//float maxpt=max(hlmax[0],hlmax[1],hlmax[2]);//max of the raw clip points //float maxpt=max(hlmax[0],hlmax[1],hlmax[2]);//max of the raw clip points
//float medpt=hlmax[0]+hlmax[1]+hlmax[2]-minpt-maxpt;//median of the raw clip points //float medpt=hlmax[0]+hlmax[1]+hlmax[2]-minpt-maxpt;//median of the raw clip points
float maxave = (hlmax[0] + hlmax[1] + hlmax[2]) / 3; //ave of the raw clip points float maxave = (hlmax[0] + hlmax[1] + hlmax[2]) / 3; //ave of the raw clip points
@@ -3418,7 +3418,7 @@ void RawImageSource::HLRecovery_blend(float* rin, float* gin, float* bin, int wi
float clip[3]; float clip[3];
for (int c = 0; c < ColorCount; ++c) { for (int c = 0; c < ColorCount; ++c) {
clip[c] = min(maxave, hlmax[c]); clip[c] = rtengine::min(maxave, hlmax[c]);
} }
// Determine the maximum level (clip) of all channels // Determine the maximum level (clip) of all channels
@@ -3473,7 +3473,7 @@ void RawImageSource::HLRecovery_blend(float* rin, float* gin, float* bin, int wi
} }
} }
chratio = (std::sqrt(sum[1] / sum[0])); chratio = std::sqrt(sum[1] / sum[0]);
// Apply ratio to lightness in LCH space // Apply ratio to lightness in LCH space
for (int c = 1; c < ColorCount; c++) { for (int c = 1; c < ColorCount; c++) {
@@ -4341,7 +4341,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double
{ {
/* /*
Copyright (c) Jacques Desmis 6 - 2018 jdesmis@gmail.com Copyright (c) Jacques Desmis 6 - 2018 jdesmis@gmail.com
Copyright (c) Ingo Weirich 3 - 2020 (heckflosse67@gmx.de) Copyright (c) Ingo Weyrich 3 - 2020 (heckflosse67@gmx.de)
This algorithm try to find temperature correlation between 20 to 200 color between 200 spectral color and about 20 to 55 color found in the image, I just found the idea in the web "correlate with chroma" instead of RGB grey point,but I don't use any algo found on the web. This algorithm try to find temperature correlation between 20 to 200 color between 200 spectral color and about 20 to 55 color found in the image, I just found the idea in the web "correlate with chroma" instead of RGB grey point,but I don't use any algo found on the web.
@@ -4416,8 +4416,8 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double
{static_cast<float>(wiprof[2][0]), static_cast<float>(wiprof[2][1]), static_cast<float>(wiprof[2][2])} {static_cast<float>(wiprof[2][0]), static_cast<float>(wiprof[2][1]), static_cast<float>(wiprof[2][2])}
}; };
const int bfwitc = bfw / 10 + 1 ;// 10 arbitrary value ; perhaps 4 or 5 or 20 const int bfwitc = bfw;
const int bfhitc = bfh / 10 + 1; const int bfhitc = bfh;
typedef struct WbGreen { typedef struct WbGreen {
double green; double green;
@@ -4552,7 +4552,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double
} RangeGreen; } RangeGreen;
constexpr RangeGreen Rangestandard = {8, 70}; constexpr RangeGreen Rangestandard = {8, 70};
constexpr RangeGreen Rangeextand = {4, 77}; constexpr RangeGreen Rangeextended = {4, 77};
const RangeGreen Rangemax = {0, N_g}; const RangeGreen Rangemax = {0, N_g};
RangeGreen Rangegreenused; RangeGreen Rangegreenused;
@@ -4560,7 +4560,7 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double
if (settings->itcwb_greenrange == 0) { if (settings->itcwb_greenrange == 0) {
Rangegreenused = Rangestandard; Rangegreenused = Rangestandard;
} else if (settings->itcwb_greenrange == 1) { } else if (settings->itcwb_greenrange == 1) {
Rangegreenused = Rangeextand; Rangegreenused = Rangeextended;
} else { } else {
Rangegreenused = Rangemax; Rangegreenused = Rangemax;
} }
@@ -4816,13 +4816,12 @@ void RawImageSource::ItcWB(bool extra, double &tempref, double &greenref, double
#ifdef _OPENMP #ifdef _OPENMP
#pragma omp parallel for #pragma omp parallel for
#endif #endif
for (int y = 0; y < bfh ; y += 10) { for (int y = 0; y < bfh ; ++y) {
int yy = y / 10; for (int x = 0; x < bfw ; ++x) {
for (int x = 0, xx = 0; x < bfw ; x += 10, ++xx) {
const float RR = rmm[rep] * redloc[y][x]; const float RR = rmm[rep] * redloc[y][x];
const float GG = gmm[rep] * greenloc[y][x]; const float GG = gmm[rep] * greenloc[y][x];
const float BB = bmm[rep] * blueloc[y][x]; const float BB = bmm[rep] * blueloc[y][x];
Color::rgbxyY(RR, GG, BB, xc[yy][xx], yc[yy][xx], Yc[yy][xx], wp); Color::rgbxyY(RR, GG, BB, xc[y][x], yc[y][x], Yc[y][x], wp);
} }
} }
//histogram xy depend of temp...but in most cases D45 ..D65.. //histogram xy depend of temp...but in most cases D45 ..D65..
@@ -5217,15 +5216,12 @@ void RawImageSource::WBauto(double & tempref, double & greenref, array2D<float>
} }
} }
void RawImageSource::getrgbloc(bool local, bool gamma, bool cat02, int begx, int begy, int yEn, int xEn, int cx, int cy, int bf_h, int bf_w) void RawImageSource::getrgbloc(int begx, int begy, int yEn, int xEn, int cx, int cy, int bf_h, int bf_w)
{ {
BENCHFUN
//used by auto WB local to calculate red, green, blue in local region //used by auto WB local to calculate red, green, blue in local region
int bfh = H, bfw = W; const int bfw = W / 10 + 1 ;// 10 arbitrary value ; perhaps 4 or 5 or 20
const int bfh = H / 10 + 1;
if (local) {
bfh = bf_h + 3;
bfw = bf_w + 3;
}
if (! greenloc) { if (! greenloc) {
greenloc(bfw, bfh); greenloc(bfw, bfh);
@@ -5240,73 +5236,17 @@ void RawImageSource::getrgbloc(bool local, bool gamma, bool cat02, int begx, in
} }
double avgL = 0.0; double avgL = 0.0;
//center data on normal values //center data on normal values
int nn = 0; int nn = 0;
if (!local) {
#ifdef _OPENMP
#pragma omp parallel sections
#endif
{
#ifdef _OPENMP
#pragma omp section
#endif
{
for (int i = 0; i < H; i ++) {
for (int j = 0; j < W; j++) {
redloc[i][j] = red[i][j];
}
}
}
#ifdef _OPENMP
#pragma omp section
#endif
{
for (int i = 0; i < H; i ++) {
for (int j = 0; j < W; j++) {
greenloc[i][j] = green[i][j];
}
}
}
#ifdef _OPENMP
#pragma omp section
#endif
{
for (int i = 0; i < H; i ++) {
for (int j = 0; j < W; j++) {
blueloc[i][j] = blue[i][j];
}
}
}
}
}
#ifdef _OPENMP #ifdef _OPENMP
#pragma omp parallel for reduction(+:avgL, nn) #pragma omp parallel for reduction(+:avgL, nn)
#endif #endif
for (int i = 0; i < H; i ++) { for (int i = 0; i < H; i ++) {
for (int j = 0; j < W; j++) { for (int j = 0; j < W; j++) {
int lox = cx + j; const float LL = 0.299f * red[i][j] + 0.587f * green[i][j] + 0.114f * blue[i][j];
int loy = cy + i; avgL += static_cast<double>(LL);
nn++;
if (!local) {
const float redmm = redloc[i][j];
const float greenmm = greenloc[i][j];
const float bluemm = blueloc[i][j];
const float LL = 0.299f * redmm + 0.587f * greenmm + 0.114f * bluemm;
avgL += static_cast<double>(LL);
nn++;
} else {
if (lox >= begx && lox < xEn && loy >= begy && loy < yEn) {
const float redmm = redloc[loy - begy][lox - begx] = red[i][j];
const float greenmm = greenloc[loy - begy][lox - begx] = green[i][j];
const float bluemm = blueloc[loy - begy][lox - begx] = blue[i][j];
const float LL = 0.299f * redmm + 0.587f * greenmm + 0.114f * bluemm;
avgL += static_cast<double>(LL);
nn++;
}
}
} }
} }
avgL /= nn; avgL /= nn;
@@ -5317,9 +5257,9 @@ void RawImageSource::getrgbloc(bool local, bool gamma, bool cat02, int begx, in
#ifdef _OPENMP #ifdef _OPENMP
#pragma omp parallel for reduction(+:vari, mm) #pragma omp parallel for reduction(+:vari, mm)
#endif #endif
for (int i = 0; i < bfh; i++) for (int i = 0; i < H; i++)
for (int j = 0; j < bfw; j++) { for (int j = 0; j < W; j++) {
float LL = 0.299f * redloc[i][j] + 0.587f * greenloc[i][j] + 0.114f * blueloc[i][j]; const float LL = 0.299f * red[i][j] + 0.587f * green[i][j] + 0.114f * blue[i][j];
vari += SQR(LL - avgL); vari += SQR(LL - avgL);
mm++; mm++;
} }
@@ -5330,23 +5270,15 @@ void RawImageSource::getrgbloc(bool local, bool gamma, bool cat02, int begx, in
#ifdef _OPENMP #ifdef _OPENMP
#pragma omp parallel for #pragma omp parallel for
#endif #endif
for (int i = 0; i < bfh; i++) for (int i = 0; i < bfh; ++i) {
for (int j = 0; j < bfw; j++) { const int ii = i * 10;
redloc[i][j] *= multip; if (ii < H) {
greenloc[i][j] *= multip; for (int j = 0, jj = 0; jj < W; ++j, jj += 10) {
blueloc[i][j] *= multip; redloc[i][j] = red[ii][jj] * multip;
} greenloc[i][j] = green[ii][jj] * multip;
blueloc[i][j] = blue[ii][jj] * multip;
if (gamma) {
#ifdef _OPENMP
#pragma omp parallel for
#endif
for (int i = 0; i < bfh; i++)
for (int j = 0; j < bfw; j++) {
redloc[i][j] = Color::gammatab_srgb[redloc[i][j]];
greenloc[i][j] = Color::gammatab_srgb[greenloc[i][j]];
blueloc[i][j] = Color::gammatab_srgb[blueloc[i][j]];
} }
}
} }
} }
@@ -5365,7 +5297,6 @@ void RawImageSource::getAutoWBMultipliersitc(double & tempref, double & greenref
double avg_b = 0; double avg_b = 0;
int rn = 0, gn = 0, bn = 0; int rn = 0, gn = 0, bn = 0;
double avg_rm, avg_gm, avg_bm; double avg_rm, avg_gm, avg_bm;
int bfh = H, bfw = W;
if (wbpar.method == "autold") { if (wbpar.method == "autold") {
if (fuji) { if (fuji) {
for (int i = 32; i < H - 32; i++) { for (int i = 32; i < H - 32; i++) {
@@ -5542,6 +5473,8 @@ void RawImageSource::getAutoWBMultipliersitc(double & tempref, double & greenref
if (wbpar.method == "autitcgreen") { if (wbpar.method == "autitcgreen") {
bool twotimes = false; bool twotimes = false;
const int bfw = W / 10 + 1 ;// 10 arbitrary value ; perhaps 4 or 5 or 20
const int bfh = H / 10 + 1;
WBauto(tempref, greenref, redloc, greenloc, blueloc, bfw, bfh, avg_rm, avg_gm, avg_bm, tempitc, greenitc, studgood, twotimes, wbpar, begx, begy, yEn, xEn, cx, cy, cmp, raw); WBauto(tempref, greenref, redloc, greenloc, blueloc, bfw, bfh, avg_rm, avg_gm, avg_bm, tempitc, greenitc, studgood, twotimes, wbpar, begx, begy, yEn, xEn, cx, cy, cmp, raw);
} }

View File

@@ -144,7 +144,7 @@ public:
void scaleColors (int winx, int winy, int winw, int winh, const procparams::RAWParams &raw, array2D<float> &rawData); // raw for cblack void scaleColors (int winx, int winy, int winw, int winh, const procparams::RAWParams &raw, array2D<float> &rawData); // raw for cblack
void WBauto(double &tempref, double &greenref, array2D<float> &redloc, array2D<float> &greenloc, array2D<float> &blueloc, int bfw, int bfh, double &avg_rm, double &avg_gm, double &avg_bm, double &tempitc, double &greenitc, float &studgood, bool &twotimes, const procparams::WBParams & wbpar, int begx, int begy, int yEn, int xEn, int cx, int cy, const procparams::ColorManagementParams &cmp, const procparams::RAWParams &raw) override; void WBauto(double &tempref, double &greenref, array2D<float> &redloc, array2D<float> &greenloc, array2D<float> &blueloc, int bfw, int bfh, double &avg_rm, double &avg_gm, double &avg_bm, double &tempitc, double &greenitc, float &studgood, bool &twotimes, const procparams::WBParams & wbpar, int begx, int begy, int yEn, int xEn, int cx, int cy, const procparams::ColorManagementParams &cmp, const procparams::RAWParams &raw) override;
void getAutoWBMultipliersitc(double &tempref, double &greenref, double &tempitc, double &greenitc, float &studgood, int begx, int begy, int yEn, int xEn, int cx, int cy, int bf_h, int bf_w, double &rm, double &gm, double &bm, const procparams::WBParams & wbpar, const procparams::ColorManagementParams &cmp, const procparams::RAWParams &raw) override; void getAutoWBMultipliersitc(double &tempref, double &greenref, double &tempitc, double &greenitc, float &studgood, int begx, int begy, int yEn, int xEn, int cx, int cy, int bf_h, int bf_w, double &rm, double &gm, double &bm, const procparams::WBParams & wbpar, const procparams::ColorManagementParams &cmp, const procparams::RAWParams &raw) override;
void getrgbloc(bool local, bool gamma, bool cat02, int begx, int begy, int yEn, int xEn, int cx, int cy, int bf_h, int bf_w) override; void getrgbloc(int begx, int begy, int yEn, int xEn, int cx, int cy, int bf_h, int bf_w) override;
void getImage (const ColorTemp &ctemp, int tran, Imagefloat* image, const PreviewProps &pp, const procparams::ToneCurveParams &hrp, const procparams::RAWParams &raw) override; void getImage (const ColorTemp &ctemp, int tran, Imagefloat* image, const PreviewProps &pp, const procparams::ToneCurveParams &hrp, const procparams::RAWParams &raw) override;
eSensorType getSensorType () const override; eSensorType getSensorType () const override;

View File

@@ -315,9 +315,6 @@ void StdImageSource::WBauto(double &tempref, double &greenref, array2D<float> &r
{ {
} }
void StdImageSource::getrgbloc(bool local, bool gamma, bool cat02, int begx, int begy, int yEn, int xEn, int cx, int cy, int bf_h, int bf_w)
{}
void StdImageSource::getAutoWBMultipliersitc(double &tempref, double &greenref, double &tempitc, double &greenitc, float &studgood, int begx, int begy, int yEn, int xEn, int cx, int cy, int bf_h, int bf_w, double &rm, double &gm, double &bm, const WBParams & wbpar, const ColorManagementParams &cmp, const RAWParams &raw) void StdImageSource::getAutoWBMultipliersitc(double &tempref, double &greenref, double &tempitc, double &greenitc, float &studgood, int begx, int begy, int yEn, int xEn, int cx, int cy, int bf_h, int bf_w, double &rm, double &gm, double &bm, const WBParams & wbpar, const ColorManagementParams &cmp, const RAWParams &raw)
{ {
if (redAWBMul != -1.) { if (redAWBMul != -1.) {

View File

@@ -58,7 +58,7 @@ public:
int load (const Glib::ustring &fname) override; int load (const Glib::ustring &fname) override;
void getImage (const ColorTemp &ctemp, int tran, Imagefloat* image, const PreviewProps &pp, const procparams::ToneCurveParams &hrp, const procparams::RAWParams &raw) override; void getImage (const ColorTemp &ctemp, int tran, Imagefloat* image, const PreviewProps &pp, const procparams::ToneCurveParams &hrp, const procparams::RAWParams &raw) override;
void getrgbloc(bool local, bool gamma, bool cat02, int begx, int begy, int yEn, int xEn, int cx, int cy, int bf_h, int bf_w) override; void getrgbloc (int begx, int begy, int yEn, int xEn, int cx, int cy, int bf_h, int bf_w) override {};
ColorTemp getWB () const override ColorTemp getWB () const override
{ {
return wb; return wb;