Skip to content

Commit

Permalink
Fix upsampling using box filter
Browse files Browse the repository at this point in the history
  • Loading branch information
dvicini authored and njroussel committed Apr 3, 2023
1 parent 498807b commit 64e2ab1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions include/mitsuba/core/rfilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ template <typename Scalar_> struct Resampler {

/* Perform the evaluation and record the weight */
auto weight = rfilter->eval(pos * inv_scale);

/* Handle the (numerical) edge case of the pixel center missing
the filter support when upsampling using the box filter. */
if (target_res > source_res && rfilter->is_box_filter())
weight = Float(1.0);
m_weights[i * m_taps + j] = static_cast<Scalar>(weight);
sum += double(weight);
}
Expand Down
10 changes: 9 additions & 1 deletion src/rfilters/tests/test_rfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,21 @@ def test07_resampler_box(variant_scalar_rgb):
assert resampler.taps() == 1
resampler.resample(a, 1, b, 1, 1)

# # Resample to same size
# Resample to smaller size
resampler = mi.Resampler(f, 5, 3)
b = dr.zeros(Float, 3)
assert resampler.taps() == 2
resampler.resample(a, 1, b, 1, 1)
assert dr.all(b == [0.125, 0.5, 0.875])

# Resample to larger size
a = dr.linspace(Float, 0, 1, 2)
resampler = mi.Resampler(f, 2, 3)
b = dr.zeros(Float, 3)
assert resampler.taps() == 1
resampler.resample(a, 1, b, 1, 1)
assert dr.all(b == [0.0, 1.0, 1.0])


def test08_resampler_boundary_conditions(variant_scalar_rgb):
# Use a slightly larger filter
Expand Down

0 comments on commit 64e2ab1

Please sign in to comment.