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 =