sparrow.im.combine

Contents

sparrow.im.combine#

sparrow.im.combine(sdata, img_layer, output_layer, nuc_channels=None, mem_channels=None, crd=None, scale_factors=None, overwrite=False)#

Combines specific channels within an image layer of a SpatialData object.

When given, nuc_channels are aggregated together, as are mem_channels.

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

  • img_layer (str) – The image layer in sdata to process.

  • output_layer (str) – The name of the output layer where results will be stored.

  • nuc_channels (Union[int, str, Iterable[int | str], None] (default: None)) – Specifies which channel(s) to consider as nuclear channels.

  • mem_channels (Union[int, str, Iterable[int | str], None] (default: None)) – Specifies which channel(s) to consider as membrane channels.

  • 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).

  • 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 output layer if it already exists in sdata.

Return type:

SpatialData

Returns:

: The sdata object with the combined image added to the specified output layer. If nuc_channels and mem_channels is not None, the nuc channels will be at position 0 and the mem channel at position 1.

Raises:
  • ValueError – If output_layer is not provided.

  • ValueError – If no channels are specified for combining.

  • ValueError – If provided arrays are not 2D or 3D (c, (z) , y, x).

Notes

The function combines specified channels from a SpatialData object’s image layer, creating a new image layer. The provided channels can be specified as nuclear or membrane channels. If coordinates (crd) are specified, only the region within those coordinates will be considered for the combination.

Examples

Sum nuclear channels 0 and 1, and keep membrane channel 2 as is from the image layer “raw_image”:

>>> sdata = combine(sdata, img_layer="raw_image", output_layer="combined_image", nuc_channels=[0,1], mem_channels=2)

Sum only nuclear channels 0 and 1:

>>> sdata = combine(sdata, img_layer="raw_image", output_layer="nuc_combined", nuc_channels=[0,1])