22
33import numpy as np
44import functools
5- import warnings
65from scipy import ndimage as ndi
76from scipy .spatial import cKDTree
87
@@ -67,7 +66,7 @@ def _check_dtype_supported(ar):
6766 "its value, while the previous parameter only removed smaller ones." ,
6867)
6968def remove_small_objects (
70- ar , min_size = DEPRECATED , connectivity = 1 , * , max_size = 64 , out = None
69+ ar , min_size = DEPRECATED , connectivity = 1 , * , max_size = 63 , out = None
7170):
7271 """Remove objects smaller than the specified size.
7372
@@ -81,7 +80,7 @@ def remove_small_objects(
8180 ar : ndarray (arbitrary shape, int or bool type)
8281 The array containing the objects of interest. If the array type is
8382 int, the ints must be non-negative.
84- max_size : int, optional (default: 64)
83+ max_size : int, optional
8584 Remove objects whose contiguous area (or volume, in N-D) contains this
8685 number of pixels or fewer.
8786
@@ -167,12 +166,12 @@ def remove_small_objects(
167166 "Did you mean to use a boolean array?"
168167 )
169168
170- if min_size is not DEPRECATED :
171- # Exclusive threshold is deprecated behavior
172- too_small = component_sizes < min_size
173- else :
174- # New behavior uses inclusive threshold
175- too_small = component_sizes <= max_size
169+ if min_size is deprecate_parameter . DEPRECATED_GOT_VALUE :
170+ # Old parameter with exclusive threshold (< instead of <=) was used and
171+ # forwarded to `max_size`, correct for this
172+ max_size -= 1
173+
174+ too_small = component_sizes <= max_size
176175 too_small_mask = too_small [ccs ]
177176 out [too_small_mask ] = 0
178177
@@ -189,15 +188,15 @@ def remove_small_objects(
189188 "its value, while the previous parameter only removed smaller ones." ,
190189)
191190def remove_small_holes (
192- ar , area_threshold = DEPRECATED , connectivity = 1 , * , max_size = 64 , out = None
191+ ar , area_threshold = DEPRECATED , connectivity = 1 , * , max_size = 63 , out = None
193192):
194193 """Remove contiguous holes smaller than the specified size.
195194
196195 Parameters
197196 ----------
198197 ar : ndarray (arbitrary shape, int or bool type)
199198 The array containing the connected components of interest.
200- max_size : int, optional (default: 64)
199+ max_size : int, optional
201200 Remove holes whose contiguous area (or volume, in N-D) contains this
202201 number of pixels or fewer.
203202
@@ -278,20 +277,18 @@ def remove_small_holes(
278277 # Creating the inverse of ar
279278 np .logical_not (ar , out = out )
280279
280+ if area_threshold is deprecate_parameter .DEPRECATED_GOT_VALUE :
281+ # Old parameter with exclusive threshold (< instead of <=) was used and
282+ # forwarded to `max_size`, correct for this
283+ max_size -= 1
284+
281285 # removing small objects from the inverse of ar
282- with warnings .catch_warnings ():
283- warnings .filterwarnings (
284- "ignore" ,
285- message = "Parameter `min_size` is deprecated" ,
286- category = FutureWarning ,
287- )
288- out = remove_small_objects (
289- out ,
290- min_size = area_threshold ,
291- max_size = max_size ,
292- connectivity = connectivity ,
293- out = out ,
294- )
286+ out = remove_small_objects (
287+ out ,
288+ max_size = max_size ,
289+ connectivity = connectivity ,
290+ out = out ,
291+ )
295292
296293 np .logical_not (out , out = out )
297294
0 commit comments