Add prescale parameter to "blob functions"#7858
Conversation
This makes heavy use of the scaling implementation that was proposed in [1]. Furthermore, `ski._shared.utils` seesm like a more fitting place. [1] https://www.github.com/scikit-image/scikit-image/pull/7697
prescale parameter to "blob functions"prescale function and similar parameter to "blob functions"
prescale function and similar parameter to "blob functions"prescale parameter to "blob functions"
matthew-brett
left a comment
There was a problem hiding this comment.
A few comments in passing.
I'm wondering about the divide by two heuristic. Will that always work?
Co-authored-by: Matthew Brett <matthew.brett@gmail.com>
As pointed out by @stefanv, substraction with small floats can be problematic – so do that before division by peak_to_peak. Also handle NaNs and Infs in input value range explicitly. Cover everything with tests.
That keyword is new in version 2 which isn't our minimal dependency yet. However, going forward `strict=True` should probably be the default at some point. It avoids unepexted suprises.
We are not sure yet if it is worth supporting and committing to this option. We can always add it later if it is requested.
We are not really clear what behavior would be expected for NaN and inf values. So instead, it's easier to just raise a ValueError for now, encouraging users to handle this manually.
`_prescale_value_range` is really more of a helper function that ties our old legacy scaling behavior and the new min-max scaling together. It is meant as a convenience function to use in a few places where our API needs to work with a well-behaved output range. We very probably don't want to the slightly awkward API of `_prescale_value_range` public. Instead, if we want to later make something public. It's probably something closer to a fresh API like `_minmax_scale_value_range`.
stefanv
left a comment
There was a problem hiding this comment.
Some minor outstanding comments to address, but I'd say go ahead, fix what you can and merge.
|
|
||
| See Also | ||
| -------- | ||
| _rescale_value_range |
There was a problem hiding this comment.
| _rescale_value_range | |
| _rescale |
There was a problem hiding this comment.
Undecided if I want to take you up on this suggestion. I don't think it hurts at all to have _value_range in there to make it clear what is scaled?
But for now, I'll take you up on it and postpone the naming discussion for if we decide to make this function public.
There was a problem hiding this comment.
Actually, scratch that. I propose to leave this more specific name for now to help differentiate it from:
rescaleinskimage.transformrescale_intensityinskimage.exposure_rescale_sigma_rgb2ycbcrinskimage.restoration
There was a problem hiding this comment.
I'm also in favor of keeping the more specific name _rescale_value_range.
Co-authored-by: Marianne Corvellec <marianne.corvellec@ens-lyon.org> Co-authored-by: Stefan van der Walt <stefan@mentat.za.net>
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
src/skimage/_shared/utils.py (1)
1279-1281: Consider returning the input directly formode="none".Currently
mode="none"returnsimage.copy(). If the intent is truly "do nothing," returning the original array without copying could be more efficient. However, if the copy is intentional to prevent mutation of the input, this is fine.
| internally computed stack of Difference-of-Gaussian (DoG) images. This | ||
| in turn affects the effect of the `threshold` parameter. | ||
|
|
||
| ``'minmax'`` |
There was a problem hiding this comment.
Test is OK, but I think simplest is just to make the scaling function public API and refer to it. Future PR is fine.
| fe.params | ||
|
|
||
|
|
||
| class Test_minmax_scale_value_range: |
There was a problem hiding this comment.
| class Test_minmax_scale_value_range: | |
| class TestMinmaxScaleValueRange: |
There was a problem hiding this comment.
Personally, I think the better "grep-ability" is totally worth breaking the camelCase convention here. But I don't care enough to block it, and since you both are in favor... 🤷
There was a problem hiding this comment.
Actually, the rest of that module already uses snake case in class names. So leaving it for now for local consistency. But I'll open a thread on Zulip where I propose that for skimage2 as a convention. Otherwise I'm happy to clean that up in our code base.
|
Approved, feel free to merge when ready. |
| Rescaling values between [0, 1], or *min-max normalization* [1]_, | ||
| is a simple method to ensure that data is inside a range. |
There was a problem hiding this comment.
| Rescaling values between [0, 1], or *min-max normalization* [1]_, | |
| is a simple method to ensure that data is inside a range. | |
| Rescaling or *min-max normalization* [1]_ | |
| is a simple method to ensure that all data values lie in a certain range. |
(based on cited reference https://en.wikipedia.org/wiki/Feature_scaling#Rescaling_(min-max_normalization))
Was applied in other cases, so apply here too.
Co-authored-by: Marianne Corvellec <marianne.corvellec@ens-lyon.org>
|
Merging if the CI stays green. 🤞 |
* origin/main: (27 commits) Move `_shared` to `_skimage2` (#8102) Port `pad_footprint` & `mirror_footprint` to `skimage2` (#8094) Add rescaling API to skimage2 (#8075) Move `skimage2` implementation into `_skimage2` (#8093) Undo (double) mirroring in `ski2.morphology.dilation` (#8060) Grammar (#8091) Move `ensure_spacing` into `skimage2` (#8067) Ensure that `skimage2` does not eagerly import `skimage` (#8087) Use lazy-loader 0.5 (#8080) MAINT: make ellipse fitting forward compatible (#8054) Avoid deprecated assign to ndarray.shape (#8020) Avoid circular import in `feature/corner.py` (#8077) Turn off coderabbit auto-labeling & label checks (#8070) Fix GIL being re-enabled by C++ extensions (#8059) Fix conventions following docstub and misc. (#8055) Port grayscale morphology operators to skimage2 (#8046) Add revised `peak_local_max` to `skimage2` (#8039) Allow read-only arrays as input to remap (#7535) Add `prescale` parameter to "blob functions" (#7858) Try to make coderabbit respect exisiting type labels (#8042) ...
Description
Implementation of the new strategy around value range scaling in our library that we extensively discussed in the recent sprint and meeting. We will add more detailed descriptions of this strategy but in short:
prescaleparameter for functions that actually need / benefit from prescaling the input image.Checklist
./doc/examplesfor new featuresRelease note
For maintainers and optionally contributors, please refer to the instructions on how to document this PR for the release notes.