Crop transforms (augmentations.crops.transforms)¶
class
albumentations.augmentations.crops.transforms.BBoxSafeRandomCrop
(erosion_rate=0.0, always_apply=False, p=1.0)
[view source on GitHub]
¶
Crop a random part of the input without loss of bboxes.
Parameters:
Name | Type | Description |
---|---|---|
erosion_rate |
float |
erosion rate applied on input image height before crop. |
p |
float |
probability of applying the transform. Default: 1. |
Targets: image, mask, bboxes Image types: uint8, float32
class
albumentations.augmentations.crops.transforms.CenterCrop
(height, width, always_apply=False, p=1.0)
[view source on GitHub]
¶
Crop the central part of the input.
Parameters:
Name | Type | Description |
---|---|---|
height |
int |
height of the crop. |
width |
int |
width of the crop. |
p |
float |
probability of applying the transform. Default: 1. |
Targets: image, mask, bboxes, keypoints
Image types: uint8, float32
Note: It is recommended to use uint8 images as input. Otherwise the operation will require internal conversion float32 -> uint8 -> float32 that causes worse performance.
class
albumentations.augmentations.crops.transforms.Crop
(x_min=0, y_min=0, x_max=1024, y_max=1024, always_apply=False, p=1.0)
[view source on GitHub]
¶
Crop region from image.
Parameters:
Name | Type | Description |
---|---|---|
x_min |
int |
Minimum upper left x coordinate. |
y_min |
int |
Minimum upper left y coordinate. |
x_max |
int |
Maximum lower right x coordinate. |
y_max |
int |
Maximum lower right y coordinate. |
Targets: image, mask, bboxes, keypoints
Image types: uint8, float32
class
albumentations.augmentations.crops.transforms.CropAndPad
(px=None, percent=None, pad_mode=0, pad_cval=0, pad_cval_mask=0, keep_size=True, sample_independently=True, interpolation=1, always_apply=False, p=1.0)
[view source on GitHub]
¶
Crop and pad images by pixel amounts or fractions of image sizes.
Cropping removes pixels at the sides (i.e. extracts a subimage from a given full image).
Padding adds pixels to the sides (e.g. black pixels).
This transformation will never crop images below a height or width of 1
.
Note:
This transformation automatically resizes images back to their original size. To deactivate this, add the
parameter keep_size=False
.
Parameters:
Name | Type | Description |
---|---|---|
px |
int or tuple |
The number of pixels to crop (negative values) or pad (positive values)
on each side of the image. Either this or the parameter |
percent |
float or tuple |
The number of pixels to crop (negative values) or pad (positive values)
on each side of the image given as a fraction of the image
height/width. E.g. if this is set to |
pad_mode |
int |
OpenCV border mode. |
pad_cval |
number, Sequence[number] |
The constant value to use if the pad mode is |
pad_cval_mask |
number, Sequence[number] |
Same as pad_cval but only for masks. |
keep_size |
bool |
After cropping and padding, the result image will usually have a
different height/width compared to the original input image. If this
parameter is set to |
sample_independently |
bool |
If |
interpolation |
OpenCV flag |
flag that is used to specify the interpolation algorithm. Should be one of: cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_LANCZOS4. Default: cv2.INTER_LINEAR. |
Targets: image, mask, bboxes, keypoints
Image types: any
class
albumentations.augmentations.crops.transforms.CropNonEmptyMaskIfExists
(height, width, ignore_values=None, ignore_channels=None, always_apply=False, p=1.0)
[view source on GitHub]
¶
Crop area with mask if mask is non-empty, else make random crop.
Parameters:
Name | Type | Description |
---|---|---|
height |
int |
vertical size of crop in pixels |
width |
int |
horizontal size of crop in pixels |
ignore_values |
list of int |
values to ignore in mask, |
ignore_channels |
list of int |
channels to ignore in mask
(e.g. if background is a first channel set |
p |
float |
probability of applying the transform. Default: 1.0. |
Targets: image, mask, bboxes, keypoints
Image types: uint8, float32
class
albumentations.augmentations.crops.transforms.RandomCrop
(height, width, always_apply=False, p=1.0)
[view source on GitHub]
¶
Crop a random part of the input.
Parameters:
Name | Type | Description |
---|---|---|
height |
int |
height of the crop. |
width |
int |
width of the crop. |
p |
float |
probability of applying the transform. Default: 1. |
Targets: image, mask, bboxes, keypoints
Image types: uint8, float32
class
albumentations.augmentations.crops.transforms.RandomCropFromBorders
(crop_left=0.1, crop_right=0.1, crop_top=0.1, crop_bottom=0.1, always_apply=False, p=1.0)
[view source on GitHub]
¶
Crop bbox from image randomly cut parts from borders without resize at the end
Parameters:
Name | Type | Description |
---|---|---|
crop_left |
float |
single float value in (0.0, 1.0) range. Default 0.1. Image will be randomly cut |
crop_right |
float |
single float value in (0.0, 1.0) range. Default 0.1. Image will be randomly cut |
crop_top |
float |
singlefloat value in (0.0, 1.0) range. Default 0.1. Image will be randomly cut |
crop_bottom |
float |
single float value in (0.0, 1.0) range. Default 0.1. Image will be randomly cut |
p |
float |
probability of applying the transform. Default: 1. |
Targets: image, mask, bboxes, keypoints
Image types: uint8, float32
class
albumentations.augmentations.crops.transforms.RandomCropNearBBox
(max_part_shift=(0.3, 0.3), cropping_box_key='cropping_bbox', always_apply=False, p=1.0)
[view source on GitHub]
¶
Crop bbox from image with random shift by x,y coordinates
Parameters:
Name | Type | Description |
---|---|---|
max_part_shift |
float, [float, float] |
Max shift in |
cropping_box_key |
str |
Additional target key for cropping box. Default |
p |
float |
probability of applying the transform. Default: 1. |
Targets: image, mask, bboxes, keypoints
Image types: uint8, float32
Examples:
>>> aug = Compose([RandomCropNearBBox(max_part_shift=(0.1, 0.5), cropping_box_key='test_box')],
>>> bbox_params=BboxParams("pascal_voc"))
>>> result = aug(image=image, bboxes=bboxes, test_box=[0, 5, 10, 20])
class
albumentations.augmentations.crops.transforms.RandomResizedCrop
(height, width, scale=(0.08, 1.0), ratio=(0.75, 1.3333333333333333), interpolation=1, always_apply=False, p=1.0)
[view source on GitHub]
¶
Torchvision's variant of crop a random part of the input and rescale it to some size.
Parameters:
Name | Type | Description |
---|---|---|
height |
int |
height after crop and resize. |
width |
int |
width after crop and resize. |
scale |
[float, float] |
range of size of the origin size cropped |
ratio |
[float, float] |
range of aspect ratio of the origin aspect ratio cropped |
interpolation |
OpenCV flag |
flag that is used to specify the interpolation algorithm. Should be one of: cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_LANCZOS4. Default: cv2.INTER_LINEAR. |
p |
float |
probability of applying the transform. Default: 1. |
Targets: image, mask, bboxes, keypoints
Image types: uint8, float32
class
albumentations.augmentations.crops.transforms.RandomSizedBBoxSafeCrop
(height, width, erosion_rate=0.0, interpolation=1, always_apply=False, p=1.0)
[view source on GitHub]
¶
Crop a random part of the input and rescale it to some size without loss of bboxes.
Parameters:
Name | Type | Description |
---|---|---|
height |
int |
height after crop and resize. |
width |
int |
width after crop and resize. |
erosion_rate |
float |
erosion rate applied on input image height before crop. |
interpolation |
OpenCV flag |
flag that is used to specify the interpolation algorithm. Should be one of: cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_LANCZOS4. Default: cv2.INTER_LINEAR. |
p |
float |
probability of applying the transform. Default: 1. |
Targets: image, mask, bboxes Image types: uint8, float32
class
albumentations.augmentations.crops.transforms.RandomSizedCrop
(min_max_height, height, width, w2h_ratio=1.0, interpolation=1, always_apply=False, p=1.0)
[view source on GitHub]
¶
Crop a random part of the input and rescale it to some size.
Parameters:
Name | Type | Description |
---|---|---|
min_max_height |
[int, int] |
crop size limits. |
height |
int |
height after crop and resize. |
width |
int |
width after crop and resize. |
w2h_ratio |
float |
aspect ratio of crop. |
interpolation |
OpenCV flag |
flag that is used to specify the interpolation algorithm. Should be one of: cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_LANCZOS4. Default: cv2.INTER_LINEAR. |
p |
float |
probability of applying the transform. Default: 1. |
Targets: image, mask, bboxes, keypoints
Image types: uint8, float32