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 theheight
dimension in the pixel space. If afloat
, it specifies the relative position and must be in [0, 1].x (
Union
[int
,float
]) – Coordinate of the crop along thewidth
dimension in the pixel space. If afloat
, 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 singleint
, 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 usingskimage.transform.rescale()
.cval (
Union
[int
,float
]) – Fill value to use ifmask_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 ifsize
defines a square.preserve_dtypes (
bool
) – Whether to preserver the data types of underlyingxarray.DataArray
, even ifcval
is of different type.
- Return type:
- 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
andsize
does not define a square.
Notes
If
preserve_dtypes = True
butcval
cannot be safely cast,cval
will be set to 0.