harpy.im.combine#
- harpy.im.combine(sdata, image_name, output_image_name, nuc_channels=None, mem_channels=None, crd=None, scale_factors=None, overwrite=False)#
Combines specific channels within an image element of a SpatialData object.
When given,
nuc_channelsare aggregated together, as aremem_channels.- Parameters:
sdata (
SpatialData) – Spatial data object containing the image to be combined.image_name (
str) – The image element insdatato process.output_image_name (
str) – The name of the output element where results will be stored.nuc_channels (
int|str|Iterable[int|str] |None(default:None)) – Specifies which channel(s) to consider as nuclear channels.mem_channels (
int|str|Iterable[int|str] |None(default:None)) – Specifies which channel(s) to consider as membrane channels.crd (
tuple[int,int,int,int] |None(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 (
Sequence[dict[str,int] |int] |None(default:None)) – Scale factors to apply for multiscale.overwrite (
bool(default:False)) – If True, overwrites the output element if it already exists insdata.
- Return type:
- Returns:
: The
sdataobject with the combined image added to the specified output element. Ifnuc_channelsandmem_channelsis not None, the nuc channels will be at position 0 and the mem channel at position 1.- Raises:
ValueError – If
output_image_nameis 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 element, creating a new image element. 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 element “raw_image”:
>>> sdata = combine(sdata, image_name="raw_image", output_image_name="combined_image", nuc_channels=[0,1], mem_channels=2)
Sum only nuclear channels 0 and 1:
>>> sdata = combine(sdata, image_name="raw_image", output_image_name="nuc_combined", nuc_channels=[0,1])