further cleanup of rtengine/PF_correct_RT.cc
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
//
|
//
|
||||||
// code dated: November 24, 2010
|
// code dated: November 24, 2010
|
||||||
// optimized: September 2013, Ingo Weyrich
|
// optimized: September 2013, Ingo Weyrich
|
||||||
|
// further optimized: February 2018, Ingo Weyrich
|
||||||
//
|
//
|
||||||
// PF_correct_RT.cc is free software: you can redistribute it and/or modify
|
// PF_correct_RT.cc is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU General Public License as published by
|
// it under the terms of the GNU General Public License as published by
|
||||||
@@ -95,7 +96,7 @@ void ImProcFunctions::PF_correct_RT(LabImage * src, double radius, int thresh)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // __SSE2__
|
#endif
|
||||||
|
|
||||||
for(int j = 0; j < width; j++) {
|
for(int j = 0; j < width; j++) {
|
||||||
if (chCurve) {
|
if (chCurve) {
|
||||||
@@ -112,10 +113,10 @@ void ImProcFunctions::PF_correct_RT(LabImage * src, double radius, int thresh)
|
|||||||
chparam *= 2.f; // increased action if chparam < 0
|
chparam *= 2.f; // increased action if chparam < 0
|
||||||
}
|
}
|
||||||
|
|
||||||
chromaChfactor = 1.f + chparam;
|
chromaChfactor = SQR(1.f + chparam);
|
||||||
}
|
}
|
||||||
|
|
||||||
float chroma = SQR(chromaChfactor * (src->a[i][j] - tmpa[i][j])) + SQR(chromaChfactor * (src->b[i][j] - tmpb[i][j])); //modulate chroma function hue
|
float chroma = chromaChfactor * (SQR(src->a[i][j] - tmpa[i][j]) + SQR(src->b[i][j] - tmpb[i][j])); //modulate chroma function hue
|
||||||
chromave += chroma;
|
chromave += chroma;
|
||||||
fringe[i * width + j] = chroma;
|
fringe[i * width + j] = chroma;
|
||||||
}
|
}
|
||||||
@@ -123,7 +124,8 @@ void ImProcFunctions::PF_correct_RT(LabImage * src, double radius, int thresh)
|
|||||||
}
|
}
|
||||||
|
|
||||||
chromave /= (height * width);
|
chromave /= (height * width);
|
||||||
|
std::cout << chromave << std::endl;
|
||||||
|
if(chromave > 0.f) {
|
||||||
// now as chromave is calculated, we postprocess fringe to reduce the number of divisions in future
|
// now as chromave is calculated, we postprocess fringe to reduce the number of divisions in future
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
#pragma omp parallel for simd
|
#pragma omp parallel for simd
|
||||||
@@ -216,7 +218,7 @@ void ImProcFunctions::PF_correct_RT(LabImage * src, double radius, int thresh)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}//end of ab channel averaging
|
}//end of ab channel averaging
|
||||||
|
}
|
||||||
if(chCurve) {
|
if(chCurve) {
|
||||||
delete chCurve;
|
delete chCurve;
|
||||||
}
|
}
|
||||||
@@ -237,7 +239,6 @@ void ImProcFunctions::PF_correct_RTcam(CieImage * src, double radius, int thresh
|
|||||||
|
|
||||||
// local variables
|
// local variables
|
||||||
const int width = src->W, height = src->H;
|
const int width = src->W, height = src->H;
|
||||||
constexpr float eps2 = 0.01f;
|
|
||||||
|
|
||||||
//temporary array to store chromaticity
|
//temporary array to store chromaticity
|
||||||
float *fringe = new float[width * height];
|
float *fringe = new float[width * height];
|
||||||
@@ -298,8 +299,7 @@ void ImProcFunctions::PF_correct_RTcam(CieImage * src, double radius, int thresh
|
|||||||
#pragma omp for
|
#pragma omp for
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for(int i = 0; i < height; i++ )
|
for(int i = 0; i < height; i++ ) {
|
||||||
{
|
|
||||||
int j = 0;
|
int j = 0;
|
||||||
for(; j < width - 3; j += 4) {
|
for(; j < width - 3; j += 4) {
|
||||||
STVFU(fringe[i * width + j], xatan2f(LVFU(srbb[i][j]), LVFU(sraa[i][j])));
|
STVFU(fringe[i * width + j], xatan2f(LVFU(srbb[i][j]), LVFU(sraa[i][j])));
|
||||||
@@ -339,10 +339,10 @@ void ImProcFunctions::PF_correct_RTcam(CieImage * src, double radius, int thresh
|
|||||||
chparam *= 2.f; // increase action if chparam < 0
|
chparam *= 2.f; // increase action if chparam < 0
|
||||||
}
|
}
|
||||||
|
|
||||||
chromaChfactor = 1.f + chparam;
|
chromaChfactor = SQR(1.f + chparam);
|
||||||
}
|
}
|
||||||
|
|
||||||
float chroma = SQR(chromaChfactor * (sraa[i][j] - tmaa[i][j])) + SQR(chromaChfactor * (srbb[i][j] - tmbb[i][j])); //modulate chroma function hue
|
float chroma = chromaChfactor * (SQR(sraa[i][j] - tmaa[i][j]) + SQR(srbb[i][j] - tmbb[i][j])); //modulate chroma function hue
|
||||||
chromave += chroma;
|
chromave += chroma;
|
||||||
fringe[i * width + j] = chroma;
|
fringe[i * width + j] = chroma;
|
||||||
}
|
}
|
||||||
@@ -351,16 +351,17 @@ void ImProcFunctions::PF_correct_RTcam(CieImage * src, double radius, int thresh
|
|||||||
|
|
||||||
chromave /= (height * width);
|
chromave /= (height * width);
|
||||||
|
|
||||||
|
if(chromave > 0.f) {
|
||||||
// now as chromave is calculated, we postprocess fringe to reduce the number of divisions in future
|
// now as chromave is calculated, we postprocess fringe to reduce the number of divisions in future
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
#pragma omp parallel for simd
|
#pragma omp parallel for simd
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for(int j = 0; j < width * height; j++) {
|
for(int j = 0; j < width * height; j++) {
|
||||||
fringe[j] = 1.f / (fringe[j] + chromave + eps2);
|
fringe[j] = 1.f / (fringe[j] + chromave);
|
||||||
}
|
}
|
||||||
|
|
||||||
const float threshfactor = 1.f / (SQR(thresh / 33.f) * chromave * 5.0f + chromave + eps2);
|
const float threshfactor = 1.f / (SQR(thresh / 33.f) * chromave * 5.0f + chromave);
|
||||||
|
|
||||||
// Issue 1674:
|
// Issue 1674:
|
||||||
// often, CA isn't evenly distributed, e.g. a lot in contrasty regions and none in the sky.
|
// often, CA isn't evenly distributed, e.g. a lot in contrasty regions and none in the sky.
|
||||||
@@ -475,6 +476,7 @@ void ImProcFunctions::PF_correct_RTcam(CieImage * src, double radius, int thresh
|
|||||||
src->C_p[i][j] = sqrt(SQR(interb) + SQR(intera));
|
src->C_p[i][j] = sqrt(SQR(interb) + SQR(intera));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(chCurve) {
|
if(chCurve) {
|
||||||
delete chCurve;
|
delete chCurve;
|
||||||
@@ -491,7 +493,6 @@ void ImProcFunctions::Badpixelscam(CieImage * src, double radius, int thresh, in
|
|||||||
const int width = src->W, height = src->H;
|
const int width = src->W, height = src->H;
|
||||||
|
|
||||||
constexpr float eps = 1.f;
|
constexpr float eps = 1.f;
|
||||||
constexpr float eps2 = 0.01f;
|
|
||||||
|
|
||||||
const JaggedArray<float> tmL(width, height);
|
const JaggedArray<float> tmL(width, height);
|
||||||
|
|
||||||
@@ -546,7 +547,7 @@ void ImProcFunctions::Badpixelscam(CieImage * src, double radius, int thresh, in
|
|||||||
shmedv += vabsf(LVFU(src->sh_p[i1][j1]) - LVFU(tmL[i1][j1]));
|
shmedv += vabsf(LVFU(src->sh_p[i1][j1]) - LVFU(tmL[i1][j1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
STVFU(badpix[i * width + j], vself(vmaskf_gt(shfabsv, (shmedv - shfabsv) * shthrv), onev, ZEROV));
|
STVFU(badpix[i * width + j], vselfzero(vmaskf_gt(shfabsv, (shmedv - shfabsv) * shthrv), onev));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
for (; j < width - 2; j++) {
|
for (; j < width - 2; j++) {
|
||||||
@@ -825,13 +826,14 @@ void ImProcFunctions::Badpixelscam(CieImage * src, double radius, int thresh, in
|
|||||||
|
|
||||||
chrommed /= (height * width);
|
chrommed /= (height * width);
|
||||||
|
|
||||||
|
if(chrommed > 0.f) {
|
||||||
// now chrommed is calculated, so we postprocess badpix to reduce the number of divisions in future
|
// now chrommed is calculated, so we postprocess badpix to reduce the number of divisions in future
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
#pragma omp parallel
|
#pragma omp parallel
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#ifdef __SSE2__
|
#ifdef __SSE2__
|
||||||
vfloat sumv = F2V(chrommed + eps2);
|
vfloat chrommedv = F2V(chrommed);
|
||||||
vfloat onev = F2V(1.f);
|
vfloat onev = F2V(1.f);
|
||||||
#endif
|
#endif
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
@@ -842,16 +844,16 @@ void ImProcFunctions::Badpixelscam(CieImage * src, double radius, int thresh, in
|
|||||||
int j = 0;
|
int j = 0;
|
||||||
#ifdef __SSE2__
|
#ifdef __SSE2__
|
||||||
for(; j < width - 3; j += 4) {
|
for(; j < width - 3; j += 4) {
|
||||||
STVFU(badpix[i * width + j], onev / (LVFU(badpix[i * width + j]) + sumv));
|
STVFU(badpix[i * width + j], onev / (LVFU(badpix[i * width + j]) + chrommedv));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
for(; j < width; j++) {
|
for(; j < width; j++) {
|
||||||
badpix[i * width + j] = 1.f / (badpix[i * width + j] + chrommed + eps2);
|
badpix[i * width + j] = 1.f / (badpix[i * width + j] + chrommed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const float threshfactor = 1.f / ((thresh * chrommed) / 33.f + chrommed + eps2);
|
const float threshfactor = 1.f / ((thresh * chrommed) / 33.f + chrommed);
|
||||||
|
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
#pragma omp parallel for schedule(dynamic,16)
|
#pragma omp parallel for schedule(dynamic,16)
|
||||||
@@ -946,7 +948,7 @@ void ImProcFunctions::Badpixelscam(CieImage * src, double radius, int thresh, in
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
delete [] badpix;
|
delete [] badpix;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -959,7 +961,6 @@ void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, in
|
|||||||
const int width = src->W, height = src->H;
|
const int width = src->W, height = src->H;
|
||||||
|
|
||||||
constexpr float eps = 1.f;
|
constexpr float eps = 1.f;
|
||||||
constexpr float eps2 = 0.01f;
|
|
||||||
|
|
||||||
const JaggedArray<float> tmL(width, height);
|
const JaggedArray<float> tmL(width, height);
|
||||||
|
|
||||||
@@ -995,11 +996,11 @@ void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, in
|
|||||||
float shfabs = fabs(src->L[i][j] - tmL[i][j]);
|
float shfabs = fabs(src->L[i][j] - tmL[i][j]);
|
||||||
float shmed = 0.0f;
|
float shmed = 0.0f;
|
||||||
|
|
||||||
for (int i1 = max(0, i - 2); i1 <= min(i + 2, height - 1); i1++ )
|
for (int i1 = max(0, i - 2); i1 <= min(i + 2, height - 1); i1++) {
|
||||||
for (int j1 = 0; j1 <= j + 2; j1++) {
|
for (int j1 = 0; j1 <= j + 2; j1++) {
|
||||||
shmed += fabs(src->L[i1][j1] - tmL[i1][j1]);
|
shmed += fabs(src->L[i1][j1] - tmL[i1][j1]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
badpix[i * width + j] = (shfabs > ((shmed - shfabs) * shthr));
|
badpix[i * width + j] = (shfabs > ((shmed - shfabs) * shthr));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1009,23 +1010,23 @@ void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, in
|
|||||||
vfloat shfabsv = vabsf(LVFU(src->L[i][j]) - LVFU(tmL[i][j]));
|
vfloat shfabsv = vabsf(LVFU(src->L[i][j]) - LVFU(tmL[i][j]));
|
||||||
vfloat shmedv = ZEROV;
|
vfloat shmedv = ZEROV;
|
||||||
|
|
||||||
for (int i1 = max(0, i - 2); i1 <= min(i + 2, height - 1); i1++ )
|
for (int i1 = max(0, i - 2); i1 <= min(i + 2, height - 1); i1++) {
|
||||||
for (int j1 = j - 2; j1 <= j + 2; j1++) {
|
for (int j1 = j - 2; j1 <= j + 2; j1++) {
|
||||||
shmedv += vabsf(LVFU(src->L[i1][j1]) - LVFU(tmL[i1][j1]));
|
shmedv += vabsf(LVFU(src->L[i1][j1]) - LVFU(tmL[i1][j1]));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
STVFU(badpix[i * width + j], vself(vmaskf_gt(shfabsv, (shmedv - shfabsv) * shthrv), onev, ZEROV));
|
STVFU(badpix[i * width + j], vselfzero(vmaskf_gt(shfabsv, (shmedv - shfabsv) * shthrv), onev));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
for (; j < width - 2; j++) {
|
for (; j < width - 2; j++) {
|
||||||
float shfabs = fabs(src->L[i][j] - tmL[i][j]);
|
float shfabs = fabs(src->L[i][j] - tmL[i][j]);
|
||||||
float shmed = 0.0f;
|
float shmed = 0.0f;
|
||||||
|
|
||||||
for (int i1 = max(0, i - 2); i1 <= min(i + 2, height - 1); i1++ )
|
for (int i1 = max(0, i - 2); i1 <= min(i + 2, height - 1); i1++) {
|
||||||
for (int j1 = j - 2; j1 <= j + 2; j1++) {
|
for (int j1 = j - 2; j1 <= j + 2; j1++) {
|
||||||
shmed += fabs(src->L[i1][j1] - tmL[i1][j1]);
|
shmed += fabs(src->L[i1][j1] - tmL[i1][j1]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
badpix[i * width + j] = (shfabs > ((shmed - shfabs) * shthr));
|
badpix[i * width + j] = (shfabs > ((shmed - shfabs) * shthr));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1033,11 +1034,11 @@ void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, in
|
|||||||
float shfabs = fabs(src->L[i][j] - tmL[i][j]);
|
float shfabs = fabs(src->L[i][j] - tmL[i][j]);
|
||||||
float shmed = 0.0f;
|
float shmed = 0.0f;
|
||||||
|
|
||||||
for (int i1 = max(0, i - 2); i1 <= min(i + 2, height - 1); i1++ )
|
for (int i1 = max(0, i - 2); i1 <= min(i + 2, height - 1); i1++) {
|
||||||
for (int j1 = j - 2; j1 < width; j1++) {
|
for (int j1 = j - 2; j1 < width; j1++) {
|
||||||
shmed += fabs(src->L[i1][j1] - tmL[i1][j1]);
|
shmed += fabs(src->L[i1][j1] - tmL[i1][j1]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
badpix[i * width + j] = (shfabs > ((shmed - shfabs) * shthr));
|
badpix[i * width + j] = (shfabs > ((shmed - shfabs) * shthr));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1054,109 +1055,94 @@ void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, in
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
float norm = 0.0f;
|
float norm = 0.f;
|
||||||
float shsum = 0.0f;
|
float shsum = 0.f;
|
||||||
float sum = 0.0f;
|
float sum = 0.f;
|
||||||
int tot = 0;
|
float tot = 0.f;
|
||||||
|
|
||||||
for (int i1 = max(0, i - 2); i1 <= min(i + 2, height - 1); i1++ )
|
for (int i1 = max(0, i - 2); i1 <= min(i + 2, height - 1); i1++) {
|
||||||
for (int j1 = 0; j1 <= j + 2; j1++) {
|
for (int j1 = 0; j1 <= j + 2; j1++) {
|
||||||
if (i1 == i && j1 == j) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (badpix[i1 * width + j1]) {
|
if (badpix[i1 * width + j1]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
sum += src->L[i1][j1];
|
sum += src->L[i1][j1];
|
||||||
tot++;
|
tot += 1.f;
|
||||||
float dirsh = 1.f / (SQR(src->L[i1][j1] - src->L[i][j]) + eps);
|
float dirsh = 1.f / (SQR(src->L[i1][j1] - src->L[i][j]) + eps);
|
||||||
shsum += dirsh * src->L[i1][j1];
|
shsum += dirsh * src->L[i1][j1];
|
||||||
norm += dirsh;
|
norm += dirsh;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (norm > 0.f) {
|
if (norm > 0.f) {
|
||||||
src->L[i][j] = shsum / norm;
|
src->L[i][j] = shsum / norm;
|
||||||
} else {
|
} else if(tot > 0.f) {
|
||||||
if(tot > 0) {
|
|
||||||
src->L[i][j] = sum / tot;
|
src->L[i][j] = sum / tot;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for (; j < width - 2; j++) {
|
for (; j < width - 2; j++) {
|
||||||
if (!badpix[i * width + j]) {
|
if (!badpix[i * width + j]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
float norm = 0.0f;
|
float norm = 0.f;
|
||||||
float shsum = 0.0f;
|
float shsum = 0.f;
|
||||||
float sum = 0.0f;
|
float sum = 0.f;
|
||||||
int tot = 0;
|
float tot = 0.f;
|
||||||
|
|
||||||
for (int i1 = max(0, i - 2); i1 <= min(i + 2, height - 1); i1++ )
|
for (int i1 = max(0, i - 2); i1 <= min(i + 2, height - 1); i1++) {
|
||||||
for (int j1 = j - 2; j1 <= j + 2; j1++) {
|
for (int j1 = j - 2; j1 <= j + 2; j1++) {
|
||||||
if (i1 == i && j1 == j) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (badpix[i1 * width + j1]) {
|
if (badpix[i1 * width + j1]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
sum += src->L[i1][j1];
|
sum += src->L[i1][j1];
|
||||||
tot++;
|
tot += 1.f;
|
||||||
float dirsh = 1.f / (SQR(src->L[i1][j1] - src->L[i][j]) + eps);
|
float dirsh = 1.f / (SQR(src->L[i1][j1] - src->L[i][j]) + eps);
|
||||||
shsum += dirsh * src->L[i1][j1];
|
shsum += dirsh * src->L[i1][j1];
|
||||||
norm += dirsh;
|
norm += dirsh;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (norm > 0.f) {
|
if (norm > 0.f) {
|
||||||
src->L[i][j] = shsum / norm;
|
src->L[i][j] = shsum / norm;
|
||||||
} else {
|
} else if(tot > 0.f) {
|
||||||
if(tot > 0) {
|
|
||||||
src->L[i][j] = sum / tot;
|
src->L[i][j] = sum / tot;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for (; j < width; j++) {
|
for (; j < width; j++) {
|
||||||
if (!badpix[i * width + j]) {
|
if (!badpix[i * width + j]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
float norm = 0.0f;
|
float norm = 0.f;
|
||||||
float shsum = 0.0f;
|
float shsum = 0.f;
|
||||||
float sum = 0.0f;
|
float sum = 0.f;
|
||||||
int tot = 0;
|
float tot = 0.f;
|
||||||
|
|
||||||
for (int i1 = max(0, i - 2); i1 <= min(i + 2, height - 1); i1++ )
|
for (int i1 = max(0, i - 2); i1 <= min(i + 2, height - 1); i1++) {
|
||||||
for (int j1 = j - 2; j1 < width; j1++) {
|
for (int j1 = j - 2; j1 < width; j1++) {
|
||||||
if (i1 == i && j1 == j) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (badpix[i1 * width + j1]) {
|
if (badpix[i1 * width + j1]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
sum += src->L[i1][j1];
|
sum += src->L[i1][j1];
|
||||||
tot++;
|
tot += 1.f;
|
||||||
float dirsh = 1.f / (SQR(src->L[i1][j1] - src->L[i][j]) + eps);
|
float dirsh = 1.f / (SQR(src->L[i1][j1] - src->L[i][j]) + eps);
|
||||||
shsum += dirsh * src->L[i1][j1];
|
shsum += dirsh * src->L[i1][j1];
|
||||||
norm += dirsh;
|
norm += dirsh;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (norm > 0.f) {
|
if (norm > 0.f) {
|
||||||
src->L[i][j] = shsum / norm;
|
src->L[i][j] = shsum / norm;
|
||||||
} else {
|
} else if(tot > 0.f) {
|
||||||
if(tot > 0) {
|
|
||||||
src->L[i][j] = sum / tot;
|
src->L[i][j] = sum / tot;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// end luma badpixels
|
// end luma badpixels
|
||||||
|
|
||||||
@@ -1188,16 +1174,16 @@ void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, in
|
|||||||
}
|
}
|
||||||
|
|
||||||
chrommed /= (height * width);
|
chrommed /= (height * width);
|
||||||
float threshfactor = (thresh * chrommed) / 33.f;
|
if(chrommed > 0.f) {
|
||||||
|
|
||||||
// now chrommed is calculated, so we postprocess badpix to reduce the number of divisions in future
|
// now as chrommed is calculated, we postprocess badpix to reduce the number of divisions in future
|
||||||
|
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
#pragma omp parallel
|
#pragma omp parallel
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#ifdef __SSE2__
|
#ifdef __SSE2__
|
||||||
vfloat sumv = F2V(chrommed + eps2);
|
vfloat chrommedv = F2V(chrommed);
|
||||||
vfloat onev = F2V(1.f);
|
vfloat onev = F2V(1.f);
|
||||||
#endif
|
#endif
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
@@ -1208,27 +1194,22 @@ void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, in
|
|||||||
int j = 0;
|
int j = 0;
|
||||||
#ifdef __SSE2__
|
#ifdef __SSE2__
|
||||||
for(; j < width - 3; j += 4) {
|
for(; j < width - 3; j += 4) {
|
||||||
STVFU(badpix[i * width + j], onev / (LVFU(badpix[i * width + j]) + sumv));
|
STVFU(badpix[i * width + j], onev / (LVFU(badpix[i * width + j]) + chrommedv));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
for(; j < width; j++) {
|
for(; j < width; j++) {
|
||||||
badpix[i * width + j] = 1.f / (badpix[i * width + j] + chrommed + eps2);
|
badpix[i * width + j] = 1.f / (badpix[i * width + j] + chrommed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// because we changed the values of badpix we also have to recalculate threshfactor
|
const float threshfactor = 1.f / ((thresh * chrommed) / 33.f + chrommed);
|
||||||
threshfactor = 1.f / (threshfactor + chrommed + eps2);
|
|
||||||
|
|
||||||
chrom *= 327.68f;
|
chrom *= 327.68f;
|
||||||
chrom *= chrom;
|
chrom *= chrom;
|
||||||
|
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
#pragma omp parallel
|
#pragma omp parallel for schedule(dynamic,16)
|
||||||
#endif
|
|
||||||
{
|
|
||||||
#ifdef _OPENMP
|
|
||||||
#pragma omp for schedule(dynamic,16)
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for(int i = 0; i < height; i++ ) {
|
for(int i = 0; i < height; i++ ) {
|
||||||
@@ -1240,14 +1221,14 @@ void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, in
|
|||||||
float btot = 0.f;
|
float btot = 0.f;
|
||||||
float norm = 0.f;
|
float norm = 0.f;
|
||||||
|
|
||||||
for (int i1 = max(0, i - halfwin + 1); i1 < min(height, i + halfwin); i1++)
|
for (int i1 = max(0, i - halfwin + 1); i1 < min(height, i + halfwin); i1++) {
|
||||||
for (int j1 = 0; j1 < j + halfwin; j1++) {
|
for (int j1 = 0; j1 < j + halfwin; j1++) {
|
||||||
float wt = badpix[i1 * width + j1];
|
float wt = badpix[i1 * width + j1];
|
||||||
atot += wt * src->a[i1][j1];
|
atot += wt * src->a[i1][j1];
|
||||||
btot += wt * src->b[i1][j1];
|
btot += wt * src->b[i1][j1];
|
||||||
norm += wt;
|
norm += wt;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if(SQR(atot) + SQR(btot) < chrom * SQR(norm)) {
|
if(SQR(atot) + SQR(btot) < chrom * SQR(norm)) {
|
||||||
src->a[i][j] = atot / norm;
|
src->a[i][j] = atot / norm;
|
||||||
src->b[i][j] = btot / norm;
|
src->b[i][j] = btot / norm;
|
||||||
@@ -1266,13 +1247,14 @@ void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, in
|
|||||||
vfloat btotv = ZEROV;
|
vfloat btotv = ZEROV;
|
||||||
vfloat normv = ZEROV;
|
vfloat normv = ZEROV;
|
||||||
|
|
||||||
for (int i1 = max(0, i - halfwin + 1); i1 < min(height, i + halfwin); i1++)
|
for (int i1 = max(0, i - halfwin + 1); i1 < min(height, i + halfwin); i1++) {
|
||||||
for (int j1 = j - halfwin + 1; j1 < j + halfwin; j1++) {
|
for (int j1 = j - halfwin + 1; j1 < j + halfwin; j1++) {
|
||||||
vfloat wtv = LVFU(badpix[i1 * width + j1]);
|
vfloat wtv = LVFU(badpix[i1 * width + j1]);
|
||||||
atotv += wtv * LVFU(src->a[i1][j1]);
|
atotv += wtv * LVFU(src->a[i1][j1]);
|
||||||
btotv += wtv * LVFU(src->b[i1][j1]);
|
btotv += wtv * LVFU(src->b[i1][j1]);
|
||||||
normv += wtv;
|
normv += wtv;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
selMask = vandm(selMask, vmaskf_lt(SQRV(atotv) + SQR(btotv), chromv * SQRV(normv)));
|
selMask = vandm(selMask, vmaskf_lt(SQRV(atotv) + SQR(btotv), chromv * SQRV(normv)));
|
||||||
if(_mm_movemask_ps((vfloat)selMask)) {
|
if(_mm_movemask_ps((vfloat)selMask)) {
|
||||||
vfloat aOrig = LVFU(src->a[i][j]);
|
vfloat aOrig = LVFU(src->a[i][j]);
|
||||||
@@ -1290,14 +1272,14 @@ void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, in
|
|||||||
float btot = 0.f;
|
float btot = 0.f;
|
||||||
float norm = 0.f;
|
float norm = 0.f;
|
||||||
|
|
||||||
for (int i1 = max(0, i - halfwin + 1); i1 < min(height, i + halfwin); i1++)
|
for (int i1 = max(0, i - halfwin + 1); i1 < min(height, i + halfwin); i1++) {
|
||||||
for (int j1 = j - halfwin + 1; j1 < j + halfwin; j1++) {
|
for (int j1 = j - halfwin + 1; j1 < j + halfwin; j1++) {
|
||||||
float wt = badpix[i1 * width + j1];
|
float wt = badpix[i1 * width + j1];
|
||||||
atot += wt * src->a[i1][j1];
|
atot += wt * src->a[i1][j1];
|
||||||
btot += wt * src->b[i1][j1];
|
btot += wt * src->b[i1][j1];
|
||||||
norm += wt;
|
norm += wt;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if(SQR(atot) + SQR(btot) < chrom * SQR(norm)) {
|
if(SQR(atot) + SQR(btot) < chrom * SQR(norm)) {
|
||||||
src->a[i][j] = atot / norm;
|
src->a[i][j] = atot / norm;
|
||||||
src->b[i][j] = btot / norm;
|
src->b[i][j] = btot / norm;
|
||||||
@@ -1312,14 +1294,14 @@ void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, in
|
|||||||
float btot = 0.f;
|
float btot = 0.f;
|
||||||
float norm = 0.f;
|
float norm = 0.f;
|
||||||
|
|
||||||
for (int i1 = max(0, i - halfwin + 1); i1 < min(height, i + halfwin); i1++)
|
for (int i1 = max(0, i - halfwin + 1); i1 < min(height, i + halfwin); i1++) {
|
||||||
for (int j1 = j - halfwin + 1; j1 < width; j1++) {
|
for (int j1 = j - halfwin + 1; j1 < width; j1++) {
|
||||||
float wt = badpix[i1 * width + j1];
|
float wt = badpix[i1 * width + j1];
|
||||||
atot += wt * src->a[i1][j1];
|
atot += wt * src->a[i1][j1];
|
||||||
btot += wt * src->b[i1][j1];
|
btot += wt * src->b[i1][j1];
|
||||||
norm += wt;
|
norm += wt;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if(SQR(atot) + SQR(btot) < chrom * SQR(norm)) {
|
if(SQR(atot) + SQR(btot) < chrom * SQR(norm)) {
|
||||||
src->a[i][j] = atot / norm;
|
src->a[i][j] = atot / norm;
|
||||||
src->b[i][j] = btot / norm;
|
src->b[i][j] = btot / norm;
|
||||||
@@ -1328,7 +1310,6 @@ void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, in
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete [] badpix;
|
delete [] badpix;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user