Exclude centre cell from morph_erode/dilate when kernel[centre]==0 (#1397)#1398
Merged
brendancol merged 1 commit intomainfrom May 1, 2026
Merged
Exclude centre cell from morph_erode/dilate when kernel[centre]==0 (#1397)#1398brendancol merged 1 commit intomainfrom
brendancol merged 1 commit intomainfrom
Conversation
…1397) The numpy and CUDA kernel functions seeded the running min/max from the centre cell before iterating the structuring element. When the kernel had a 0 at the centre, the loop skipped the centre cell but the seed value already came from it, so the centre still contaminated the result. Fix: drop the centre seed and assign from the first kernel-included neighbour, then compare against subsequent ones. NaN propagation now only fires when a NaN neighbour is actually included by the kernel. Cells where the kernel covers no non-zero entries return NaN. Affects all four backends (numpy, cupy, dask+numpy, dask+cupy).
1 task
brendancol
added a commit
that referenced
this pull request
May 1, 2026
…1401) Three modules audited 2026-04-30. - fire: clean (per-pixel ops only; NaN guards via x!=x; CUDA bounds use strict <; division guarded; CPU/GPU/dask paths line-for-line equivalent; no CRIT/HIGH/MEDIUM). - terrain_metrics: LOW only (Inf input not rejected, propagates; dask+cupy non-nan boundary path double-pads with consistent output). - morphology: HIGH x 2 fixed. - #1397 / PR #1398: morph_erode/dilate seeded centre cell into the running min/max even when kernel[centre]==0, contaminating the result with the excluded pixel (all four backends). - #1399 / PR #1400: _morph_chunk_numpy and _morph_chunk_cupy used result[hy:-hy, hx:-hx] which becomes the empty slice 0:-0 for 1xN or Nx1 kernels, raising ValueError on the dask backends while numpy and cupy paths handled them.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
morph_erodeandmorph_dilatewhen the structuring element has a 0 at the centre. Previously the running min/max was seeded from the centre cell before the kernel loop, so the centre still influenced the result even when the kernel excluded it._erode_kernel_numpy,_dilate_kernel_numpy,_erode_gpu,_dilate_gpu.Fixes #1397.
Test plan
pytest xrspatial/tests/test_morphology.py xrspatial/tests/test_morphology_derived.pypasses (70 tests)