Performance optimization of defringe (Issue1674)

This commit is contained in:
Ingo
2013-01-22 18:36:31 +01:00
parent 7918fab562
commit 4ae5b0739b

View File

@@ -63,14 +63,14 @@ void ImProcFunctions::PF_correct_RT(LabImage * src, LabImage * dst, double radiu
gaussVertical<float> (tmp1->a, tmp1->a, buffer, src->W, src->H, radius);
gaussVertical<float> (tmp1->b, tmp1->b, buffer, src->W, src->H, radius);
gaussHorizontal<float> (src->L, tmp1->L, buffer, src->W, src->H, radius);
gaussVertical<float> (tmp1->L, tmp1->L, buffer, src->W, src->H, radius);
// gaussHorizontal<float> (src->L, tmp1->L, buffer, src->W, src->H, radius);
// gaussVertical<float> (tmp1->L, tmp1->L, buffer, src->W, src->H, radius);
}
//#ifdef _OPENMP
//#pragma omp parallel for
//#endif
float chromave=0;
float chromave=0;
#ifdef _OPENMP
#pragma omp parallel for reduction(+:chromave)
#endif
for(int i = 0; i < height; i++ ) {
for(int j = 0; j < width; j++) {
float chroma = SQR(src->a[i][j]-tmp1->a[i][j])+SQR(src->b[i][j]-tmp1->b[i][j]);
@@ -79,11 +79,17 @@ void ImProcFunctions::PF_correct_RT(LabImage * src, LabImage * dst, double radiu
}
}
chromave /= (height*width);
float threshfactor = (thresh*chromave)/33.f; // Calculated once to eliminate mult inside the next loop
// printf("Chro %f \n",chromave);
#ifdef _OPENMP
#pragma omp parallel for
#endif
// Issue 1674:
// often, CA isn't evenly distributed, e.g. a lot in contrasty regions and none in the sky.
// so it's better to schedule dynamic and let every thread only process 16 rows, to avoid running big threads out of work
// Measured it and in fact gives better performance than without schedule(dynamic,16). Of course, there could be a better
// choice for the chunk_size than 16
#ifdef _OPENMP
#pragma omp parallel for schedule(dynamic,16)
#endif
for(int i = 0; i < height; i++ ) {
for(int j = 0; j < width; j++) {
tmp1->a[i][j] = src->a[i][j];
@@ -91,7 +97,7 @@ void ImProcFunctions::PF_correct_RT(LabImage * src, LabImage * dst, double radiu
//test for pixel darker than some fraction of neighborhood ave, near an edge, more saturated than average
/*if (100*tmp1->L[i][j]>50*src->L[i][j] && \*/
/*1000*abs(tmp1->L[i][j]-src->L[i][j])>thresh*(tmp1->L[i][j]+src->L[i][j]) && \*/
if (33.f*fringe[i*width+j]>thresh*chromave) {
if (fringe[i*width+j]>threshfactor) {
float atot=0.f;
float btot=0.f;
float norm=0.f;
@@ -142,7 +148,9 @@ void ImProcFunctions::PF_correct_RTcam(CieImage * src, CieImage * dst, double ra
for (int i=0; i<height; i++)
sraa[i] = new float[width];
#ifdef _OPENMP
#pragma omp parallel for
#endif
for (int i=0; i<height; i++)
for (int j=0; j<width; j++) {
sraa[i][j]=src->C_p[i][j]*cos(piid*src->h_p[i][j]);
@@ -157,7 +165,9 @@ void ImProcFunctions::PF_correct_RTcam(CieImage * src, CieImage * dst, double ra
for (int i=0; i<height; i++)
srbb[i] = new float[width];
#ifdef _OPENMP
#pragma omp parallel for
#endif
for (int i=0; i<height; i++)
for (int j=0; j<width; j++) {
srbb[i][j]=src->C_p[i][j]*sin(piid*src->h_p[i][j]);
@@ -187,10 +197,10 @@ void ImProcFunctions::PF_correct_RTcam(CieImage * src, CieImage * dst, double ra
}
//#ifdef _OPENMP
//#pragma omp parallel for
//#endif
float chromave=0;
float chromave=0;
#ifdef _OPENMP
#pragma omp parallel for reduction(+:chromave)
#endif
for(int i = 0; i < height; i++ ) {
for(int j = 0; j < width; j++) {
float chroma =SQR(sraa[i][j]-tmaa[i][j])+SQR(srbb[i][j]-tmbb[i][j]);
@@ -199,12 +209,17 @@ void ImProcFunctions::PF_correct_RTcam(CieImage * src, CieImage * dst, double ra
}
}
chromave /= (height*width);
float threshfactor = (thresh*chromave)/33.f; // Calculated once to eliminate mult inside the next loop
// printf("Chromave CAM %f \n",chromave);
// Issue 1674:
// often, CA isn't evenly distributed, e.g. a lot in contrasty regions and none in the sky.
// so it's better to schedule dynamic and let every thread only process 16 rows, to avoid running big threads out of work
// Measured it and in fact gives better performance than without schedule(dynamic,16). Of course, there could be a better
// choice for the chunk_size than 16
#ifdef _OPENMP
#pragma omp parallel for
#pragma omp parallel for schedule(dynamic,16)
#endif
for(int i = 0; i < height; i++ ) {
for(int j = 0; j < width; j++) {
tmaa[i][j] = sraa[i][j];
@@ -213,7 +228,7 @@ void ImProcFunctions::PF_correct_RTcam(CieImage * src, CieImage * dst, double ra
//test for pixel darker than some fraction of neighborhood ave, near an edge, more saturated than average
/*if (100*tmp1->L[i][j]>50*src->L[i][j] && \*/
/*1000*abs(tmp1->L[i][j]-src->L[i][j])>thresh*(tmp1->L[i][j]+src->L[i][j]) && \*/
if (33.f*fringe[i*width+j]>thresh*chromave) {
if (fringe[i*width+j]>threshfactor) {
float atot=0.f;
float btot=0.f;
float norm=0.f;