图像增强

import imageio
import imgaug as ia
from imgaug import augmenters as iaa
# matplotlib inline
import cv2 as cv
import numpy as np
from scipy import ndimage

def inhance(path1,path2):
    image = imageio.imread("img.png")  # Image格式
    print("Original")

 #实现仿射变换,本节仅利用了其中的旋转操作;
    rotate = iaa.Affine(rotate=(-25, 25))
    image_rotate = rotate(image=image)
    cv.imwrite(path1[:-4] + 'rotate' + path1[-4:], image_rotate)

#添加高斯白噪声
    addGasss=iaa.AdditiveGaussianNoise(scale=(10, 60))
    image_addGasss=addGasss(image=image)
    cv.imwrite(path1[:-4] + 'addGasss' + path1[-4:], image_addGasss)

#实现裁剪和边缘补充
    cropandpad=iaa.CropAndPad(percent=(-0.2, 0.2), pad_mode="edge")
    image_cropandpad = cropandpad(image=image)
    cv.imwrite(path1[:-4] + 'cropandpad' + path1[-4:], image_cropandpad)

#Hue空间调整饱和度
    addToSatu = iaa.AddToHueAndSaturation((-60, 60))
    image_addToSatu = addToSatu(image=image)
    cv.imwrite(path1[:-4] + 'addToSatu' + path1[-4:], image_addToSatu)

#随机弹性变换(仿射变换的一种)
    addElastic = iaa.AddToHueAndSaturation((-60, 60))
    image_addElastic = addElastic(image=image)
    cv.imwrite(path1[:-4] + 'addElastic' + path1[-4:], image_addElastic)

#左右翻转
    h_flip = cv.flip(image, 1) #左右
    cv.imwrite(path1[:-4] + 'h_flip' + path1[-4:], h_flip)
#上下翻转
    w_flip = cv.flip(image, 0) #上下
    cv.imwrite(path1[:-4] + 'w_flip' + path1[-4:], w_flip)

#旋转90度
    img_rote_90 = ndimage.rotate(image, 90)
    cv.imwrite(path1[:-4] + 'img_rote_90' + path1[-4:], img_rote_90)

#旋转180度
    img_rote_180 = ndimage.rotate(image, 180)
    cv.imwrite(path1[:-4] + 'img_rote_180' + path1[-4:], img_rote_180)

#旋转270度
    img_rote_270 = ndimage.rotate(image, 270)
    cv.imwrite(path1[:-4] + 'img_rote_270' + path1[-4:], img_rote_270)


if __name__ == '__main__':
    inhance('img.png','img_1.png')

 

上一篇:最近公共祖先


下一篇:YOLOV5训练数据出现:no labels found