dehaze: do not consider out-of-gamut pixels when estimating the ambient light
This commit is contained in:
@@ -58,8 +58,7 @@ namespace {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
int get_dark_channel(const array2D<float> &R, const array2D<float> &G, const array2D<float> &B, array2D<float> &dst,
|
int get_dark_channel(const array2D<float> &R, const array2D<float> &G, const array2D<float> &B, array2D<float> &dst, int patchsize, float *ambient, bool clip, bool multithread)
|
||||||
int patchsize, float *ambient, bool multithread)
|
|
||||||
{
|
{
|
||||||
const int W = R.width();
|
const int W = R.width();
|
||||||
const int H = R.height();
|
const int H = R.height();
|
||||||
@@ -89,7 +88,9 @@ int get_dark_channel(const array2D<float> &R, const array2D<float> &G, const arr
|
|||||||
}
|
}
|
||||||
val = min(val, yval);
|
val = min(val, yval);
|
||||||
}
|
}
|
||||||
|
if (clip) {
|
||||||
val = LIM01(val);
|
val = LIM01(val);
|
||||||
|
}
|
||||||
for (int yy = y; yy < pH; ++yy) {
|
for (int yy = y; yy < pH; ++yy) {
|
||||||
std::fill(dst[yy]+x, dst[yy]+pW, val);
|
std::fill(dst[yy]+x, dst[yy]+pW, val);
|
||||||
}
|
}
|
||||||
@@ -120,9 +121,11 @@ float estimate_ambient_light(const array2D<float> &R, const array2D<float> &G, c
|
|||||||
std::priority_queue<float> p;
|
std::priority_queue<float> p;
|
||||||
for (int y = 0; y < H; y += patchsize) {
|
for (int y = 0; y < H; y += patchsize) {
|
||||||
for (int x = 0; x < W; x += patchsize) {
|
for (int x = 0; x < W; x += patchsize) {
|
||||||
|
if (!OOG(dark[y][x], 1.f)) {
|
||||||
p.push(dark[y][x]);
|
p.push(dark[y][x]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
darklim = get_percentile(p, 0.95);
|
darklim = get_percentile(p, 0.95);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,7 +134,7 @@ float estimate_ambient_light(const array2D<float> &R, const array2D<float> &G, c
|
|||||||
|
|
||||||
for (int y = 0; y < H; y += patchsize) {
|
for (int y = 0; y < H; y += patchsize) {
|
||||||
for (int x = 0; x < W; x += patchsize) {
|
for (int x = 0; x < W; x += patchsize) {
|
||||||
if (dark[y][x] >= darklim) {
|
if (dark[y][x] >= darklim && !OOG(dark[y][x], 1.f)) {
|
||||||
patches.push_back(std::make_pair(x, y));
|
patches.push_back(std::make_pair(x, y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -245,7 +248,7 @@ void ImProcFunctions::dehaze(Imagefloat *img)
|
|||||||
extract_channels(img, R, G, B, patchsize, 1e-1, multiThread);
|
extract_channels(img, R, G, B, patchsize, 1e-1, multiThread);
|
||||||
|
|
||||||
patchsize = max(max(W, H) / 600, 2);
|
patchsize = max(max(W, H) / 600, 2);
|
||||||
npatches = get_dark_channel(R, G, B, dark, patchsize, nullptr, multiThread);
|
npatches = get_dark_channel(R, G, B, dark, patchsize, nullptr, false, multiThread);
|
||||||
DEBUG_DUMP(dark);
|
DEBUG_DUMP(dark);
|
||||||
|
|
||||||
max_t = estimate_ambient_light(R, G, B, dark, patchsize, npatches, ambient);
|
max_t = estimate_ambient_light(R, G, B, dark, patchsize, npatches, ambient);
|
||||||
@@ -256,7 +259,7 @@ void ImProcFunctions::dehaze(Imagefloat *img)
|
|||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
get_dark_channel(R, G, B, dark, patchsize, ambient, multiThread);
|
get_dark_channel(R, G, B, dark, patchsize, ambient, true, multiThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (min(ambient[0], ambient[1], ambient[2]) < 0.01f) {
|
if (min(ambient[0], ambient[1], ambient[2]) < 0.01f) {
|
||||||
@@ -289,6 +292,10 @@ void ImProcFunctions::dehaze(Imagefloat *img)
|
|||||||
|
|
||||||
DEBUG_DUMP(t);
|
DEBUG_DUMP(t);
|
||||||
|
|
||||||
|
if (options.rtSettings.verbose) {
|
||||||
|
std::cout << "dehaze: max distance is " << max_t << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
float depth = -float(params->dehaze.depth) / 100.f;
|
float depth = -float(params->dehaze.depth) / 100.f;
|
||||||
const float t0 = max(1e-3f, std::exp(depth * max_t));
|
const float t0 = max(1e-3f, std::exp(depth * max_t));
|
||||||
const float teps = 1e-3f;
|
const float teps = 1e-3f;
|
||||||
|
Reference in New Issue
Block a user