squidpy.im.ImageContainer.crop_corner

ImageContainer.crop_corner(y, x, size=None, library_id=None, scale=1.0, cval=0, mask_circle=False, preserve_dtypes=True)[source]

Extract a crop from the upper-left corner.

Parameters:
  • y (Union[int, float]) – Coordinate of the crop along the height dimension in the pixel space. If a float, it specifies the relative position and must be in [0, 1].

  • x (Union[int, float]) – Coordinate of the crop along the width dimension in the pixel space. If a float, it specifies the relative position and must be in [0, 1].

  • size (Union[int, float, tuple[Union[int, float], Union[int, float]], None]) – Size of the crop as (height, width). If a single int, the crop will be a square.

  • library_id (Optional[str]) – Name of the Z-dimension to be cropped. If None, all Z-dimensions are cropped.

  • scale (float) – Rescale the crop using skimage.transform.rescale().

  • cval (int | float) – Fill value to use if mask_circle = True or if crop goes out of the image boundary.

  • mask_circle (bool) – Whether to mask out values that are not within a circle defined by this crop. Only available if size defines a square.

  • preserve_dtypes (bool) – Whether to preserver the data types of underlying xarray.DataArray, even if cval is of different type.

Return type:

ImageContainer

Returns:

: The cropped image of size size * scale.

Raises:

ValueError – If the crop would completely lie outside of the image or if mask_circle = True and size does not define a square.

Notes

If preserve_dtypes = True but cval cannot be safely cast, cval will be set to 0.