Document where the filters differ from scipy.ndimage. - #36
Merged
Conversation
The note added in #34 had the comparison backwards. For an even footprint `scipy.ndimage.median_filter()` returns the larger of the two middle elements, not the smaller, because it is implemented as a rank filter that selects the element of rank `size // 2`. Say why, too: selecting an element of the footprint is what lets SciPy return a result in the dtype of the input. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #36 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 14 14
Lines 677 677
=========================================
Hits 677 677
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The README and the documentation landing page both claim the filters are similar to those in `scipy.ndimage`, and then list only the ways this library does more. Add the other half: the boundary modes that are not supported, the promotion of integer input, and the tie-breaking convention for an even-sized median footprint. The docstring note that #36 corrects is only read by someone who already suspects a difference. A migrating user reads the landing page. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
scipy.ndimage.
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.
Two documentation changes; no behavior change.
Correct the note on even-sized median footprints
The note added in #34 had the comparison backwards. For a footprint with an
even number of elements,
scipy.ndimage.median_filter()returns thelarger of the two middle elements, not the smaller, because it delegates
to
_rank_filter()and asks for the element of ranksize // 2:where averaging each pair, as
numpy.median()and this package do, gives[0., 5., 15., 25., 35.]. Selecting rather than averaging is what letsSciPy return a result in the dtype of the input.
Add a "Differences from
scipy.ndimage" sectionThe README and the documentation landing page both open by saying the
filters are similar to those in
scipy.ndimage, and then list only the waysthis library does more. That sets up a migrating user to be surprised, and a
Notesblock on one function is only read by someone who already suspects adifference. The new section covers the other half:
"reflect","constant", and the"grid-*"modesraise a
ValueErrorhere;"truncate"has no SciPy equivalent.input dtype, which is what allows a fully-excluded
wherefootprint toreturn
NaN(Fix the "mirror" boundary mode and validatemodeandsize. #32).including that SciPy's convention is a biased estimator: on unit-variance
noise a
size=2median filter shifts the signal by roughly 0.57, whilethe two conventions agree exactly for odd-sized footprints.
The section states the tradeoff in both directions rather than only ours:
SciPy's rank selection never introduces a value that was not already in the
footprint, which averaging does (a 4-level image filtered at
size=4comesback with 7 levels).
🤖 Generated with Claude Code