ImageContainer.crop_corner

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 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 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 int | float | tuple[int | float, int | float] | None (default: None)

Size of the crop as (height, width). If a single int, the crop will be a square.

library_id str | None (default: None)

Name of the Z-dimension to be cropped. If None, all Z-dimensions are cropped.

scale float (default: 1.0)

Rescale the crop using skimage.transform.rescale().

cval int | float (default: 0)

Fill value to use if mask_circle = True or if crop goes out of the image boundary.

mask_circle bool (default: False)

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 (default: True)

Whether to preserver the data types of underlying xarray.DataArray, even if cval is of different type.

Returns:

ImageContainer – 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.