Skip to content

Add skimage2 version of binary_blobs with updated signature#7976

Merged
lagru merged 41 commits intoscikit-image:mainfrom
lagru:sk2-binary-blobs
Jan 30, 2026
Merged

Add skimage2 version of binary_blobs with updated signature#7976
lagru merged 41 commits intoscikit-image:mainfrom
lagru:sk2-binary-blobs

Conversation

@lagru
Copy link
Copy Markdown
Member

@lagru lagru commented Dec 2, 2025

Description

Closes #7945. This replaces the old length and n_dim arguments with a single shape argument. This allows generating images with varying dimension lengths.

  • Still need to document this in the migration guide.
  • And this also needs appropriate warnings that we can eventually make visible.

Checklist

Release note

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

Add `skimage2.data.binary_blobs` with improved signature compared to the old
version in `skimage.data`. The old version is now a simple wrapper around the
implementation in `skimage2`.
Add `skimage._shared._warnings.warn_external` which automatically sets the correct
stacklevel for warnings.

This replaces the old `length` and `n_dim` arguments with a single
`shape` argument. This allows generating images with varying dimension
lengths.
@lagru lagru added ⏩ type: Enhancement Improve existing features 🥾 Path to skimage2 A step towards the new "API 2.0" labels Dec 2, 2025
lagru added 2 commits December 8, 2025 21:36
This avoids problems due to different stack depths between the skimage
and skimage2 API. We'd have to set a different `stacklevel` depending
for skimage2 and skimage.
@lagru lagru marked this pull request as ready for review December 8, 2025 20:41
Co-authored-by: Stefan van der Walt <sjvdwalt@gmail.com>
The previous regex would never match because the "__name__" might not
be just "skimage" or "skimage2". The new regex also matches
"skimage.something".
Might avoid a potentially endless loop if there's an error in the
breaking logic of the loop
lagru added a commit that referenced this pull request Dec 31, 2025
I think in practice this file is changed far to often for unrelated
reasons. Thus resulting in a significant waste of resources (for example
#7889 or
#7976). We are
periodically building and testing wheels for our nightlies. So we should
still catch stuff early. And if necessary there's always the option to
use a `maintenance/*` branch.
Copy link
Copy Markdown
Member

@stefanv stefanv left a comment

Choose a reason for hiding this comment

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

I don't understand the blob_size_fraction argument; otherwise all seems well to me. Some minor tweaks required to LICENSE files.

@lagru
Copy link
Copy Markdown
Member Author

lagru commented Jan 29, 2026

Should we add a grayscale blobs function, and have binary blobs just call grayscale and threshold?

@jni

Sounds useful. Probably not a priority right now but you should create an issue so we don't forget. 😊

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/skimage2/data/_synthetic.py`:
- Around line 108-109: Validate the volume_fraction argument before calling
np.quantile: check that volume_fraction is a numeric scalar and 0 <=
volume_fraction <= 1, and if not raise a ValueError with a clear message
referencing the parameter (e.g. "volume_fraction must be between 0 and 1, got
{value}"). Add this check immediately before the lines computing threshold =
np.quantile(mask, 1 - volume_fraction) / blobs = mask >= threshold so
out-of-range inputs produce a user-friendly error.

@coderabbitai coderabbitai bot added the 📜 type: API Involves API change(s) label Jan 29, 2026
@lagru lagru removed the 📜 type: API Involves API change(s) label Jan 29, 2026
Copy link
Copy Markdown
Member

@mkcor mkcor left a comment

Choose a reason for hiding this comment

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

Thanks for iterating with me, @lagru!

So ski2 it is, perfect!

Thanks for clarifying what the 'API boundary' meant; I get it now. I'm not familiar with the term 'frame' in this context though: Isn't it 'block' as in 'code block?' Or 'code unit?'

I left only minor (wording) suggestions, so I'll go ahead and commit them.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/skimage/_shared/_warnings.py (1)

160-166: Consider documenting category as optional with its default value.

The numpydoc format typically includes "optional" and the default value for keyword arguments with defaults.

✍️ Proposed docstring update
     Parameters
     ----------
     message : str
         Warning message.
-    category : type[Warning]
+    category : type[Warning], optional
         The class used in the warning.
+        Default is ``None``, which emits a ``UserWarning``.
     """

As per coding guidelines, all code should be documented using the NumPy/SciPy docstring standard (numpydoc format).

Copy link
Copy Markdown
Member

@mkcor mkcor left a comment

Choose a reason for hiding this comment

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

If CI is green and I don't hear anything, I'll merge in ~6 hours, because it's currently holding #7858 back. @lagru feel free to merge earlier if you see fit.

lagru and others added 4 commits January 30, 2026 13:54
Co-authored-by: Marianne Corvellec <marianne.corvellec@ens-lyon.org>
Co-authored-by: Marianne Corvellec <marianne.corvellec@ens-lyon.org>
@lagru lagru merged commit 02693c8 into scikit-image:main Jan 30, 2026
26 of 27 checks passed
@stefanv stefanv added this to the 0.27 milestone Jan 30, 2026
@lagru lagru deleted the sk2-binary-blobs branch January 30, 2026 13:54
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

None yet

Development

Successfully merging this pull request may close these issues.

Reconsider signature of binary_blobs

6 participants