harpy.im.normalize#
- harpy.im.normalize(sdata, image_name, output_image_name, p_min=5.0, p_max=95.0, eps=1e-20, internal_method='tdigest', scale_factors=None, overwrite=False)#
Normalize the intensity of an image element in a SpatialData object using specified percentiles.
The normalization can be applied globally or individually to each channel, depending on whether
p_minandp_maxare provided as single values or as lists. This allows for flexible intensity scaling across multiple channels.- Parameters:
sdata (
SpatialData) – SpatialData object.image_name (
str) – The image element insdatato normalize.output_image_name (
str) – The name of the output element where the normalized image will be stored.p_min (
float|list[float] (default:5.0)) – The lower percentile for normalization. If provided as a list, the length must match the number of channels.p_max (
float|list[float] (default:95.0)) – The upper percentile for normalization. If provided as a list, the length must match the number of channels.eps (float, optional) – A small epsilon value added to the denominator to avoid division by zero. Default is 1e-20.
internal_method (str, optional) – The method dask uses for computing percentiles. Default is “tdigest”. Can be “dask” or “tdigest”.
scale_factors (
Sequence[dict[str,int] |int] |None(default:None)) – Scale factors to apply for multiscale.overwrite (
bool(default:False)) – If True, overwrites the element if it already exists.
- Return type:
- Returns:
: The
sdataobject with the normalized image added.- Raises:
ValueError – If
p_minandp_maxare provided as lists and their lengths do not match the number of channels.
Examples
Normalize using a single percentile range for all channels:
>>> sdata = normalize(sdata, image_name='my_image', output_image_name='normalized_image', p_min=5, p_max=95)
Normalize using different percentile ranges for each channel:
>>> sdata = normalize(sdata, image_name='my_image', output_image_name='normalized_image', p_min=[5, 10, 15], p_max=[95, 90, 85])