sparrow.im.min_max_filtering

sparrow.im.min_max_filtering#

sparrow.im.min_max_filtering(sdata, img_layer=None, size_min_max_filter=85, chunks=None, output_layer='min_max_filtered', crd=None, to_coordinate_system='global', scale_factors=None, overwrite=False)#

Apply min max filtering to an image in a SpatialData object using dask (using dask_image.ndfilters.maximum_filter and dask_image.ndfilters.minimum_filter).

The size of the filter can be provided either as an integer or a list of integers corresponding to each channel. Compatibility with image layers that have either two or three spatial dimensions.

Parameters:
  • sdata (SpatialData) – Spatial data object containing the images to be processed.

  • img_layer (Optional[str] (default: None)) – The image layer in sdata to run min_max_filtering on. If not provided, the last image layer in sdata is used.

  • size_min_max_filter (int | list[int] (default: 85)) – Size of the min_max filter. If provided as a list, the length must match the number of channels.

  • chunks (Union[str, tuple[int, ...], int, None] (default: None)) – Specification for rechunking the data before applying the function.

  • output_layer (str (default: 'min_max_filtered')) – The name of the output layer. Defaults to “min_max_filtered”.

  • crd (Optional[tuple[int, int, int, int]] (default: None)) – The coordinates specifying the region of the image to be processed. Defines the bounds (x_min, x_max, y_min, y_max).

  • to_coordinate_system (str (default: 'global')) – The coordinate system to which the crd is specified. Ignored if crd is None.

  • scale_factors (Optional[Sequence[Union[dict[str, int], int]]] (default: None)) – Scale factors to apply for multiscale.

  • overwrite (bool (default: False)) – If True overwrites the element if it already exists.

Return type:

SpatialData

Returns:

: The sdata object with the min max filtered image added.

Raises:

ValueError – If size_min_max_filter is a list and its length does not match the number of channels.

Examples

Apply min max filtering with a single size:

>>> sdata = min_max_filtering(sdata, size_min_max_filtering=50)

Apply min max filtering with different sizes for each channel:

>>> sdata = min_max_filtering(sdata, size_min_max_filtering=[30, 50, 70])