一、文档:
GitHub: https://github.com/albumentations-team/albumentations
官方文档:Albumentations Documentation
二、Installation
pip install -U albumentations
三、Keypoints augmentation Example:
1. Import the required libraries
import albumentations as A
import cv2
2. Define an augmentation pipeline.
transform = A.Compose([
A.RandomCrop(width=330, height=330),
A.RandomBrightnessContrast(p=0.2),
],keypoint_params=A.KeypointParams(format='xy',label_fields=['class_labels'], remove_invisible =False))
#对图片的操作放在第一个参数的列表中,可支持多种操作,p参数表示进行该操作的概率。
#A.KeypointParams()中,format参数定义ground_truth的坐标点格式,还有“yx”、“xysa”等;label_fields定义ground_truth中标签的名称,此参数是一个列表,可以设置多个标签;remove_invisible参数用来设置是否移除数据增强后超出图片范围的点,默认为True,若为True则不显示不可见的点,若为False则显示不可见的点
3. Read images, keypoints and class_labels
image = cv2.imread("/path/image.jpg")
#image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
keypoints = [
(264, 203),
(86, 88),
(254, 160),
(193, 103),
(65, 341),
]
#关键点信息以坐标的形式放入一个列表中,格式与format参数设置的格式同步
class_labels = [
'left_elbow',
'right_elbow',
'left_wrist',
'right_wrist',
'right_hip',
]
4. Pass an image and keypoints to the augmentation pipeline and receive augmented images and points.
#对数据进行变换
transformed = transform(image=image, keypoints=keypoints, class_labels=class_labels)
#读取变换后的数据
transformed_image = transformed['image']
transformed_keypoints = transformed['keypoints']
transformed_class_labels = transformed['class_labels']
四、List of augmentations
1、Spatial-level transforms (空间变换)
(1)、仿射变换
- Affine(scale=None, translate_percent=None, translate_px=None, rotate=None, shear=None, interpolation=1, mask_interpolation=0, cval=0, cval_mask=0, mode=0, fit_output=False, always_apply=False, p=0.5) -support keypoints
#仿射变换
该变换包括Translation(移动)、Rotation(旋转)、Scaling(缩放)、Shear(剪切为梯形),其中:
scale<