Haze removal doesn't work with images with large overexposed regions, fixes #5181, patch by @agriggio and @heckflosse
This commit is contained in:
parent
41495853d6
commit
cbdf3267e0
@ -58,23 +58,20 @@ namespace {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
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 get_dark_channel(const array2D<float> &R, const array2D<float> &G, const array2D<float> &B, array2D<float> &dst, int patchsize, const float ambient[3], bool clip, bool multithread)
|
||||||
{
|
{
|
||||||
const int W = R.width();
|
const int W = R.width();
|
||||||
const int H = R.height();
|
const int H = R.height();
|
||||||
|
|
||||||
int npatches = 0;
|
|
||||||
|
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
#pragma omp parallel for reduction(+:npatches) if (multithread)
|
#pragma omp parallel for if (multithread)
|
||||||
#endif
|
#endif
|
||||||
for (int y = 0; y < H; y += patchsize) {
|
for (int y = 0; y < H; y += patchsize) {
|
||||||
int pH = min(y+patchsize, H);
|
const int pH = min(y + patchsize, H);
|
||||||
for (int x = 0; x < W; x += patchsize, ++npatches) {
|
for (int x = 0; x < W; x += patchsize) {
|
||||||
float val = RT_INFINITY_F;
|
float val = RT_INFINITY_F;
|
||||||
int pW = min(x+patchsize, W);
|
const int pW = min(x + patchsize, W);
|
||||||
for (int yy = y; yy < pH; ++yy) {
|
for (int yy = y; yy < pH; ++yy) {
|
||||||
float yval = RT_INFINITY_F;
|
|
||||||
for (int xx = x; xx < pW; ++xx) {
|
for (int xx = x; xx < pW; ++xx) {
|
||||||
float r = R[yy][xx];
|
float r = R[yy][xx];
|
||||||
float g = G[yy][xx];
|
float g = G[yy][xx];
|
||||||
@ -84,9 +81,8 @@ int get_dark_channel(const array2D<float> &R, const array2D<float> &G, const arr
|
|||||||
g /= ambient[1];
|
g /= ambient[1];
|
||||||
b /= ambient[2];
|
b /= ambient[2];
|
||||||
}
|
}
|
||||||
yval = min(yval, r, g, b);
|
val = min(val, r, g, b);
|
||||||
}
|
}
|
||||||
val = min(val, yval);
|
|
||||||
}
|
}
|
||||||
if (clip) {
|
if (clip) {
|
||||||
val = LIM01(val);
|
val = LIM01(val);
|
||||||
@ -97,7 +93,7 @@ int get_dark_channel(const array2D<float> &R, const array2D<float> &G, const arr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return npatches;
|
return (W / patchsize + ((W % patchsize) > 0)) * (H / patchsize + ((H % patchsize) > 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -121,7 +117,7 @@ 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)) {
|
if (!OOG(dark[y][x], 1.f - 1e-5f)) {
|
||||||
p.push(dark[y][x]);
|
p.push(dark[y][x]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -221,7 +217,7 @@ void ImProcFunctions::dehaze(Imagefloat *img)
|
|||||||
|
|
||||||
const int W = img->getWidth();
|
const int W = img->getWidth();
|
||||||
const int H = img->getHeight();
|
const int H = img->getHeight();
|
||||||
float strength = LIM01(float(params->dehaze.strength) / 100.f * 0.9f);
|
const float strength = LIM01(float(params->dehaze.strength) / 100.f * 0.9f);
|
||||||
|
|
||||||
if (options.rtSettings.verbose) {
|
if (options.rtSettings.verbose) {
|
||||||
std::cout << "dehaze: strength = " << strength << std::endl;
|
std::cout << "dehaze: strength = " << strength << std::endl;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user