包的导入
path = r"D:\\"
img = cv2. imread( "D:\\photo\\test.jpg" )
img = cv2. resize( img, ( 128 , 128 ) )
cv2. imwrite( path+ "img.jpg" , img)
随机裁剪区域,使用灰度填充0.05为比例
aug = iaa. Cutout( size= 0.05 )
images_aug = aug( images= img)
cv2. imwrite( path+ "Cutout.jpg" , images_aug)
随机移除几个区域,用黑色填充
aug = iaa. Dropout( p= ( 0.0 , 0.5 ) , per_channel= True )
images_aug = aug( images= img)
cv2. imwrite( path+ "Dropout.jpg" , images_aug)
运动模糊
aug = iaa. MotionBlur( k= 7 , angle= 360 , direction= 1 , order= 1 )
images_aug = aug( images= img)
cv2. imwrite( path+ "MotionBlur.jpg" , images_aug)
高斯模糊
aug = iaa. GaussianBlur( sigma= 2.0 )
( B, G, R) = cv2. split( img)
images_aug_B = aug( images= B)
images_aug_G = aug( images= G)
images_aug_R = aug( images= R)
images_aug = cv2. merge( [ images_aug_B, images_aug_G, images_aug_R] )
cv2. imwrite( path+ "GaussianBlur.jpg" , images_aug)
脉冲噪声
aug = iaa. ImpulseNoise( 0.5 )
images_aug = aug( images= img)
cv2. imwrite( path+ "ImpulseNoise.jpg" , images_aug)
中心裁剪指定大小
aug = iaa. CropToFixedSize( 512 , 512 , seed = 6 , position= "center" )
( B, G, R) = cv2. split( img)
images_aug_B = aug( images= B) [ 0 ]
images_aug_G = aug( images= G) [