sparrow.im.tiling_correction

sparrow.im.tiling_correction#

sparrow.im.tiling_correction(sdata, img_layer=None, tile_size=2144, crd=None, to_coordinate_system='global', scale_factors=None, output_layer='tiling_correction', overwrite=False)#

Function corrects for the tiling effect that occurs in some image data (e.g. resolve data).

The illumination within the tiles is adjusted, afterwards the tiles are connected as a whole image by inpainting the lines between the tiles.

Parameters:
  • sdata (SpatialData) – The SpatialData object containing the image data to correct.

  • img_layer (Optional[str] (default: None)) – The image layer in sdata to be corrected for tiling effects. If not provided, the last image layer in sdata is used.

  • tile_size (int (default: 2144)) – The size of the tiles in the image.

  • crd (Optional[Tuple[int, int, int, int]] (default: None)) – Coordinates defining the region of the image to correct. It 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. If a crd is specified, only the coordinate system defined here will be kept in output_layer.

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

  • output_layer (str (default: 'tiling_correction')) – Name of the image layer where the corrected image will be stored in the sdata object.

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

Return type:

Tuple[SpatialData, List[ndarray]]

Returns:

: Updated sdata object containing the corrected image and a list of flatfield arrays with length equal to the number of channels.

Raises:
  • ValueError – If the image layer does not contain exactly 2 spatial dimensions.

  • ValueError – If the dimensions of the image layer are not multiples of the given tile size.

Notes

The function integrates the BaSiC algorithm for illumination correction and uses OpenCV’s inpainting to stitch tiles together. It manages the pre- and post-processing of data, translation of coordinates, and addition of corrected image results back to the sdata object.