guided filter: added support for automatic computation of subsampling factor

This commit is contained in:
Alberto Griggio 2018-10-18 08:53:02 +02:00
parent b50b8dea9f
commit 2026fe1d17
3 changed files with 33 additions and 5 deletions

View File

@ -52,11 +52,39 @@ namespace rtengine {
#endif
namespace {
int calculate_subsampling(int w, int h, int r)
{
if (r == 1) {
return 1;
}
if (max(w, h) <= 600) {
return 1;
}
for (int s = 5; s > 0; --s) {
if (r % s == 0) {
return s;
}
}
return LIM(r / 2, 2, 4);
}
} // namespace
void guidedFilter(const array2D<float> &guide, const array2D<float> &src, array2D<float> &dst, int r, float epsilon, bool multithread, int subsampling)
{
const int W = src.width();
const int H = src.height();
if (subsampling <= 0) {
subsampling = calculate_subsampling(W, H, r);
}
enum Op { MUL, DIVEPSILON, ADD, SUB, ADDMUL, SUBMUL };
const auto apply =

View File

@ -24,6 +24,6 @@
namespace rtengine {
void guidedFilter(const array2D<float> &guide, const array2D<float> &src, array2D<float> &dst, int r, float epsilon, bool multithread, int subsampling=4);
void guidedFilter(const array2D<float> &guide, const array2D<float> &src, array2D<float> &dst, int r, float epsilon, bool multithread, int subsampling=0);
} // namespace rtengine

View File

@ -208,9 +208,9 @@ void extract_channels(Imagefloat *img, array2D<float> &r, array2D<float> &g, arr
}
}
guidedFilter(r, r, r, radius, epsilon, multithread, radius / 2);
guidedFilter(g, g, g, radius, epsilon, multithread, radius / 2);
guidedFilter(b, b, b, radius, epsilon, multithread, radius / 2);
guidedFilter(r, r, r, radius, epsilon, multithread);
guidedFilter(g, g, g, radius, epsilon, multithread);
guidedFilter(b, b, b, radius, epsilon, multithread);
}
@ -287,7 +287,7 @@ void ImProcFunctions::dehaze(Imagefloat *img)
{
array2D<float> guideB(W, H, img->b.ptrs, ARRAY2D_BYREFERENCE);
guidedFilter(guideB, t_tilde, t, radius, epsilon, multiThread, patchsize);
guidedFilter(guideB, t_tilde, t, radius, epsilon, multiThread);
}
DEBUG_DUMP(t);