sparrow.im.gaussian_filtering

sparrow.im.gaussian_filtering#

sparrow.im.gaussian_filtering(sdata, img_layer=None, sigma=6, chunks=None, output_layer='gaussian_filtered', crd=None, to_coordinate_system='global', scale_factors=None, overwrite=False)#

Apply Gaussian filtering to an image in a SpatialData object using dask.

The sigma value 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. See scipy.ndimage.filters.gaussian_filter for more info

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.

  • sigma (int | list[int] (default: 6)) – Standard deviation for Gaussian kernel. 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: 'gaussian_filtered')) – The name of the output layer. Defaults to “gaussian_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) – If True overwrites the element if it already exists.

Return type:

SpatialData

Returns:

: The sdata object with the Gaussian filtered image added.

Raises:

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

Examples

Apply Gaussian filtering with a single sigma for all channels:

>>> sdata = gaussian_filtering(sdata, sigma=8)

Apply gaussian filtering with different sigmas for each channel:

>>> sdata = min_max_filtering(sdata, sigma=[6, 0, 4])

Set sigma to zero to copy the channel (i.e. no Gaussian filter).