Speedup for BadpixelsLab()
This commit is contained in:
parent
cfbcd6cd5b
commit
cde2796569
@ -38,6 +38,7 @@
|
|||||||
namespace rtengine
|
namespace rtengine
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// Defringe in Lab mode
|
||||||
void ImProcFunctions::PF_correct_RT(LabImage * lab, double radius, int thresh)
|
void ImProcFunctions::PF_correct_RT(LabImage * lab, double radius, int thresh)
|
||||||
{
|
{
|
||||||
BENCHFUN
|
BENCHFUN
|
||||||
@ -46,7 +47,6 @@ void ImProcFunctions::PF_correct_RT(LabImage * lab, double radius, int thresh)
|
|||||||
chCurve.reset(new FlatCurve(params->defringe.huecurve));
|
chCurve.reset(new FlatCurve(params->defringe.huecurve));
|
||||||
}
|
}
|
||||||
|
|
||||||
// local variables
|
|
||||||
const int width = lab->W, height = lab->H;
|
const int width = lab->W, height = lab->H;
|
||||||
|
|
||||||
// temporary array to store chromaticity
|
// temporary array to store chromaticity
|
||||||
@ -128,7 +128,7 @@ void ImProcFunctions::PF_correct_RT(LabImage * lab, double radius, int thresh)
|
|||||||
const int halfwin = std::ceil(2 * radius) + 1;
|
const int halfwin = std::ceil(2 * radius) + 1;
|
||||||
|
|
||||||
// Issue 1674:
|
// Issue 1674:
|
||||||
// often, CA is not evenly distributed, e.g. a lot in contrasty regions and none in the sky.
|
// often, colour fringe is not 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
|
// 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
|
// 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
|
// choice for the chunk_size than 16
|
||||||
@ -202,6 +202,7 @@ void ImProcFunctions::PF_correct_RT(LabImage * lab, double radius, int thresh)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Defringe in CIECAM02 mode
|
||||||
void ImProcFunctions::PF_correct_RTcam(CieImage * ncie, double radius, int thresh)
|
void ImProcFunctions::PF_correct_RTcam(CieImage * ncie, double radius, int thresh)
|
||||||
{
|
{
|
||||||
BENCHFUN
|
BENCHFUN
|
||||||
@ -212,7 +213,6 @@ void ImProcFunctions::PF_correct_RTcam(CieImage * ncie, double radius, int thres
|
|||||||
chCurve.reset(new FlatCurve(params->defringe.huecurve));
|
chCurve.reset(new FlatCurve(params->defringe.huecurve));
|
||||||
}
|
}
|
||||||
|
|
||||||
// local variables
|
|
||||||
const int width = ncie->W, height = ncie->H;
|
const int width = ncie->W, height = ncie->H;
|
||||||
|
|
||||||
// temporary array to store chromaticity
|
// temporary array to store chromaticity
|
||||||
@ -322,13 +322,12 @@ void ImProcFunctions::PF_correct_RTcam(CieImage * ncie, double radius, int thres
|
|||||||
const int halfwin = std::ceil(2 * radius) + 1;
|
const int halfwin = std::ceil(2 * radius) + 1;
|
||||||
|
|
||||||
// Issue 1674:
|
// Issue 1674:
|
||||||
// often, CA isn't evenly distributed, e.g. a lot in contrasty regions and none in the sky.
|
// often, colour fringe is not 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
|
// 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
|
// 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
|
// choice for the chunk_size than 16
|
||||||
// Issue 1972: Split this loop in three parts to avoid most of the min and max-operations
|
// Issue 1972: Split this loop in three parts to avoid most of the min and max-operations
|
||||||
|
|
||||||
|
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
#pragma omp parallel for schedule(dynamic,16)
|
#pragma omp parallel for schedule(dynamic,16)
|
||||||
#endif
|
#endif
|
||||||
@ -414,6 +413,7 @@ void ImProcFunctions::PF_correct_RTcam(CieImage * ncie, double radius, int thres
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CIECAM02 hot/bad pixel filter
|
||||||
void ImProcFunctions::Badpixelscam(CieImage * ncie, double radius, int thresh, int mode, float chrom, bool hotbad)
|
void ImProcFunctions::Badpixelscam(CieImage * ncie, double radius, int thresh, int mode, float chrom, bool hotbad)
|
||||||
{
|
{
|
||||||
BENCHFUN
|
BENCHFUN
|
||||||
@ -449,7 +449,7 @@ void ImProcFunctions::Badpixelscam(CieImage * ncie, double radius, int thresh, i
|
|||||||
#ifdef __SSE2__
|
#ifdef __SSE2__
|
||||||
const vfloat shthrv = F2V(shthr);
|
const vfloat shthrv = F2V(shthr);
|
||||||
const vfloat onev = F2V(1.f);
|
const vfloat onev = F2V(1.f);
|
||||||
#endif // __SSE2__
|
#endif
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
#pragma omp for
|
#pragma omp for
|
||||||
#endif
|
#endif
|
||||||
@ -587,9 +587,7 @@ void ImProcFunctions::Badpixelscam(CieImage * ncie, double radius, int thresh, i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} // end luma badpixels
|
||||||
|
|
||||||
// end luma badpixels
|
|
||||||
|
|
||||||
if (hotbad) {
|
if (hotbad) {
|
||||||
JaggedArray<float> sraa(width, height);
|
JaggedArray<float> sraa(width, height);
|
||||||
@ -602,7 +600,7 @@ void ImProcFunctions::Badpixelscam(CieImage * ncie, double radius, int thresh, i
|
|||||||
|
|
||||||
#ifdef __SSE2__
|
#ifdef __SSE2__
|
||||||
const vfloat piDiv180v = F2V(RT_PI_F_180);
|
const vfloat piDiv180v = F2V(RT_PI_F_180);
|
||||||
#endif // __SSE2__
|
#endif
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
#pragma omp for
|
#pragma omp for
|
||||||
#endif
|
#endif
|
||||||
@ -843,6 +841,7 @@ void ImProcFunctions::Badpixelscam(CieImage * ncie, double radius, int thresh, i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CbDL reduce artifacts
|
||||||
void ImProcFunctions::BadpixelsLab(LabImage * lab, double radius, int thresh, float chrom)
|
void ImProcFunctions::BadpixelsLab(LabImage * lab, double radius, int thresh, float chrom)
|
||||||
{
|
{
|
||||||
BENCHFUN
|
BENCHFUN
|
||||||
@ -862,16 +861,9 @@ void ImProcFunctions::BadpixelsLab(LabImage * lab, double radius, int thresh, fl
|
|||||||
const std::unique_ptr<float[]> badpix(new float[width * height]);
|
const 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
|
|
||||||
#pragma omp parallel
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
// blur L channel
|
|
||||||
gaussianBlur(lab->L, tmL, width, height, radius / 2.0);//low value to avoid artifacts
|
|
||||||
}
|
|
||||||
|
|
||||||
//luma badpixels
|
//luma badpixels
|
||||||
|
// for bad pixels in L channel we need 0 / != 0 information. Use 1 byte per pixel instead of 4 to reduce memory pressure
|
||||||
|
uint8_t *badpixb = reinterpret_cast<uint8_t*>(badpix.get());
|
||||||
constexpr float sh_thr = 4.5f; // low value for luma sh_p to avoid artifacts
|
constexpr float sh_thr = 4.5f; // low value for luma sh_p to avoid artifacts
|
||||||
constexpr float shthr = sh_thr / 24.0f; // divide by 24 because we are using a 5x5 grid and centre point is excluded from summation
|
constexpr float shthr = sh_thr / 24.0f; // divide by 24 because we are using a 5x5 grid and centre point is excluded from summation
|
||||||
|
|
||||||
@ -879,9 +871,11 @@ void ImProcFunctions::BadpixelsLab(LabImage * lab, double radius, int thresh, fl
|
|||||||
#pragma omp parallel
|
#pragma omp parallel
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
// blur L channel
|
||||||
|
gaussianBlur(lab->L, tmL, width, height, radius / 2.0); // low value to avoid artifacts
|
||||||
|
|
||||||
#ifdef __SSE2__
|
#ifdef __SSE2__
|
||||||
const vfloat shthrv = F2V(shthr);
|
const vfloat shthrv = F2V(shthr);
|
||||||
const vfloat onev = F2V(1.f);
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
#pragma omp for
|
#pragma omp for
|
||||||
@ -898,7 +892,7 @@ void ImProcFunctions::BadpixelsLab(LabImage * lab, double radius, int thresh, fl
|
|||||||
shmed += std::fabs(lab->L[i1][j1] - tmL[i1][j1]);
|
shmed += std::fabs(lab->L[i1][j1] - tmL[i1][j1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
badpix[i * width + j] = shfabs > ((shmed - shfabs) * shthr);
|
badpixb[i * width + j] = shfabs > ((shmed - shfabs) * shthr);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __SSE2__
|
#ifdef __SSE2__
|
||||||
@ -912,7 +906,11 @@ void ImProcFunctions::BadpixelsLab(LabImage * lab, double radius, int thresh, fl
|
|||||||
shmedv += vabsf(LVFU(lab->L[i1][j1]) - LVFU(tmL[i1][j1]));
|
shmedv += vabsf(LVFU(lab->L[i1][j1]) - LVFU(tmL[i1][j1]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
STVFU(badpix[i * width + j], vselfzero(vmaskf_gt(shfabsv, (shmedv - shfabsv) * shthrv), onev));
|
uint8_t mask = _mm_movemask_ps((vfloat)vmaskf_gt(shfabsv, (shmedv - shfabsv) * shthrv));
|
||||||
|
badpixb[i * width + j] = mask & 1;
|
||||||
|
badpixb[i * width + j + 1] = mask & 2;
|
||||||
|
badpixb[i * width + j + 2] = mask & 4;
|
||||||
|
badpixb[i * width + j + 3] = mask & 8;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
for (; j < width - 2; j++) {
|
for (; j < width - 2; j++) {
|
||||||
@ -924,7 +922,7 @@ void ImProcFunctions::BadpixelsLab(LabImage * lab, double radius, int thresh, fl
|
|||||||
shmed += std::fabs(lab->L[i1][j1] - tmL[i1][j1]);
|
shmed += std::fabs(lab->L[i1][j1] - tmL[i1][j1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
badpix[i * width + j] = shfabs > ((shmed - shfabs) * shthr);
|
badpixb[i * width + j] = shfabs > ((shmed - shfabs) * shthr);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; j < width; j++) {
|
for (; j < width; j++) {
|
||||||
@ -936,7 +934,7 @@ void ImProcFunctions::BadpixelsLab(LabImage * lab, double radius, int thresh, fl
|
|||||||
shmed += std::fabs(lab->L[i1][j1] - tmL[i1][j1]);
|
shmed += std::fabs(lab->L[i1][j1] - tmL[i1][j1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
badpix[i * width + j] = shfabs > ((shmed - shfabs) * shthr);
|
badpixb[i * width + j] = shfabs > ((shmed - shfabs) * shthr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -948,12 +946,12 @@ void ImProcFunctions::BadpixelsLab(LabImage * lab, 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 (badpixb[i * width + j]) {
|
||||||
float norm = 0.f, shsum = 0.f, sum = 0.f, tot = 0.f;
|
float norm = 0.f, shsum = 0.f, sum = 0.f, tot = 0.f;
|
||||||
|
|
||||||
for (int i1 = std::max(0, i - 2); i1 <= std::min(i + 2, height - 1); i1++) {
|
for (int i1 = std::max(0, i - 2); i1 <= std::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 (!badpixb[i1 * width + j1]) {
|
||||||
sum += lab->L[i1][j1];
|
sum += lab->L[i1][j1];
|
||||||
tot += 1.f;
|
tot += 1.f;
|
||||||
const float dirsh = 1.f / (SQR(lab->L[i1][j1] - lab->L[i][j]) + eps);
|
const float dirsh = 1.f / (SQR(lab->L[i1][j1] - lab->L[i][j]) + eps);
|
||||||
@ -971,12 +969,12 @@ void ImProcFunctions::BadpixelsLab(LabImage * lab, double radius, int thresh, fl
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (; j < width - 2; j++) {
|
for (; j < width - 2; j++) {
|
||||||
if (badpix[i * width + j]) {
|
if (badpixb[i * width + j]) {
|
||||||
float norm = 0.f, shsum = 0.f, sum = 0.f, tot = 0.f;
|
float norm = 0.f, shsum = 0.f, sum = 0.f, tot = 0.f;
|
||||||
|
|
||||||
for (int i1 = std::max(0, i - 2); i1 <= std::min(i + 2, height - 1); i1++) {
|
for (int i1 = std::max(0, i - 2); i1 <= std::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 (!badpixb[i1 * width + j1]) {
|
||||||
sum += lab->L[i1][j1];
|
sum += lab->L[i1][j1];
|
||||||
tot += 1.f;
|
tot += 1.f;
|
||||||
const float dirsh = 1.f / (SQR(lab->L[i1][j1] - lab->L[i][j]) + eps);
|
const float dirsh = 1.f / (SQR(lab->L[i1][j1] - lab->L[i][j]) + eps);
|
||||||
@ -994,12 +992,12 @@ void ImProcFunctions::BadpixelsLab(LabImage * lab, double radius, int thresh, fl
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (; j < width; j++) {
|
for (; j < width; j++) {
|
||||||
if (badpix[i * width + j]) {
|
if (badpixb[i * width + j]) {
|
||||||
float norm = 0.f, shsum = 0.f, sum = 0.f, tot = 0.f;
|
float norm = 0.f, shsum = 0.f, sum = 0.f, tot = 0.f;
|
||||||
|
|
||||||
for (int i1 = std::max(0, i - 2); i1 <= std::min(i + 2, height - 1); i1++) {
|
for (int i1 = std::max(0, i - 2); i1 <= std::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 (!badpixb[i1 * width + j1]) {
|
||||||
sum += lab->L[i1][j1];
|
sum += lab->L[i1][j1];
|
||||||
tot += 1.f;
|
tot += 1.f;
|
||||||
const float dirsh = 1.f / (SQR(lab->L[i1][j1] - lab->L[i][j]) + eps);
|
const float dirsh = 1.f / (SQR(lab->L[i1][j1] - lab->L[i][j]) + eps);
|
||||||
@ -1016,9 +1014,7 @@ void ImProcFunctions::BadpixelsLab(LabImage * lab, double radius, int thresh, fl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} // end luma badpixels
|
||||||
|
|
||||||
// end luma badpixels
|
|
||||||
|
|
||||||
float** const tmaa = tmL; // reuse tmL buffer
|
float** const tmaa = tmL; // reuse tmL buffer
|
||||||
JaggedArray<float> tmbb(width, height);
|
JaggedArray<float> tmbb(width, height);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user