Skip to content

Commit b3b128c

Browse files
lagrustefanv
andauthored
Add revised peak_local_max to skimage2 (scikit-image#8039)
Adds the function `peak_local_max` to the `skimage2` namespace. Compared to the old version in `skimage` it has a few differences: * Parameter `p_norm` defaults to 2 (Euclidean distance), was `numpy.inf` (Chebyshev distance) * Parameter `exclude_border` defaults to 1, was `True` * Parameter `exclude_border` no longer accepts `False` and `True`, pass 0 instead of `False`, or `min_distance` instead of `True` * Parameters after `image` are keyword-only Deprecates passing `np.inf` to `num_peaks` and `num_peaks_per_label`. In `skimage.feature.peak_local_max`, support passing floats to the parameter `min_distance`. In `skimage.feature.peak_local_max`, use `None` as the new default for the parameters `num_peaks` and `num_peaks_per_label` – the default behavior is the same as before but passing `numpy.inf` is deprecated. Ensure `skimage.feature.peak_local_max` returns results with the correct shape when no peaks where found and `labels` where given. --------- Co-authored-by: Stefan van der Walt <stefan@mentat.za.net>
1 parent 70ab2a6 commit b3b128c

File tree

12 files changed

+584
-210
lines changed

12 files changed

+584
-210
lines changed

doc/source/user_guide/skimage2_migration.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,57 @@ ski2.data.binary_blobs(
6565
with `length`, `n_dim`, and `blob_size_fraction` containing values used with the old signature.
6666
Other parameters -- including `boundary_mode` if you already set it explicitly -- can be left unchanged.
6767

68+
### `skimage.feature.peak_local_max`
69+
70+
This function is replaced by `skimage2.feature.peak_local_max` with new behavior:
71+
72+
- Parameter `p_norm` defaults to 2 (Euclidean distance), was `numpy.inf` (Chebyshev distance)
73+
- Parameter `exclude_border` defaults to 1, was `True`
74+
- Parameter `exclude_border` no longer accepts `False` and `True`, pass 0 instead of `False`, or `min_distance` instead of `True`
75+
- Parameters after `image` are keyword-only
76+
77+
To keep the old behavior when switching to `skimage2`, update your call according to the following cases:
78+
79+
:::{list-table}
80+
:header-rows: 1
81+
82+
- - In `skimage`
83+
- In `skimage2`
84+
85+
- - `exclude_border` not passed (default)
86+
- Assign it the same value as `min_distance` which may be its default value `1`.
87+
88+
- - `exclude_border=True`
89+
- Same as above in the default case.
90+
91+
- - `exclude_border=False`
92+
- Use `min_distance=0`.
93+
94+
- - `exclude_border=<int>`
95+
- No change necessary.
96+
97+
- - `p_norm` not passed (default)
98+
- Pass the previous default explicitly with `p_norm=numpy.inf`.
99+
100+
- - `p_norm=<float>`
101+
- No change necessary.
102+
103+
:::
104+
105+
Other keyword parameters can be left unchanged.
106+
107+
Examples:
108+
109+
```python
110+
ski.morphology.peak_local_max(image)
111+
ski2.morphology.peak_local_max(image, exclude_border=1, p_norm=np.inf)
112+
113+
ski.morphology.peak_local_max(image, min_distance=10)
114+
ski2.morphology.peak_local_max(
115+
image, min_distance=10, exclude_border=10, p_norm=np.inf
116+
)
117+
```
118+
68119
## Deprecations prior to skimage2
69120

70121
We have already introduced a number of changes and deprecations to our API.

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ addopts = [
195195
"--strict-config",
196196
"--strict-markers",
197197
"--maxfail=5",
198-
# Necessary for doctest collection with editable installations
198+
# Necessary for doctest collection with editable installations and
199+
# non-unique test module names (skimage/skimage2 duplicates those)
199200
"--import-mode=importlib",
200201
# See comment on `testpaths`
201202
"--pyargs",

src/skimage/feature/corner.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,8 @@ def corner_peaks(
12011201
"""
12021202
if np.isinf(num_peaks):
12031203
num_peaks = None
1204+
if np.isinf(num_peaks_per_label):
1205+
num_peaks_per_label = None
12041206

12051207
# Get the coordinates of the detected peaks
12061208
coords = peak_local_max(
@@ -1209,7 +1211,7 @@ def corner_peaks(
12091211
threshold_abs=threshold_abs,
12101212
threshold_rel=threshold_rel,
12111213
exclude_border=exclude_border,
1212-
num_peaks=np.inf,
1214+
num_peaks=None, # Limiting to `num_peaks` is done in this function
12131215
footprint=footprint,
12141216
labels=labels,
12151217
num_peaks_per_label=num_peaks_per_label,

0 commit comments

Comments
 (0)