Skip to content

Add bilateral filter for feature-preserving smoothing (#969)#970

Merged
brendancol merged 2 commits intomasterfrom
issue-969
Mar 5, 2026
Merged

Add bilateral filter for feature-preserving smoothing (#969)#970
brendancol merged 2 commits intomasterfrom
issue-969

Conversation

@brendancol
Copy link
Contributor

Summary

  • Adds bilateral() for feature-preserving raster smoothing. Weights neighbors by spatial distance and value similarity, so noise gets smoothed but edges stay sharp.
  • Four backends: NumPy (@ngjit), CuPy (@cuda.jit), Dask+NumPy, Dask+CuPy.
  • Boundary modes (nan, nearest, reflect, wrap) and 3D multi-band arrays.

Closes #969.

What changed

File Change
xrspatial/bilateral.py New module with bilateral filter
xrspatial/__init__.py Export bilateral
xrspatial/accessor.py .xrs.bilateral() on DataArray and Dataset
xrspatial/tests/test_bilateral.py 18 tests: correctness, edge cases, cross-backend, boundary modes
docs/source/reference/focal.rst API reference entry
examples/user_guide/17_Bilateral_Filter.ipynb User guide notebook
README.md Feature matrix row

Test plan

  • Flat surface unchanged
  • Sharp edges preserved with small sigma_range
  • Edges blurred with large sigma_range
  • NaN center pixels stay NaN, NaN neighbors skipped
  • All-NaN and single-cell rasters handled
  • Known-value correctness check
  • Symmetry preserved
  • Input validation rejects bad arguments
  • NumPy, Dask+NumPy, CuPy, Dask+CuPy backends match
  • Four boundary modes produce correct output
  • 3D multi-band arrays processed per-band
  • Accessor works

@brendancol brendancol added enhancement New feature or request focal tools Focal statistics and hotspot analysis labels Mar 4, 2026
@github-actions github-actions bot added the performance PR touches performance-sensitive code label Mar 4, 2026
@brendancol brendancol merged commit ec31dc6 into master Mar 5, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request focal tools Focal statistics and hotspot analysis performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add bilateral filtering for feature-preserving smoothing

1 participant