bundles / scipy 1.17.1 / scipy / ndimage / _measurements / find_objects
function
scipy.ndimage._measurements:find_objects
Signature
def find_objects ( input , max_label = 0 ) Summary
Find objects in a labeled array.
Parameters
input: ndarray of intsArray containing objects defined by different labels. Labels with value 0 are ignored.
max_label: int, optionalMaximum label to be searched for in
input. If max_label is not given, the positions of all objects are returned.
Returns
object_slices: list of tuplesA list of tuples, with each tuple containing N slices (with N the dimension of the input array). Slices correspond to the minimal parallelepiped that contains the object. If a number is missing, None is returned instead of a slice. The label
lcorresponds to the indexl-1in the returned list.
Notes
This function is very useful for isolating a volume of interest inside a 3-D array, that cannot be "seen through".
Array API Standard Support
find_objects has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.
==================== ==================== ==================== Library CPU GPU ==================== ==================== ==================== NumPy ✅ n/a CuPy n/a ⛔ PyTorch ✅ ⛔ JAX ⚠️ no JIT ⛔ Dask ⚠️ computes graph n/a ==================== ==================== ====================
See
dev-arrayapifor more information.
Examples
from scipy import ndimage import numpy as np a = np.zeros((6,6), dtype=int) a[2:4, 2:4] = 1 a[4, 4] = 1 a[:2, :3] = 2 a[0, 5] = 3 a✓
ndimage.find_objects(a)
✗ndimage.find_objects(a, max_label=2) ndimage.find_objects(a == 1, max_label=2)✓
loc = ndimage.find_objects(a)[0] a[loc]✓
See also
Aliases
-
scipy.ndimage.find_objects