Drop using namespace
and add more const
plus whitespace fixes
This commit is contained in:
parent
d0da0c66e2
commit
2729b785c3
@ -36,15 +36,13 @@
|
|||||||
#define BENCHMARK
|
#define BENCHMARK
|
||||||
#include "StopWatch.h"
|
#include "StopWatch.h"
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace rtengine
|
namespace rtengine
|
||||||
{
|
{
|
||||||
|
|
||||||
void ImProcFunctions::PF_correct_RT(LabImage * src, double radius, int thresh)
|
void ImProcFunctions::PF_correct_RT(LabImage * src, double radius, int thresh)
|
||||||
{
|
{
|
||||||
BENCHFUN
|
BENCHFUN
|
||||||
const int halfwin = ceil(2 * radius) + 1;
|
const int halfwin = std::ceil(2 * radius) + 1;
|
||||||
|
|
||||||
std::unique_ptr<FlatCurve> chCurve;
|
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) {
|
||||||
@ -55,10 +53,10 @@ void ImProcFunctions::PF_correct_RT(LabImage * src, double radius, int thresh)
|
|||||||
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
|
||||||
std::unique_ptr<float[]> fringe(new float[width * height]);
|
const std::unique_ptr<float[]> fringe(new float[width * height]);
|
||||||
|
|
||||||
const JaggedArray<float> tmpa(width, height);
|
JaggedArray<float> tmpa(width, height);
|
||||||
const JaggedArray<float> tmpb(width, height);
|
JaggedArray<float> tmpb(width, height);
|
||||||
|
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
#pragma omp parallel
|
#pragma omp parallel
|
||||||
@ -101,10 +99,10 @@ void ImProcFunctions::PF_correct_RT(LabImage * src, double radius, int thresh)
|
|||||||
if (chCurve) {
|
if (chCurve) {
|
||||||
#ifdef __SSE2__
|
#ifdef __SSE2__
|
||||||
// use the precalculated atan values
|
// use the precalculated atan values
|
||||||
float HH = fringe[i * width + j];
|
const float HH = fringe[i * width + j];
|
||||||
#else
|
#else
|
||||||
// no precalculated values without SSE => calculate
|
// no precalculated values without SSE => calculate
|
||||||
float HH = xatan2f(src->b[i][j], src->a[i][j]);
|
const float HH = xatan2f(src->b[i][j], src->a[i][j]);
|
||||||
#endif
|
#endif
|
||||||
float chparam = chCurve->getVal((Color::huelab_to_huehsv2(HH))) - 0.5f; // get C=f(H)
|
float chparam = chCurve->getVal((Color::huelab_to_huehsv2(HH))) - 0.5f; // get C=f(H)
|
||||||
|
|
||||||
@ -115,14 +113,14 @@ void ImProcFunctions::PF_correct_RT(LabImage * src, double radius, int thresh)
|
|||||||
chromaChfactor = SQR(1.f + chparam);
|
chromaChfactor = SQR(1.f + chparam);
|
||||||
}
|
}
|
||||||
|
|
||||||
float chroma = chromaChfactor * (SQR(src->a[i][j] - tmpa[i][j]) + SQR(src->b[i][j] - tmpb[i][j])); //modulate chroma function hue
|
const 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
chromave /= (height * width);
|
chromave /= height * width;
|
||||||
|
|
||||||
if (chromave > 0.0) {
|
if (chromave > 0.0) {
|
||||||
// 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
|
||||||
@ -154,10 +152,10 @@ void ImProcFunctions::PF_correct_RT(LabImage * src, double radius, int thresh)
|
|||||||
if (fringe[i * width + j] < threshfactor) {
|
if (fringe[i * width + j] < threshfactor) {
|
||||||
float atot = 0.f, btot = 0.f, norm = 0.f;
|
float atot = 0.f, btot = 0.f, norm = 0.f;
|
||||||
|
|
||||||
for (int i1 = max(0, i - halfwin + 1); i1 < min(height, i + halfwin); i1++)
|
for (int i1 = std::max(0, i - halfwin + 1); i1 < std::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
|
||||||
float wt = fringe[i1 * width + j1];
|
const float wt = fringe[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;
|
||||||
@ -174,10 +172,10 @@ void ImProcFunctions::PF_correct_RT(LabImage * src, double radius, int thresh)
|
|||||||
if (fringe[i * width + j] < threshfactor) {
|
if (fringe[i * width + j] < threshfactor) {
|
||||||
float atot = 0.f, btot = 0.f, norm = 0.f;
|
float atot = 0.f, btot = 0.f, norm = 0.f;
|
||||||
|
|
||||||
for (int i1 = max(0, i - halfwin + 1); i1 < min(height, i + halfwin); i1++)
|
for (int i1 = std::max(0, i - halfwin + 1); i1 < std::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
|
||||||
float wt = fringe[i1 * width + j1];
|
const float wt = fringe[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;
|
||||||
@ -194,10 +192,10 @@ void ImProcFunctions::PF_correct_RT(LabImage * src, double radius, int thresh)
|
|||||||
if (fringe[i * width + j] < threshfactor) {
|
if (fringe[i * width + j] < threshfactor) {
|
||||||
float atot = 0.f, btot = 0.f, norm = 0.f;
|
float atot = 0.f, btot = 0.f, norm = 0.f;
|
||||||
|
|
||||||
for (int i1 = max(0, i - halfwin + 1); i1 < min(height, i + halfwin); i1++)
|
for (int i1 = std::max(0, i - halfwin + 1); i1 < std::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
|
||||||
float wt = fringe[i1 * width + j1];
|
const float wt = fringe[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;
|
||||||
@ -214,7 +212,7 @@ void ImProcFunctions::PF_correct_RT(LabImage * src, double radius, int thresh)
|
|||||||
void ImProcFunctions::PF_correct_RTcam(CieImage * src, double radius, int thresh)
|
void ImProcFunctions::PF_correct_RTcam(CieImage * src, double radius, int thresh)
|
||||||
{
|
{
|
||||||
BENCHFUN
|
BENCHFUN
|
||||||
const int halfwin = ceil(2 * radius) + 1;
|
const int halfwin = std::ceil(2 * radius) + 1;
|
||||||
|
|
||||||
std::unique_ptr<FlatCurve> chCurve;
|
std::unique_ptr<FlatCurve> chCurve;
|
||||||
|
|
||||||
@ -226,19 +224,19 @@ void ImProcFunctions::PF_correct_RTcam(CieImage * src, double radius, int thresh
|
|||||||
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
|
||||||
std::unique_ptr<float[]> fringe(new float[width * height]);
|
const 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** const 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** const srbb = src->C_p; // we use the src->C_p buffer to avoid memory allocation/deallocation and reduce memory pressure
|
||||||
const JaggedArray<float> tmaa(width, height);
|
JaggedArray<float> tmaa(width, height);
|
||||||
const JaggedArray<float> tmbb(width, height);
|
JaggedArray<float> tmbb(width, height);
|
||||||
|
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
#pragma omp parallel
|
#pragma omp parallel
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#ifdef __SSE2__
|
#ifdef __SSE2__
|
||||||
vfloat piDiv180v = F2V(RT_PI_F_180);
|
const vfloat piDiv180v = F2V(RT_PI_F_180);
|
||||||
#endif
|
#endif
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
#pragma omp for
|
#pragma omp for
|
||||||
@ -249,13 +247,13 @@ void ImProcFunctions::PF_correct_RTcam(CieImage * src, double radius, int thresh
|
|||||||
#ifdef __SSE2__
|
#ifdef __SSE2__
|
||||||
|
|
||||||
for (; j < width - 3; j += 4) {
|
for (; j < width - 3; j += 4) {
|
||||||
vfloat2 sincosvalv = xsincosf(piDiv180v * LVFU(src->h_p[i][j]));
|
const vfloat2 sincosvalv = xsincosf(piDiv180v * LVFU(src->h_p[i][j]));
|
||||||
STVFU(sraa[i][j], LVFU(src->C_p[i][j]) * sincosvalv.y);
|
STVFU(sraa[i][j], LVFU(src->C_p[i][j]) * sincosvalv.y);
|
||||||
STVFU(srbb[i][j], LVFU(src->C_p[i][j]) * sincosvalv.x);
|
STVFU(srbb[i][j], LVFU(src->C_p[i][j]) * sincosvalv.x);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
for (; j < width; j++) {
|
for (; j < width; j++) {
|
||||||
float2 sincosval = xsincosf(RT_PI_F_180 * src->h_p[i][j]);
|
const float2 sincosval = xsincosf(RT_PI_F_180 * src->h_p[i][j]);
|
||||||
sraa[i][j] = src->C_p[i][j] * sincosval.y;
|
sraa[i][j] = src->C_p[i][j] * sincosval.y;
|
||||||
srbb[i][j] = src->C_p[i][j] * sincosval.x;
|
srbb[i][j] = src->C_p[i][j] * sincosval.x;
|
||||||
}
|
}
|
||||||
@ -313,10 +311,10 @@ void ImProcFunctions::PF_correct_RTcam(CieImage * src, double radius, int thresh
|
|||||||
if (chCurve) {
|
if (chCurve) {
|
||||||
#ifdef __SSE2__
|
#ifdef __SSE2__
|
||||||
// use the precalculated atan2 values
|
// use the precalculated atan2 values
|
||||||
float HH = fringe[i * width + j];
|
const float HH = fringe[i * width + j];
|
||||||
#else
|
#else
|
||||||
// no precalculated values without SSE => calculate
|
// no precalculated values without SSE => calculate
|
||||||
float HH = xatan2f(srbb[i][j], sraa[i][j]);
|
const float HH = xatan2f(srbb[i][j], sraa[i][j]);
|
||||||
#endif
|
#endif
|
||||||
float chparam = chCurve->getVal(Color::huelab_to_huehsv2(HH)) - 0.5f; //get C=f(H)
|
float chparam = chCurve->getVal(Color::huelab_to_huehsv2(HH)) - 0.5f; //get C=f(H)
|
||||||
|
|
||||||
@ -327,14 +325,14 @@ void ImProcFunctions::PF_correct_RTcam(CieImage * src, double radius, int thresh
|
|||||||
chromaChfactor = SQR(1.f + chparam);
|
chromaChfactor = SQR(1.f + chparam);
|
||||||
}
|
}
|
||||||
|
|
||||||
float chroma = chromaChfactor * (SQR(sraa[i][j] - tmaa[i][j]) + SQR(srbb[i][j] - tmbb[i][j])); //modulate chroma function hue
|
const 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
chromave /= (height * width);
|
chromave /= height * width;
|
||||||
|
|
||||||
if (chromave > 0.0) {
|
if (chromave > 0.0) {
|
||||||
// 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
|
||||||
@ -367,10 +365,10 @@ void ImProcFunctions::PF_correct_RTcam(CieImage * src, double radius, int thresh
|
|||||||
if (fringe[i * width + j] < threshfactor) {
|
if (fringe[i * width + j] < threshfactor) {
|
||||||
float atot = 0.f, btot = 0.f, norm = 0.f;
|
float atot = 0.f, btot = 0.f, norm = 0.f;
|
||||||
|
|
||||||
for (int i1 = max(0, i - halfwin + 1); i1 < min(height, i + halfwin); i1++)
|
for (int i1 = std::max(0, i - halfwin + 1); i1 < std::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
|
||||||
float wt = fringe[i1 * width + j1];
|
const 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;
|
||||||
@ -390,10 +388,10 @@ void ImProcFunctions::PF_correct_RTcam(CieImage * src, double radius, int thresh
|
|||||||
if (fringe[i * width + j] < threshfactor) {
|
if (fringe[i * width + j] < threshfactor) {
|
||||||
float atot = 0.f, btot = 0.f, norm = 0.f;
|
float atot = 0.f, btot = 0.f, norm = 0.f;
|
||||||
|
|
||||||
for (int i1 = max(0, i - halfwin + 1); i1 < min(height, i + halfwin); i1++)
|
for (int i1 = std::max(0, i - halfwin + 1); i1 < std::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
|
||||||
float wt = fringe[i1 * width + j1];
|
const 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;
|
||||||
@ -413,10 +411,10 @@ void ImProcFunctions::PF_correct_RTcam(CieImage * src, double radius, int thresh
|
|||||||
if (fringe[i * width + j] < threshfactor) {
|
if (fringe[i * width + j] < threshfactor) {
|
||||||
float atot = 0.f, btot = 0.f, norm = 0.f;
|
float atot = 0.f, btot = 0.f, norm = 0.f;
|
||||||
|
|
||||||
for (int i1 = max(0, i - halfwin + 1); i1 < min(height, i + halfwin); i1++)
|
for (int i1 = std::max(0, i - halfwin + 1); i1 < std::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
|
||||||
float wt = fringe[i1 * width + j1];
|
const 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;
|
||||||
@ -439,15 +437,15 @@ void ImProcFunctions::PF_correct_RTcam(CieImage * src, double radius, int thresh
|
|||||||
#ifdef __SSE2__
|
#ifdef __SSE2__
|
||||||
|
|
||||||
for (; j < width - 3; j += 4) {
|
for (; j < width - 3; j += 4) {
|
||||||
vfloat interav = LVFU(tmaa[i][j]);
|
const vfloat interav = LVFU(tmaa[i][j]);
|
||||||
vfloat interbv = LVFU(tmbb[i][j]);
|
const vfloat interbv = LVFU(tmbb[i][j]);
|
||||||
STVFU(src->h_p[i][j], xatan2f(interbv, interav) / F2V(RT_PI_F_180));
|
STVFU(src->h_p[i][j], xatan2f(interbv, interav) / F2V(RT_PI_F_180));
|
||||||
STVFU(src->C_p[i][j], vsqrtf(SQRV(interbv) + SQRV(interav)));
|
STVFU(src->C_p[i][j], vsqrtf(SQRV(interbv) + SQRV(interav)));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
for (; j < width; j++) {
|
for (; j < width; j++) {
|
||||||
float intera = tmaa[i][j];
|
const float intera = tmaa[i][j];
|
||||||
float interb = tmbb[i][j];
|
const float interb = tmbb[i][j];
|
||||||
src->h_p[i][j] = xatan2f(interb, intera) / RT_PI_F_180;
|
src->h_p[i][j] = xatan2f(interb, intera) / RT_PI_F_180;
|
||||||
src->C_p[i][j] = sqrt(SQR(interb) + SQR(intera));
|
src->C_p[i][j] = sqrt(SQR(interb) + SQR(intera));
|
||||||
}
|
}
|
||||||
@ -466,9 +464,9 @@ void ImProcFunctions::Badpixelscam(CieImage * src, double radius, int thresh, in
|
|||||||
|
|
||||||
constexpr float eps = 1.f;
|
constexpr float eps = 1.f;
|
||||||
|
|
||||||
const JaggedArray<float> tmL(width, height);
|
JaggedArray<float> tmL(width, height);
|
||||||
|
|
||||||
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
|
#ifdef _OPENMP
|
||||||
@ -488,8 +486,8 @@ void ImProcFunctions::Badpixelscam(CieImage * src, double radius, int thresh, in
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#ifdef __SSE2__
|
#ifdef __SSE2__
|
||||||
vfloat shthrv = F2V(shthr);
|
const vfloat shthrv = F2V(shthr);
|
||||||
vfloat onev = F2V(1.f);
|
const vfloat onev = F2V(1.f);
|
||||||
#endif // __SSE2__
|
#endif // __SSE2__
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
#pragma omp for
|
#pragma omp for
|
||||||
@ -498,53 +496,57 @@ void ImProcFunctions::Badpixelscam(CieImage * src, double radius, int thresh, in
|
|||||||
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++) {
|
||||||
float shfabs = fabs(src->sh_p[i][j] - tmL[i][j]);
|
const float shfabs = std::fabs(src->sh_p[i][j] - tmL[i][j]);
|
||||||
float shmed = 0.f;
|
float shmed = 0.f;
|
||||||
|
|
||||||
for (int i1 = max(0, i - 2); i1 <= 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++) {
|
||||||
shmed += fabs(src->sh_p[i1][j1] - tmL[i1][j1]);
|
shmed += std::fabs(src->sh_p[i1][j1] - tmL[i1][j1]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
badpix[i * width + j] = (shfabs > ((shmed - shfabs) * shthr));
|
badpix[i * width + j] = shfabs > ((shmed - shfabs) * shthr);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __SSE2__
|
#ifdef __SSE2__
|
||||||
|
|
||||||
for (; j < width - 5; j += 4) {
|
for (; j < width - 5; j += 4) {
|
||||||
vfloat shfabsv = vabsf(LVFU(src->sh_p[i][j]) - LVFU(tmL[i][j]));
|
const vfloat shfabsv = vabsf(LVFU(src->sh_p[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 = 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++) {
|
||||||
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], vselfzero(vmaskf_gt(shfabsv, (shmedv - shfabsv) * shthrv), onev));
|
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->sh_p[i][j] - tmL[i][j]);
|
const float shfabs = std::fabs(src->sh_p[i][j] - tmL[i][j]);
|
||||||
float shmed = 0.f;
|
float shmed = 0.f;
|
||||||
|
|
||||||
for (int i1 = max(0, i - 2); i1 <= 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++) {
|
||||||
shmed += fabs(src->sh_p[i1][j1] - tmL[i1][j1]);
|
shmed += std::fabs(src->sh_p[i1][j1] - tmL[i1][j1]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
badpix[i * width + j] = (shfabs > ((shmed - shfabs) * shthr));
|
badpix[i * width + j] = shfabs > ((shmed - shfabs) * shthr);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; j < width; j++) {
|
for (; j < width; j++) {
|
||||||
float shfabs = fabs(src->sh_p[i][j] - tmL[i][j]);
|
const float shfabs = std::fabs(src->sh_p[i][j] - tmL[i][j]);
|
||||||
float shmed = 0.f;
|
float shmed = 0.f;
|
||||||
|
|
||||||
for (int i1 = max(0, i - 2); i1 <= 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++) {
|
||||||
shmed += fabs(src->sh_p[i1][j1] - tmL[i1][j1]);
|
shmed += std::fabs(src->sh_p[i1][j1] - tmL[i1][j1]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
badpix[i * width + j] = (shfabs > ((shmed - shfabs) * shthr));
|
badpix[i * width + j] = shfabs > ((shmed - shfabs) * shthr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -559,12 +561,12 @@ void ImProcFunctions::Badpixelscam(CieImage * src, double radius, int thresh, in
|
|||||||
if (badpix[i * width + j]) {
|
if (badpix[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 = max(0, i - 2); i1 <= 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 (!badpix[i1 * width + j1]) {
|
||||||
sum += src->sh_p[i1][j1];
|
sum += src->sh_p[i1][j1];
|
||||||
tot += 1.f;
|
tot += 1.f;
|
||||||
float dirsh = 1.f / (SQR(src->sh_p[i1][j1] - src->sh_p[i][j]) + eps);
|
const float dirsh = 1.f / (SQR(src->sh_p[i1][j1] - src->sh_p[i][j]) + eps);
|
||||||
shsum += dirsh * src->sh_p[i1][j1];
|
shsum += dirsh * src->sh_p[i1][j1];
|
||||||
norm += dirsh;
|
norm += dirsh;
|
||||||
}
|
}
|
||||||
@ -582,12 +584,12 @@ void ImProcFunctions::Badpixelscam(CieImage * src, double radius, int thresh, in
|
|||||||
if (badpix[i * width + j]) {
|
if (badpix[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 = max(0, i - 2); i1 <= 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 (!badpix[i1 * width + j1]) {
|
||||||
sum += src->sh_p[i1][j1];
|
sum += src->sh_p[i1][j1];
|
||||||
tot += 1.f;
|
tot += 1.f;
|
||||||
float dirsh = 1.f / (SQR(src->sh_p[i1][j1] - src->sh_p[i][j]) + eps);
|
const float dirsh = 1.f / (SQR(src->sh_p[i1][j1] - src->sh_p[i][j]) + eps);
|
||||||
shsum += dirsh * src->sh_p[i1][j1];
|
shsum += dirsh * src->sh_p[i1][j1];
|
||||||
norm += dirsh;
|
norm += dirsh;
|
||||||
}
|
}
|
||||||
@ -605,12 +607,12 @@ void ImProcFunctions::Badpixelscam(CieImage * src, double radius, int thresh, in
|
|||||||
if (badpix[i * width + j]) {
|
if (badpix[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 = max(0, i - 2); i1 <= 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 (!badpix[i1 * width + j1]) {
|
||||||
sum += src->sh_p[i1][j1];
|
sum += src->sh_p[i1][j1];
|
||||||
tot += 1.f;
|
tot += 1.f;
|
||||||
float dirsh = 1.f / (SQR(src->sh_p[i1][j1] - src->sh_p[i][j]) + eps);
|
const float dirsh = 1.f / (SQR(src->sh_p[i1][j1] - src->sh_p[i][j]) + eps);
|
||||||
shsum += dirsh * src->sh_p[i1][j1];
|
shsum += dirsh * src->sh_p[i1][j1];
|
||||||
norm += dirsh;
|
norm += dirsh;
|
||||||
}
|
}
|
||||||
@ -629,9 +631,8 @@ void ImProcFunctions::Badpixelscam(CieImage * src, double radius, int thresh, in
|
|||||||
// end luma badpixels
|
// end luma badpixels
|
||||||
|
|
||||||
if (hotbad) {
|
if (hotbad) {
|
||||||
|
JaggedArray<float> sraa(width, height);
|
||||||
const JaggedArray<float> sraa(width, height);
|
JaggedArray<float> srbb(width, height);
|
||||||
const JaggedArray<float> srbb(width, height);
|
|
||||||
|
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
#pragma omp parallel
|
#pragma omp parallel
|
||||||
@ -639,7 +640,7 @@ void ImProcFunctions::Badpixelscam(CieImage * src, double radius, int thresh, in
|
|||||||
{
|
{
|
||||||
|
|
||||||
#ifdef __SSE2__
|
#ifdef __SSE2__
|
||||||
vfloat piDiv180v = F2V(RT_PI_F_180);
|
const vfloat piDiv180v = F2V(RT_PI_F_180);
|
||||||
#endif // __SSE2__
|
#endif // __SSE2__
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
#pragma omp for
|
#pragma omp for
|
||||||
@ -650,24 +651,23 @@ void ImProcFunctions::Badpixelscam(CieImage * src, double radius, int thresh, in
|
|||||||
#ifdef __SSE2__
|
#ifdef __SSE2__
|
||||||
|
|
||||||
for (; j < width - 3; j += 4) {
|
for (; j < width - 3; j += 4) {
|
||||||
vfloat2 sincosvalv = xsincosf(piDiv180v * LVFU(src->h_p[i][j]));
|
const vfloat2 sincosvalv = xsincosf(piDiv180v * LVFU(src->h_p[i][j]));
|
||||||
STVFU(sraa[i][j], LVFU(src->C_p[i][j])*sincosvalv.y);
|
STVFU(sraa[i][j], LVFU(src->C_p[i][j])*sincosvalv.y);
|
||||||
STVFU(srbb[i][j], LVFU(src->C_p[i][j])*sincosvalv.x);
|
STVFU(srbb[i][j], LVFU(src->C_p[i][j])*sincosvalv.x);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
for (; j < width; j++) {
|
for (; j < width; j++) {
|
||||||
float2 sincosval = xsincosf(RT_PI_F_180 * src->h_p[i][j]);
|
const float2 sincosval = xsincosf(RT_PI_F_180 * src->h_p[i][j]);
|
||||||
sraa[i][j] = src->C_p[i][j] * sincosval.y;
|
sraa[i][j] = src->C_p[i][j] * sincosval.y;
|
||||||
srbb[i][j] = src->C_p[i][j] * sincosval.x;
|
srbb[i][j] = src->C_p[i][j] * sincosval.x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float ** tmaa = tmL; // reuse tmL buffer
|
float** const tmaa = tmL; // reuse tmL buffer
|
||||||
const JaggedArray<float> tmbb(width, height);
|
JaggedArray<float> tmbb(width, height);
|
||||||
|
|
||||||
if (mode == 2) { //choice of gaussian blur
|
if (mode == 2) { //choice of gaussian blur
|
||||||
|
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
#pragma omp parallel
|
#pragma omp parallel
|
||||||
#endif
|
#endif
|
||||||
@ -687,12 +687,12 @@ void ImProcFunctions::Badpixelscam(CieImage * src, double radius, int thresh, in
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (int i = 0; i < height; i++) {
|
for (int i = 0; i < height; i++) {
|
||||||
int ip = i < 2 ? i + 2 : i -2;
|
const int ip = i < 2 ? i + 2 : i - 2;
|
||||||
int in = i > height - 3 ? i - 2 : i + 2;
|
const int in = i > height - 3 ? i - 2 : i + 2;
|
||||||
|
|
||||||
for (int j = 0; j < width; j++) {
|
for (int j = 0; j < width; j++) {
|
||||||
int jp = j < 2 ? j + 2 : j -2;
|
const int jp = j < 2 ? j + 2 : j -2;
|
||||||
int jn = j > width - 3 ? j - 2 : j + 2;
|
const int jn = j > width - 3 ? j - 2 : j + 2;
|
||||||
|
|
||||||
tmaa[i][j] = median(sraa[ip][jp], sraa[ip][j], sraa[ip][jn], sraa[i][jp], sraa[i][j], sraa[i][jn], sraa[in][jp], sraa[in][j], sraa[in][jn]);
|
tmaa[i][j] = median(sraa[ip][jp], sraa[ip][j], sraa[ip][jn], sraa[i][jp], sraa[i][j], sraa[i][jn], sraa[in][jp], sraa[in][j], sraa[in][jn]);
|
||||||
}
|
}
|
||||||
@ -702,12 +702,12 @@ void ImProcFunctions::Badpixelscam(CieImage * src, double radius, int thresh, in
|
|||||||
#pragma omp for
|
#pragma omp for
|
||||||
#endif
|
#endif
|
||||||
for (int i = 0; i < height; i++) {
|
for (int i = 0; i < height; i++) {
|
||||||
int ip = i < 2 ? i + 2 : i -2;
|
const int ip = i < 2 ? i + 2 : i - 2;
|
||||||
int in = i > height - 3 ? i - 2 : i + 2;
|
const int in = i > height - 3 ? i - 2 : i + 2;
|
||||||
|
|
||||||
for (int j = 0; j < width; j++) {
|
for (int j = 0; j < width; j++) {
|
||||||
int jp = j < 2 ? j + 2 : j -2;
|
const int jp = j < 2 ? j + 2 : j -2;
|
||||||
int jn = j > width - 3 ? j - 2 : j + 2;
|
const int jn = j > width - 3 ? j - 2 : j + 2;
|
||||||
|
|
||||||
tmbb[i][j] = median(srbb[ip][jp], srbb[ip][j], srbb[ip][jn], srbb[i][jp], srbb[i][j], srbb[i][jn], srbb[in][jp], srbb[in][j], srbb[in][jn]);
|
tmbb[i][j] = median(srbb[ip][jp], srbb[ip][j], srbb[ip][jn], srbb[i][jp], srbb[i][j], srbb[i][jn], srbb[in][jp], srbb[in][j], srbb[in][jn]);
|
||||||
}
|
}
|
||||||
@ -723,13 +723,13 @@ void ImProcFunctions::Badpixelscam(CieImage * src, double radius, int thresh, in
|
|||||||
|
|
||||||
for (int i = 0; i < height; i++) {
|
for (int i = 0; i < height; i++) {
|
||||||
for (int j = 0; j < width; j++) {
|
for (int j = 0; j < width; j++) {
|
||||||
float chroma = SQR(sraa[i][j] - tmaa[i][j]) + SQR(srbb[i][j] - tmbb[i][j]);
|
const float chroma = SQR(sraa[i][j] - tmaa[i][j]) + SQR(srbb[i][j] - tmbb[i][j]);
|
||||||
chrommed += chroma;
|
chrommed += chroma;
|
||||||
badpix[i * width + j] = chroma;
|
badpix[i * width + j] = chroma;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
chrommed /= (height * width);
|
chrommed /= height * width;
|
||||||
|
|
||||||
if (chrommed > 0.0) {
|
if (chrommed > 0.0) {
|
||||||
// now as chrommed is calculated, 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
|
||||||
@ -738,8 +738,8 @@ void ImProcFunctions::Badpixelscam(CieImage * src, double radius, int thresh, in
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#ifdef __SSE2__
|
#ifdef __SSE2__
|
||||||
vfloat chrommedv = F2V(chrommed);
|
const vfloat chrommedv = F2V(chrommed);
|
||||||
vfloat onev = F2V(1.f);
|
const vfloat onev = F2V(1.f);
|
||||||
#endif
|
#endif
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
#pragma omp for
|
#pragma omp for
|
||||||
@ -759,7 +759,7 @@ void ImProcFunctions::Badpixelscam(CieImage * src, double radius, int thresh, in
|
|||||||
}
|
}
|
||||||
|
|
||||||
const float threshfactor = 1.f / ((thresh * chrommed) / 33.f + chrommed);
|
const float threshfactor = 1.f / ((thresh * chrommed) / 33.f + chrommed);
|
||||||
const int halfwin = ceil(2 * radius) + 1;
|
const int halfwin = std::ceil(2 * radius) + 1;
|
||||||
|
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
#pragma omp parallel for schedule(dynamic,16)
|
#pragma omp parallel for schedule(dynamic,16)
|
||||||
@ -772,9 +772,9 @@ void ImProcFunctions::Badpixelscam(CieImage * src, double radius, int thresh, in
|
|||||||
if (badpix[i * width + j] < threshfactor) {
|
if (badpix[i * width + j] < threshfactor) {
|
||||||
float atot = 0.f, btot = 0.f, norm = 0.f;
|
float atot = 0.f, btot = 0.f, norm = 0.f;
|
||||||
|
|
||||||
for (int i1 = max(0, i - halfwin + 1); i1 < min(height, i + halfwin); i1++)
|
for (int i1 = std::max(0, i - halfwin + 1); i1 < std::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];
|
const 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;
|
||||||
@ -794,18 +794,18 @@ void ImProcFunctions::Badpixelscam(CieImage * src, double radius, int thresh, in
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __SSE2__
|
#ifdef __SSE2__
|
||||||
vfloat threshfactorv = F2V(threshfactor);
|
const vfloat threshfactorv = F2V(threshfactor);
|
||||||
vfloat chromv = F2V(chrom);
|
const vfloat chromv = F2V(chrom);
|
||||||
vfloat piDiv180v = F2V(RT_PI_F_180);
|
const vfloat piDiv180v = F2V(RT_PI_F_180);
|
||||||
for (; j < width - halfwin - 3; j+=4) {
|
for (; j < width - halfwin - 3; j+=4) {
|
||||||
|
|
||||||
vmask selMask = vmaskf_lt(LVFU(badpix[i * width + j]), threshfactorv);
|
vmask selMask = vmaskf_lt(LVFU(badpix[i * width + j]), threshfactorv);
|
||||||
if (_mm_movemask_ps((vfloat)selMask)) {
|
if (_mm_movemask_ps((vfloat)selMask)) {
|
||||||
vfloat atotv = ZEROV, btotv = ZEROV, normv = ZEROV;
|
vfloat atotv = ZEROV, btotv = ZEROV, normv = ZEROV;
|
||||||
|
|
||||||
for (int i1 = max(0, i - halfwin + 1); i1 < min(height, i + halfwin); i1++)
|
for (int i1 = std::max(0, i - halfwin + 1); i1 < std::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]);
|
const vfloat wtv = LVFU(badpix[i1 * width + j1]);
|
||||||
atotv += wtv * LVFU(sraa[i1][j1]);
|
atotv += wtv * LVFU(sraa[i1][j1]);
|
||||||
btotv += wtv * LVFU(srbb[i1][j1]);
|
btotv += wtv * LVFU(srbb[i1][j1]);
|
||||||
normv += wtv;
|
normv += wtv;
|
||||||
@ -813,9 +813,9 @@ void ImProcFunctions::Badpixelscam(CieImage * src, double radius, int thresh, in
|
|||||||
|
|
||||||
selMask = vandm(selMask, vmaskf_gt(normv, ZEROV));
|
selMask = vandm(selMask, vmaskf_gt(normv, ZEROV));
|
||||||
if (_mm_movemask_ps((vfloat)selMask)) {
|
if (_mm_movemask_ps((vfloat)selMask)) {
|
||||||
vfloat interav = atotv / normv;
|
const vfloat interav = atotv / normv;
|
||||||
vfloat interbv = btotv / normv;
|
const vfloat interbv = btotv / normv;
|
||||||
vfloat CCv = vsqrtf(SQRV(interbv) + SQRV(interav));
|
const vfloat CCv = vsqrtf(SQRV(interbv) + SQRV(interav));
|
||||||
|
|
||||||
selMask = vandm(selMask, vmaskf_lt(CCv, chromv));
|
selMask = vandm(selMask, vmaskf_lt(CCv, chromv));
|
||||||
if (_mm_movemask_ps((vfloat)selMask)) {
|
if (_mm_movemask_ps((vfloat)selMask)) {
|
||||||
@ -831,9 +831,9 @@ void ImProcFunctions::Badpixelscam(CieImage * src, double radius, int thresh, in
|
|||||||
if (badpix[i * width + j] < threshfactor) {
|
if (badpix[i * width + j] < threshfactor) {
|
||||||
float atot = 0.f, btot = 0.f, norm = 0.f;
|
float atot = 0.f, btot = 0.f, norm = 0.f;
|
||||||
|
|
||||||
for (int i1 = max(0, i - halfwin + 1); i1 < min(height, i + halfwin); i1++)
|
for (int i1 = std::max(0, i - halfwin + 1); i1 < std::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];
|
const 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;
|
||||||
@ -857,9 +857,9 @@ void ImProcFunctions::Badpixelscam(CieImage * src, double radius, int thresh, in
|
|||||||
if (badpix[i * width + j] < threshfactor) {
|
if (badpix[i * width + j] < threshfactor) {
|
||||||
float atot = 0.f, btot = 0.f, norm = 0.f;
|
float atot = 0.f, btot = 0.f, norm = 0.f;
|
||||||
|
|
||||||
for (int i1 = max(0, i - halfwin + 1); i1 < min(height, i + halfwin); i1++)
|
for (int i1 = std::max(0, i - halfwin + 1); i1 < std::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];
|
const 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;
|
||||||
@ -890,15 +890,15 @@ void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, fl
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int halfwin = ceil(2 * radius) + 1;
|
const int halfwin = std::ceil(2 * radius) + 1;
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
const JaggedArray<float> tmL(width, height);
|
JaggedArray<float> tmL(width, height);
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
@ -919,8 +919,8 @@ void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, fl
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#ifdef __SSE2__
|
#ifdef __SSE2__
|
||||||
vfloat shthrv = F2V(shthr);
|
const vfloat shthrv = F2V(shthr);
|
||||||
vfloat onev = F2V(1.f);
|
const vfloat onev = F2V(1.f);
|
||||||
#endif
|
#endif
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
#pragma omp for
|
#pragma omp for
|
||||||
@ -929,24 +929,24 @@ 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++) {
|
||||||
float shfabs = fabs(src->L[i][j] - tmL[i][j]);
|
const float shfabs = std::fabs(src->L[i][j] - tmL[i][j]);
|
||||||
float shmed = 0.f;
|
float shmed = 0.f;
|
||||||
|
|
||||||
for (int i1 = max(0, i - 2); i1 <= 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++) {
|
||||||
shmed += fabs(src->L[i1][j1] - tmL[i1][j1]);
|
shmed += std::fabs(src->L[i1][j1] - tmL[i1][j1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
badpix[i * width + j] = (shfabs > ((shmed - shfabs) * shthr));
|
badpix[i * width + j] = shfabs > ((shmed - shfabs) * shthr);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __SSE2__
|
#ifdef __SSE2__
|
||||||
|
|
||||||
for (; j < width - 5; j += 4) {
|
for (; j < width - 5; j += 4) {
|
||||||
vfloat shfabsv = vabsf(LVFU(src->L[i][j]) - LVFU(tmL[i][j]));
|
const 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 = 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++) {
|
||||||
shmedv += vabsf(LVFU(src->L[i1][j1]) - LVFU(tmL[i1][j1]));
|
shmedv += vabsf(LVFU(src->L[i1][j1]) - LVFU(tmL[i1][j1]));
|
||||||
}
|
}
|
||||||
@ -955,27 +955,27 @@ void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, fl
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
for (; j < width - 2; j++) {
|
for (; j < width - 2; j++) {
|
||||||
float shfabs = fabs(src->L[i][j] - tmL[i][j]);
|
const float shfabs = std::fabs(src->L[i][j] - tmL[i][j]);
|
||||||
float shmed = 0.f;
|
float shmed = 0.f;
|
||||||
|
|
||||||
for (int i1 = max(0, i - 2); i1 <= 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++) {
|
||||||
shmed += fabs(src->L[i1][j1] - tmL[i1][j1]);
|
shmed += std::fabs(src->L[i1][j1] - tmL[i1][j1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
badpix[i * width + j] = (shfabs > ((shmed - shfabs) * shthr));
|
badpix[i * width + j] = shfabs > ((shmed - shfabs) * shthr);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; j < width; j++) {
|
for (; j < width; j++) {
|
||||||
float shfabs = fabs(src->L[i][j] - tmL[i][j]);
|
const float shfabs = std::fabs(src->L[i][j] - tmL[i][j]);
|
||||||
float shmed = 0.f;
|
float shmed = 0.f;
|
||||||
|
|
||||||
for (int i1 = max(0, i - 2); i1 <= 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++) {
|
||||||
shmed += fabs(src->L[i1][j1] - tmL[i1][j1]);
|
shmed += std::fabs(src->L[i1][j1] - tmL[i1][j1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
badpix[i * width + j] = (shfabs > ((shmed - shfabs) * shthr));
|
badpix[i * width + j] = shfabs > ((shmed - shfabs) * shthr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -990,12 +990,12 @@ void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, fl
|
|||||||
if (badpix[i * width + j]) {
|
if (badpix[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 = max(0, i - 2); i1 <= 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 (!badpix[i1 * width + j1]) {
|
||||||
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);
|
const 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;
|
||||||
}
|
}
|
||||||
@ -1013,12 +1013,12 @@ void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, fl
|
|||||||
if (badpix[i * width + j]) {
|
if (badpix[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 = max(0, i - 2); i1 <= 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 (!badpix[i1 * width + j1]) {
|
||||||
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);
|
const 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;
|
||||||
}
|
}
|
||||||
@ -1036,12 +1036,12 @@ void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, fl
|
|||||||
if (badpix[i * width + j]) {
|
if (badpix[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 = max(0, i - 2); i1 <= 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 (!badpix[i1 * width + j1]) {
|
||||||
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);
|
const 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;
|
||||||
}
|
}
|
||||||
@ -1059,8 +1059,8 @@ void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, fl
|
|||||||
|
|
||||||
// end luma badpixels
|
// end luma badpixels
|
||||||
|
|
||||||
float ** tmaa = tmL; // reuse tmL buffer
|
float** const tmaa = tmL; // reuse tmL buffer
|
||||||
const JaggedArray<float> tmbb(width, height);
|
JaggedArray<float> tmbb(width, height);
|
||||||
|
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
#pragma omp parallel
|
#pragma omp parallel
|
||||||
@ -1080,15 +1080,15 @@ void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, fl
|
|||||||
|
|
||||||
for (int i = 0; i < height; i++) {
|
for (int i = 0; i < height; i++) {
|
||||||
for (int j = 0; j < width; j++) {
|
for (int j = 0; j < width; j++) {
|
||||||
float chroma = SQR(src->a[i][j] - tmaa[i][j]) + SQR(src->b[i][j] - tmbb[i][j]);
|
const float chroma = SQR(src->a[i][j] - tmaa[i][j]) + SQR(src->b[i][j] - tmbb[i][j]);
|
||||||
chrommed += chroma;
|
chrommed += chroma;
|
||||||
badpix[i * width + j] = chroma;
|
badpix[i * width + j] = chroma;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
chrommed /= (height * width);
|
chrommed /= height * width;
|
||||||
if(chrommed > 0.0) {
|
|
||||||
|
|
||||||
|
if (chrommed > 0.0) {
|
||||||
// now as chrommed is calculated, 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
|
||||||
@ -1096,8 +1096,8 @@ void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, fl
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#ifdef __SSE2__
|
#ifdef __SSE2__
|
||||||
vfloat chrommedv = F2V(chrommed);
|
const vfloat chrommedv = F2V(chrommed);
|
||||||
vfloat onev = F2V(1.f);
|
const vfloat onev = F2V(1.f);
|
||||||
#endif
|
#endif
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
#pragma omp for
|
#pragma omp for
|
||||||
@ -1128,13 +1128,12 @@ 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 < halfwin; j++) {
|
for (; j < halfwin; j++) {
|
||||||
|
|
||||||
if (badpix[i * width + j] < threshfactor) {
|
if (badpix[i * width + j] < threshfactor) {
|
||||||
float atot = 0.f, btot = 0.f, norm = 0.f;
|
float atot = 0.f, btot = 0.f, norm = 0.f;
|
||||||
|
|
||||||
for (int i1 = max(0, i - halfwin + 1); i1 < min(height, i + halfwin); i1++) {
|
for (int i1 = std::max(0, i - halfwin + 1); i1 < std::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];
|
const 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;
|
||||||
@ -1148,26 +1147,25 @@ void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, fl
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __SSE2__
|
#ifdef __SSE2__
|
||||||
vfloat chromv = F2V(chrom);
|
const vfloat chromv = F2V(chrom);
|
||||||
vfloat threshfactorv = F2V(threshfactor);
|
const vfloat threshfactorv = F2V(threshfactor);
|
||||||
for (; j < width - halfwin - 3; j += 4) {
|
for (; j < width - halfwin - 3; j += 4) {
|
||||||
|
|
||||||
vmask selMask = vmaskf_lt(LVFU(badpix[i * width + j]), threshfactorv);
|
vmask selMask = vmaskf_lt(LVFU(badpix[i * width + j]), threshfactorv);
|
||||||
if (_mm_movemask_ps((vfloat)selMask)) {
|
if (_mm_movemask_ps(reinterpret_cast<vfloat>(selMask))) {
|
||||||
vfloat atotv = ZEROV, btotv = ZEROV, normv = ZEROV;
|
vfloat atotv = ZEROV, btotv = ZEROV, normv = ZEROV;
|
||||||
|
|
||||||
for (int i1 = max(0, i - halfwin + 1); i1 < min(height, i + halfwin); i1++) {
|
for (int i1 = std::max(0, i - halfwin + 1); i1 < std::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]);
|
const 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(reinterpret_cast<vfloat>(selMask))) {
|
||||||
vfloat aOrig = LVFU(src->a[i][j]);
|
const vfloat aOrig = LVFU(src->a[i][j]);
|
||||||
vfloat bOrig = LVFU(src->b[i][j]);
|
const vfloat bOrig = LVFU(src->b[i][j]);
|
||||||
STVFU(src->a[i][j], vself(selMask, atotv / normv, aOrig));
|
STVFU(src->a[i][j], vself(selMask, atotv / normv, aOrig));
|
||||||
STVFU(src->b[i][j], vself(selMask, btotv / normv, bOrig));
|
STVFU(src->b[i][j], vself(selMask, btotv / normv, bOrig));
|
||||||
}
|
}
|
||||||
@ -1179,9 +1177,9 @@ void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, fl
|
|||||||
if (badpix[i * width + j] < threshfactor) {
|
if (badpix[i * width + j] < threshfactor) {
|
||||||
float atot = 0.f, btot = 0.f, norm = 0.f;
|
float atot = 0.f, btot = 0.f, norm = 0.f;
|
||||||
|
|
||||||
for (int i1 = max(0, i - halfwin + 1); i1 < min(height, i + halfwin); i1++) {
|
for (int i1 = std::max(0, i - halfwin + 1); i1 < std::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];
|
const 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;
|
||||||
@ -1199,9 +1197,9 @@ void ImProcFunctions::BadpixelsLab(LabImage * src, double radius, int thresh, fl
|
|||||||
if (badpix[i * width + j] < threshfactor) {
|
if (badpix[i * width + j] < threshfactor) {
|
||||||
float atot = 0.f, btot = 0.f, norm = 0.f;
|
float atot = 0.f, btot = 0.f, norm = 0.f;
|
||||||
|
|
||||||
for (int i1 = max(0, i - halfwin + 1); i1 < min(height, i + halfwin); i1++) {
|
for (int i1 = std::max(0, i - halfwin + 1); i1 < std::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];
|
const 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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user