image——Data Augmentation的代码
来源:互联网 发布:王作强鱼线淘宝店 编辑:程序博客网 时间:2024/06/06 09:24
切片(crop):
def crop(image, random_crop, image_size): if image.shape[1]>image_size: sz1 = int(image.shape[1]//2) sz2 = int(image_size//2) if random_crop: diff = sz1-sz2 (h, v) = (np.random.randint(-diff, diff+1), np.random.randint(-diff, diff+1)) else: (h, v) = (0,0) image = image[(sz1-sz2+v):(sz1+sz2+v),(sz1-sz2+h):(sz1+sz2+h),:] return image
############################################################################# 函数:crop# 描述:随机裁剪图像## 输入:图像image, crop_size# 返回:图像image############################################################################def crop(image, crop_size, random_crop=True): if random_crop: # 若随机裁剪 if image.shape[1] > crop_size: sz1 = image.shape[1] // 2 sz2 = crop_size // 2 diff = sz1 - sz2 (h, v) = (np.random.randint(0, diff + 1), np.random.randint(0, diff + 1)) image = image[v:(v + crop_size), h:(h + crop_size), :] return image
# 左右上下翻转
def flip(image, random_flip=True): if random_flip and np.random.choice([True, False]): image = np.fliplr(image) if random_flip and np.random.choice([True, False]): image = np.flipud(image) return image
#图像旋转
def random_rotate_image(image): angle = np.random.uniform(low=-10.0, high=10.0) return misc.imrotate(image, angle, 'bicubic')
############################################################################# 函数:rotation# 描述:随机旋转图片,增强数据,用图像边缘进行填充。## 输入:图像image# 返回:图像image############################################################################def rotation(image, random_flip=True): if random_flip and np.random.choice([True, False]): w,h = image.shape[1], image.shape[0] # 0-180随机产生旋转角度。 angle = np.random.randint(0,180) RotateMatrix = cv2.getRotationMatrix2D(center=(image.shape[1]/2, image.shape[0]/2), angle=angle, scale=0.7) # image = cv2.warpAffine(image, RotateMatrix, (w,h), borderValue=(129,137,130)) #image = cv2.warpAffine(image, RotateMatrix, (w,h),borderValue=(129,137,130)) image = cv2.warpAffine(image, RotateMatrix, (w,h),borderMode=cv2.BORDER_REPLICATE) return image
图像归一化处理:
def prewhiten(x): mean = np.mean(x) std = np.std(x) std_adj = np.maximum(std, 1.0/np.sqrt(x.size)) y = np.multiply(np.subtract(x, mean), 1/std_adj) return y
图像平移:
############################################################################# 函数:translation# 描述:随机平移图片,增强数据,用图像边缘进行填充。## 输入:图像image# 返回:图像image############################################################################def translation(image, random_flip=True): if random_flip and np.random.choice([True, False]): w,h = 1920, 1080 H1 = np.float32([[1,0],[0,1]]) H2 = np.random.uniform(50,500, [2,1]) H = np.hstack([H1, H2]) # H = np.float32([[1,0,408],[0,1,431]]) print (H) image = cv2.warpAffine(image, H, (w,h), borderMode=cv2.BORDER_REPLICATE) return image
调整光照
from skimage import exposureimport numpy as npdef gen_exposure(image, random_xp=True): if random_xp and np.random.choice([True, False]): image = exposure.adjust_gamma(image, 1.2) # 调暗 if random_xp and np.random.choice([True, False]): image = exposure.adjust_gamma(image, 1.5) # 调暗 if random_xp and np.random.choice([True, False]): image = exposure.adjust_gamma(image, 0.9) # 调亮 if random_xp and np.random.choice([True, False]): image = exposure.adjust_gamma(image, 0.8) # 调亮 if random_xp and np.random.choice([True, False]): image = exposure.adjust_gamma(image, 0.7) # 调暗 return image
阅读全文
0 0
- image——Data Augmentation的代码
- trick—Data Augmentation
- 数据扩增 data-augmentation的方法及代码
- Data Augmentation
- data augmentation
- Data Augmentation.
- 图片数据集太少?Keras Image Data Augmentation 各参数详解
- 深度学习中的Data Augmentation和代码实现
- data augmentation 个人理解
- DATA Augmentation 数据增强
- data augmentation and dropout
- 数据增强 data augmentation
- 图片的数据增强(Data Augmentation)方法
- 深度学习避免过拟合的方法---Data Augmentation
- Keras-5 基于 ImageDataGenerator 的 Data Augmentation实现
- Data Augmentation的几种常用方法总结
- Data Augmentation & data Transfer Learning
- 图片数据集太少?看我七十二变,Keras Image Data Augmentation 各参数详解
- 基于DNN的semi-supervised learning
- ADB命令备份
- Docker:初识docker及工具介绍(一)
- 搭建GO开发环境(Win10 go-ethereum)
- Kylin使用之创建Cube和高级设置
- image——Data Augmentation的代码
- 如何用化学软件画立体图?
- 乱码问题
- OpenStack镜像如何使用Config Drive实现元数据注入
- Maven安装与配置SpringToolSuite创建项目时的配置以及pomXml和spring_beansXml以及日志文件
- perl中find常用方法
- (原创)安卓Drawable文件夹适配规律
- redux-saga HellWorld入门 异步计数器(react-redux)
- 如何用消息系统避免分布式事务?