dehaze: added more user-controllable parameters
This commit is contained in:
@@ -218,6 +218,59 @@ void get_luminance(Imagefloat *img, array2D<float> &Y, TMatrix ws, bool multithr
|
||||
}
|
||||
|
||||
|
||||
void apply_contrast(array2D<float> &dark, int contrast, double scale, bool multithread)
|
||||
{
|
||||
if (contrast) {
|
||||
const int W = dark.width();
|
||||
const int H = dark.height();
|
||||
|
||||
double tot = 0.0;
|
||||
#ifdef _OPENMP
|
||||
#pragma omp parallel for if (multithread)
|
||||
#endif
|
||||
for (int y = 0; y < H; ++y) {
|
||||
double ytot = 0.0;
|
||||
for (int x = 0; x < W; ++x) {
|
||||
ytot += dark[y][x];
|
||||
}
|
||||
#ifdef _OPENMP
|
||||
#pragma omp critical
|
||||
#endif
|
||||
{
|
||||
tot += ytot;
|
||||
}
|
||||
}
|
||||
|
||||
float avg = tot / (W * H);
|
||||
|
||||
std::vector<double> pts = {
|
||||
DCT_NURBS,
|
||||
0, //black point. Value in [0 ; 1] range
|
||||
0, //black point. Value in [0 ; 1] range
|
||||
|
||||
avg - avg * (0.6 - contrast / 250.0), //toe point
|
||||
avg - avg * (0.6 + contrast / 250.0), //value at toe point
|
||||
|
||||
avg + (1 - avg) * (0.6 - contrast / 250.0), //shoulder point
|
||||
avg + (1 - avg) * (0.6 + contrast / 250.0), //value at shoulder point
|
||||
|
||||
1., // white point
|
||||
1. // value at white point
|
||||
};
|
||||
|
||||
const DiagonalCurve curve(pts, CURVES_MIN_POLY_POINTS / scale);
|
||||
|
||||
#ifdef _OPENMP
|
||||
#pragma omp parallel for if (multithread)
|
||||
#endif
|
||||
for (int y = 0; y < H; ++y) {
|
||||
for (int x = 0; x < W; ++x) {
|
||||
dark[y][x] = curve.getVal(dark[y][x]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -231,14 +284,14 @@ void ImProcFunctions::dehaze(Imagefloat *img)
|
||||
|
||||
const int W = img->getWidth();
|
||||
const int H = img->getHeight();
|
||||
const float strength = LIM01(float(params->dehaze.strength) / 100.f * 0.9f);
|
||||
float strength = LIM01(float(params->dehaze.strength) / 100.f * 0.9f);
|
||||
|
||||
if (options.rtSettings.verbose) {
|
||||
std::cout << "dehaze: strength = " << strength << std::endl;
|
||||
}
|
||||
|
||||
array2D<float> dark(W, H);
|
||||
const int patchsize = std::max(W / 200, 2);
|
||||
const int patchsize = std::max(W / (200 + max(params->dehaze.detail, 0)), 2);
|
||||
int npatches = get_dark_channel(*img, dark, patchsize, nullptr, multiThread);
|
||||
DEBUG_DUMP(dark);
|
||||
|
||||
@@ -268,18 +321,27 @@ void ImProcFunctions::dehaze(Imagefloat *img)
|
||||
|
||||
array2D<float> &t_tilde = dark;
|
||||
get_dark_channel(*img, dark, patchsize, ambient, multiThread);
|
||||
apply_contrast(dark, params->dehaze.depth, scale, multiThread);
|
||||
DEBUG_DUMP(t_tilde);
|
||||
|
||||
|
||||
if (!params->dehaze.showDepthMap) {
|
||||
#ifdef _OPENMP
|
||||
#pragma omp parallel for if (multiThread)
|
||||
#pragma omp parallel for if (multiThread)
|
||||
#endif
|
||||
for (int y = 0; y < H; ++y) {
|
||||
for (int x = 0; x < W; ++x) {
|
||||
dark[y][x] = 1.f - strength * dark[y][x];
|
||||
for (int y = 0; y < H; ++y) {
|
||||
for (int x = 0; x < W; ++x) {
|
||||
dark[y][x] = 1.f - strength * dark[y][x];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const int radius = patchsize * 2;
|
||||
float mult = 2.f;
|
||||
if (params->dehaze.detail > 0) {
|
||||
mult -= (params->dehaze.detail / 100.f) * 1.9f;
|
||||
} else {
|
||||
mult -= params->dehaze.detail / 10.f;
|
||||
}
|
||||
const int radius = max(int(patchsize * mult), 1);
|
||||
const float epsilon = 2.5e-4;
|
||||
array2D<float> &t = t_tilde;
|
||||
|
||||
@@ -287,6 +349,19 @@ void ImProcFunctions::dehaze(Imagefloat *img)
|
||||
|
||||
DEBUG_DUMP(t);
|
||||
|
||||
|
||||
if (params->dehaze.showDepthMap) {
|
||||
#ifdef _OPENMP
|
||||
#pragma omp parallel for if (multiThread)
|
||||
#endif
|
||||
for (int y = 0; y < H; ++y) {
|
||||
for (int x = 0; x < W; ++x) {
|
||||
img->r(y, x) = img->g(y, x) = img->b(y, x) = t[y][x] * 65535.f;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const float t0 = 0.01;
|
||||
#ifdef _OPENMP
|
||||
#pragma omp parallel for if (multiThread)
|
||||
@@ -313,7 +388,7 @@ void ImProcFunctions::dehaze(Imagefloat *img)
|
||||
|
||||
if (newmed > 1e-5f) {
|
||||
const float f1 = oldmed / newmed;
|
||||
const float f = f1 * 65535.f;
|
||||
const float f = /* f1 * */ 65535.f;
|
||||
#ifdef _OPENMP
|
||||
#pragma omp parallel for if (multiThread)
|
||||
#endif
|
||||
@@ -328,6 +403,8 @@ void ImProcFunctions::dehaze(Imagefloat *img)
|
||||
Color::hsl2rgbfloat(h, s, l, img->r(y, x), img->g(y, x), img->b(y, x));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
img->normalizeFloatTo65535();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user