rtengine/PF_correct_RT.cc : further cleanup
This commit is contained in:
@@ -46,16 +46,16 @@ void ImProcFunctions::PF_correct_RT(LabImage * src, double radius, int thresh)
|
|||||||
BENCHFUN
|
BENCHFUN
|
||||||
const int halfwin = ceil(2 * radius) + 1;
|
const int halfwin = ceil(2 * radius) + 1;
|
||||||
|
|
||||||
FlatCurve* chCurve = nullptr;
|
std::unique_ptr<FlatCurve> chCurve;
|
||||||
|
|
||||||
if (params->defringe.huecurve.size() && FlatCurveType(params->defringe.huecurve.at(0)) > FCT_Linear) {
|
if (params->defringe.huecurve.size() && FlatCurveType(params->defringe.huecurve.at(0)) > FCT_Linear) {
|
||||||
chCurve = new FlatCurve(params->defringe.huecurve);
|
chCurve.reset(new FlatCurve(params->defringe.huecurve));
|
||||||
}
|
}
|
||||||
|
|
||||||
// local variables
|
// local variables
|
||||||
const int width = src->W, height = src->H;
|
const int width = src->W, height = src->H;
|
||||||
//temporary array to store chromaticity
|
//temporary array to store chromaticity
|
||||||
float *fringe = new float[width * height];
|
|
||||||
|
std::unique_ptr<float[]> fringe(new float[width * height]);
|
||||||
|
|
||||||
const JaggedArray<float> tmpa(width, height);
|
const JaggedArray<float> tmpa(width, height);
|
||||||
const JaggedArray<float> tmpb(width, height);
|
const JaggedArray<float> tmpb(width, height);
|
||||||
@@ -219,11 +219,6 @@ void ImProcFunctions::PF_correct_RT(LabImage * src, double radius, int thresh)
|
|||||||
}
|
}
|
||||||
}//end of ab channel averaging
|
}//end of ab channel averaging
|
||||||
}
|
}
|
||||||
if(chCurve) {
|
|
||||||
delete chCurve;
|
|
||||||
}
|
|
||||||
|
|
||||||
delete [] fringe;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImProcFunctions::PF_correct_RTcam(CieImage * src, double radius, int thresh)
|
void ImProcFunctions::PF_correct_RTcam(CieImage * src, double radius, int thresh)
|
||||||
@@ -231,17 +226,17 @@ void ImProcFunctions::PF_correct_RTcam(CieImage * src, double radius, int thresh
|
|||||||
BENCHFUN
|
BENCHFUN
|
||||||
const int halfwin = ceil(2 * radius) + 1;
|
const int halfwin = ceil(2 * radius) + 1;
|
||||||
|
|
||||||
FlatCurve* chCurve = nullptr;
|
std::unique_ptr<FlatCurve> chCurve;
|
||||||
|
|
||||||
if (params->defringe.huecurve.size() && FlatCurveType(params->defringe.huecurve.at(0)) > FCT_Linear) {
|
if (params->defringe.huecurve.size() && FlatCurveType(params->defringe.huecurve.at(0)) > FCT_Linear) {
|
||||||
chCurve = new FlatCurve(params->defringe.huecurve);
|
chCurve.reset(new FlatCurve(params->defringe.huecurve));
|
||||||
}
|
}
|
||||||
|
|
||||||
// local variables
|
// local variables
|
||||||
const int width = src->W, height = src->H;
|
const int width = src->W, height = src->H;
|
||||||
|
|
||||||
//temporary array to store chromaticity
|
//temporary array to store chromaticity
|
||||||
float *fringe = new float[width * height];
|
std::unique_ptr<float[]> fringe(new float[width * height]);
|
||||||
|
|
||||||
float **sraa = src->h_p; // we use the src->h_p buffer to avoid memory allocation/deallocation and reduce memory pressure
|
float **sraa = src->h_p; // we use the src->h_p buffer to avoid memory allocation/deallocation and reduce memory pressure
|
||||||
float **srbb = src->C_p; // we use the src->C_p buffer to avoid memory allocation/deallocation and reduce memory pressure
|
float **srbb = src->C_p; // we use the src->C_p buffer to avoid memory allocation/deallocation and reduce memory pressure
|
||||||
@@ -383,12 +378,11 @@ void ImProcFunctions::PF_correct_RTcam(CieImage * src, double radius, int thresh
|
|||||||
float atot = 0.f;
|
float atot = 0.f;
|
||||||
float btot = 0.f;
|
float btot = 0.f;
|
||||||
float norm = 0.f;
|
float norm = 0.f;
|
||||||
float wt;
|
|
||||||
|
|
||||||
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++) {
|
||||||
//neighbourhood average of pixels weighted by chrominance
|
//neighbourhood average of pixels weighted by chrominance
|
||||||
wt = fringe[i1 * width + j1];
|
float wt = fringe[i1 * width + j1];
|
||||||
atot += wt * sraa[i1][j1];
|
atot += wt * sraa[i1][j1];
|
||||||
btot += wt * srbb[i1][j1];
|
btot += wt * srbb[i1][j1];
|
||||||
norm += wt;
|
norm += wt;
|
||||||
@@ -409,12 +403,11 @@ void ImProcFunctions::PF_correct_RTcam(CieImage * src, double radius, int thresh
|
|||||||
float atot = 0.f;
|
float atot = 0.f;
|
||||||
float btot = 0.f;
|
float btot = 0.f;
|
||||||
float norm = 0.f;
|
float norm = 0.f;
|
||||||
float wt;
|
|
||||||
|
|
||||||
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++) {
|
||||||
//neighbourhood average of pixels weighted by chrominance
|
//neighbourhood average of pixels weighted by chrominance
|
||||||
wt = fringe[i1 * width + j1];
|
float wt = fringe[i1 * width + j1];
|
||||||
atot += wt * sraa[i1][j1];
|
atot += wt * sraa[i1][j1];
|
||||||
btot += wt * srbb[i1][j1];
|
btot += wt * srbb[i1][j1];
|
||||||
norm += wt;
|
norm += wt;
|
||||||
@@ -435,12 +428,11 @@ void ImProcFunctions::PF_correct_RTcam(CieImage * src, double radius, int thresh
|
|||||||
float atot = 0.f;
|
float atot = 0.f;
|
||||||
float btot = 0.f;
|
float btot = 0.f;
|
||||||
float norm = 0.f;
|
float norm = 0.f;
|
||||||
float wt;
|
|
||||||
|
|
||||||
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++) {
|
||||||
//neighbourhood average of pixels weighted by chrominance
|
//neighbourhood average of pixels weighted by chrominance
|
||||||
wt = fringe[i1 * width + j1];
|
float wt = fringe[i1 * width + j1];
|
||||||
atot += wt * sraa[i1][j1];
|
atot += wt * sraa[i1][j1];
|
||||||
btot += wt * srbb[i1][j1];
|
btot += wt * srbb[i1][j1];
|
||||||
norm += wt;
|
norm += wt;
|
||||||
@@ -477,12 +469,6 @@ void ImProcFunctions::PF_correct_RTcam(CieImage * src, double radius, int thresh
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(chCurve) {
|
|
||||||
delete chCurve;
|
|
||||||
}
|
|
||||||
|
|
||||||
delete [] fringe;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImProcFunctions::Badpixelscam(CieImage * src, double radius, int thresh, int mode, float chrom, bool hotbad)
|
void ImProcFunctions::Badpixelscam(CieImage * src, double radius, int thresh, int mode, float chrom, bool hotbad)
|
||||||
@@ -499,7 +485,7 @@ void ImProcFunctions::Badpixelscam(CieImage * src, double radius, int thresh, in
|
|||||||
|
|
||||||
const JaggedArray<float> tmL(width, height);
|
const JaggedArray<float> tmL(width, height);
|
||||||
|
|
||||||
float* badpix = new float[width * height];
|
std::unique_ptr<float[]> badpix(new float[width * height]);
|
||||||
|
|
||||||
if(radius >= 0.5) { // for gauss sigma less than 0.25 gaussianblur() just calls memcpy => nothing to do here
|
if(radius >= 0.5) { // for gauss sigma less than 0.25 gaussianblur() just calls memcpy => nothing to do here
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
@@ -872,11 +858,10 @@ void ImProcFunctions::Badpixelscam(CieImage * src, double radius, int thresh, in
|
|||||||
float atot = 0.f;
|
float atot = 0.f;
|
||||||
float btot = 0.f;
|
float btot = 0.f;
|
||||||
float norm = 0.f;
|
float norm = 0.f;
|
||||||
float wt;
|
|
||||||
|
|
||||||
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++) {
|
||||||
wt = badpix[i1 * width + j1];
|
float wt = badpix[i1 * width + j1];
|
||||||
atot += wt * sraa[i1][j1];
|
atot += wt * sraa[i1][j1];
|
||||||
btot += wt * srbb[i1][j1];
|
btot += wt * srbb[i1][j1];
|
||||||
norm += wt;
|
norm += wt;
|
||||||
@@ -936,11 +921,10 @@ void ImProcFunctions::Badpixelscam(CieImage * src, double radius, int thresh, in
|
|||||||
float atot = 0.f;
|
float atot = 0.f;
|
||||||
float btot = 0.f;
|
float btot = 0.f;
|
||||||
float norm = 0.f;
|
float norm = 0.f;
|
||||||
float wt;
|
|
||||||
|
|
||||||
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++) {
|
||||||
wt = badpix[i1 * width + j1];
|
float wt = badpix[i1 * width + j1];
|
||||||
atot += wt * sraa[i1][j1];
|
atot += wt * sraa[i1][j1];
|
||||||
btot += wt * srbb[i1][j1];
|
btot += wt * srbb[i1][j1];
|
||||||
norm += wt;
|
norm += wt;
|
||||||
@@ -965,11 +949,10 @@ void ImProcFunctions::Badpixelscam(CieImage * src, double radius, int thresh, in
|
|||||||
float atot = 0.f;
|
float atot = 0.f;
|
||||||
float btot = 0.f;
|
float btot = 0.f;
|
||||||
float norm = 0.f;
|
float norm = 0.f;
|
||||||
float wt;
|
|
||||||
|
|
||||||
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++) {
|
||||||
wt = badpix[i1 * width + j1];
|
float wt = badpix[i1 * width + j1];
|
||||||
atot += wt * sraa[i1][j1];
|
atot += wt * sraa[i1][j1];
|
||||||
btot += wt * srbb[i1][j1];
|
btot += wt * srbb[i1][j1];
|
||||||
norm += wt;
|
norm += wt;
|
||||||
@@ -990,8 +973,6 @@ void ImProcFunctions::Badpixelscam(CieImage * src, double radius, int thresh, in
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete [] badpix;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, float chrom)
|
void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, float chrom)
|
||||||
@@ -1005,7 +986,7 @@ void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, fl
|
|||||||
|
|
||||||
const JaggedArray<float> tmL(width, height);
|
const JaggedArray<float> tmL(width, height);
|
||||||
|
|
||||||
float* badpix = new float[width * height];
|
std::unique_ptr<float[]> badpix(new float[width * height]);
|
||||||
|
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
#pragma omp parallel
|
#pragma omp parallel
|
||||||
@@ -1092,10 +1073,7 @@ void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, fl
|
|||||||
for (int i = 0; i < height; i++) {
|
for (int i = 0; i < height; i++) {
|
||||||
int j = 0;
|
int j = 0;
|
||||||
for (; j < 2; j++) {
|
for (; j < 2; j++) {
|
||||||
if (!badpix[i * width + j]) {
|
if (badpix[i * width + j]) {
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
float norm = 0.f;
|
float norm = 0.f;
|
||||||
float shsum = 0.f;
|
float shsum = 0.f;
|
||||||
float sum = 0.f;
|
float sum = 0.f;
|
||||||
@@ -1103,11 +1081,7 @@ void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, fl
|
|||||||
|
|
||||||
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 (!badpix[i1 * width + j1]) {
|
||||||
if (badpix[i1 * width + j1]) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
sum += src->L[i1][j1];
|
sum += src->L[i1][j1];
|
||||||
tot += 1.f;
|
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);
|
||||||
@@ -1115,18 +1089,17 @@ void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, fl
|
|||||||
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 if(tot > 0.f) {
|
} else if(tot > 0.f) {
|
||||||
src->L[i][j] = sum / tot;
|
src->L[i][j] = sum / tot;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; j < width - 2; j++) {
|
|
||||||
if (!badpix[i * width + j]) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (; j < width - 2; j++) {
|
||||||
|
if (badpix[i * width + j]) {
|
||||||
float norm = 0.f;
|
float norm = 0.f;
|
||||||
float shsum = 0.f;
|
float shsum = 0.f;
|
||||||
float sum = 0.f;
|
float sum = 0.f;
|
||||||
@@ -1134,11 +1107,7 @@ void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, fl
|
|||||||
|
|
||||||
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 (!badpix[i1 * width + j1]) {
|
||||||
if (badpix[i1 * width + j1]) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
sum += src->L[i1][j1];
|
sum += src->L[i1][j1];
|
||||||
tot += 1.f;
|
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);
|
||||||
@@ -1146,18 +1115,17 @@ void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, fl
|
|||||||
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 if(tot > 0.f) {
|
} else if(tot > 0.f) {
|
||||||
src->L[i][j] = sum / tot;
|
src->L[i][j] = sum / tot;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; j < width; j++) {
|
|
||||||
if (!badpix[i * width + j]) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (; j < width; j++) {
|
||||||
|
if (badpix[i * width + j]) {
|
||||||
float norm = 0.f;
|
float norm = 0.f;
|
||||||
float shsum = 0.f;
|
float shsum = 0.f;
|
||||||
float sum = 0.f;
|
float sum = 0.f;
|
||||||
@@ -1165,11 +1133,7 @@ void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, fl
|
|||||||
|
|
||||||
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 (!badpix[i1 * width + j1]) {
|
||||||
if (badpix[i1 * width + j1]) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
sum += src->L[i1][j1];
|
sum += src->L[i1][j1];
|
||||||
tot += 1.f;
|
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);
|
||||||
@@ -1177,6 +1141,7 @@ void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, fl
|
|||||||
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 if(tot > 0.f) {
|
} else if(tot > 0.f) {
|
||||||
@@ -1184,6 +1149,7 @@ void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, fl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// end luma badpixels
|
// end luma badpixels
|
||||||
|
|
||||||
@@ -1351,8 +1317,6 @@ void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, fl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete [] badpix;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user