图像增强:增强图像中的有用信息,它可以是一个失真的过程,其目的是要改善图像的视觉效果。
在深度学习范畴下,图像增强是为了丰富图像的样本特征,使模型泛化能力更强。常用方式有:旋转、裁剪、水平或垂直旋转、改变亮度、高斯滤波、模糊处理。
此文所涉及的图像增强技术通过opencv实现。
import random
import pickle
import os
import cv2
import time
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image, ImageDraw
import os.path as osp
def img_show(img_raw):
cv2.namedWindow("Image")
cv2.imshow('Image',img_raw)
cv2.waitKey (0)
cv2.destroyAllWindows()
return img_raw
def rota_img(raw_img,degree):
"""
opencv实现
对图像进行随机任意角度(0~360度)旋转
degree:旋转角度
:return: 旋转转之后的图像
"""
h, w, c = raw_img.shape#(768,480,3)
center_x = w // 2
center_y = h // 2
center = (center_x, center_y)
M= cv2.getRotationMatrix2D(center, -degree, 1.)
image = cv2.warpAffine