Skip to content

Add rescaling API to skimage2 - #8075

Merged
lagru merged 13 commits into
scikit-image:mainfrom
lagru:sk2-rescale
Mar 19, 2026
Merged

lagru merged 13 commits into
scikit-image:mainfrom
lagru:sk2-rescale

Conversation

@lagru

@lagru lagru commented Mar 2, 2026

Copy link
Copy Markdown
Member

Description

This PR ports the current implementation of _rescale_value_range and _minmax_scale_value_range to skimage2. We want this functionality early so that we can craft nice migration advice for function that use preserve_range or the new prescale API.

Currently this is a draft. I kept _rescale_value_range internal, and exposed both modes as the new functions minmax_rescale and legacy_rescale. Somehow I feel that this is is simpler in multiple ways than keeping them in the same do-everything function. Especially, if we decide to add more rescaling modes that might need additional parameters, I think keeping separate function is clearly the better call – remember the discussion around enabling batched scaling with something like prescale=("minmax", 10, 100).

But I'm totally happy to hear and open to other suggestions.

Checklist

Release note

For maintainers and optionally contributors, please refer to the instructions on how to document this PR for the release notes.

...

@lagru lagru added 🔧 type: Maintenance Refactoring and maintenance of internals 🥾 Path to skimage2 A step towards the new "API 2.0" labels Mar 2, 2026
@lagru
lagru marked this pull request as draft March 2, 2026 20:06
@lagru
lagru marked this pull request as ready for review March 11, 2026 17:20
@lagru lagru moved this to Doing in Work pitches Mar 12, 2026
@lagru lagru self-assigned this Mar 12, 2026
@lagru lagru moved this from Doing to Needs review in Work pitches Mar 12, 2026
@lagru lagru mentioned this pull request Mar 12, 2026
1 task done

@stefanv stefanv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM; we just need to fix the names. Left some minor docstring comments too.

Comment thread src/skimage2/util/__init__.pyi Resolved
Comment thread src/skimage2/util/_value_rescaling.py Resolved
Comment thread src/skimage2/util/_value_rescaling.py Resolved
@stefanv stefanv moved this from Review to Doing in Work pitches Mar 13, 2026
lagru and others added 5 commits March 13, 2026 23:33
If we ever change this, we don't risk forgetting both places.
This is fine according to our recently proposed import hierarchy.
Co-authored-by: Stefan van der Walt <[email protected]>
@lagru lagru moved this from Doing to Review in Work pitches Mar 13, 2026
@lagru
lagru requested a review from stefanv March 13, 2026 23:02
import numpy as np


def rescale_minmax(image):

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we try upstreaming this function to NumPy (or SciPy)? Might be to "trivial" but the handling of overflow errors might make it worth it? And convenience functions still have their place...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth it, but I suspect the (0, 1) range is too specific. My guess is that it might be attractive if we had a range parameter with desired min and max.

Comment thread src/_skimage2/util/_value_rescaling.py Resolved
Comment thread src/_skimage2/util/_value_rescaling.py Resolved
Comment thread src/_skimage2/util/_value_rescaling.py Resolved
@stefanv stefanv moved this from Review to Doing in Work pitches Mar 19, 2026
@lagru
lagru merged commit 16df38b into scikit-image:main Mar 19, 2026
21 checks passed
@github-project-automation github-project-automation Bot moved this from Doing to Done in Work pitches Mar 19, 2026
@stefanv stefanv added this to the 0.27 milestone Mar 19, 2026
@lagru
lagru deleted the sk2-rescale branch March 19, 2026 11:18
matthew-brett added a commit that referenced this pull request Apr 10, 2026
* 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)
  ...
lagru added a commit that referenced this pull request May 21, 2026
Previously, `gaussian` lived in `skimage/_shared/` to avoid import circles. Now that
lazy loading is established, I don't think that's a problem any more. So I've put it
back in `skimage2/filters/`. If it becomes one, it's easy enough to move the function back to `_shared`.

In our discussion around `preserve_range`, we agreed to drop this keyword. We aim to
use `prescale` where the algorithm needs to know about the value range, elsewhere we
just explain users how to recover legacy behavior. 

Also, we need to expose `_rescale_value_range(..., mode="legacy")` in `skimage2` to
enable users to recover the legacy behavior. I propose to do that in another PR and
have marked this one as _Draft_ for now. See
#8075
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🥾 Path to skimage2 A step towards the new "API 2.0" 🔧 type: Maintenance Refactoring and maintenance of internals

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants