SSD 图像处理数据增强方法。
可以采用ACDSee,在做如下变换的时候,搞平移,随机颜色,对比度,亮度,颜色增强 ,镜像,反转,旋转,
里面搞加噪声 等等, 少量图片 可以在ACDSee里面批量做,注意选择保留最好质量。或者矢量图模式。是的转换后的图片质量最好
----------------------------
import cv2
import numpy as np
import os.path
import copy
def rotate(image, angle, center=None, scale=1.0):
(h, w) = image.shape[:2]
# If no rotation center is specified, the center of the image is set as the rotation center
if center is None:
center = (w / 2, h / 2)
M = cv2.getRotationMatrix2D(center, angle, scale)
rotated = cv2.warpAffine(image, M, (w, h))
return rotated
def noiseing(img):
#img = cv2.cvtColor(rgbimg, cv2.COLOR_BGR2GRAY)
param = 30
grayscale = 256
w = img.shape[1]
h = img.shape[0]
newimg = np.zeros((h, w, 3), np.uint8)
#row and col
for x in xrange(0, h):
for y in xrange(0, w, 2): #Avoid exceeding boundaries
r1 = np.random.random_sample()
r2 = np.random.random_sample()
z1 = param * np.cos(2 * np.pi * r2) * np.sqrt((-2) * np.log(r1))
z2 = param * np.sin(2 * np.pi * r2) * np.sqrt((-2) * np.log(r1))
fxy_0 = int(img[x, y, 0] + z1)
fxy_1 = int(img[x, y, 1] + z1)
fxy_2 = int(img[x, y, 2] + z1)
fxy1_0 = int(img[x, y + 1, 0] + z2)
fxy1_1 = int(img[x, y + 1, 1] + z2)
fxy1_2 = int(img[x, y + 1, 2] + z2)
# f(x,y)
if fxy_0 < 0:
fxy_val_0 = 0
elif fxy_0 > grayscale - 1:
fxy_val_0 = grayscale - 1
else:
fxy_val_0 = fxy_0
if fxy_1 < 0:
fxy_val_1 = 0
elif fxy_1 > grayscale - 1:
fxy_val_1 = grayscale - 1
else:
fxy_val_1 = fxy_1
if fxy_2 < 0:
fxy_val_2 = 0
elif fxy_2 > grayscale - 1:
fxy_val_2 = grayscale - 1
else:
fxy_val_2 = fxy_2
# f(x,y+1)
if fxy1_0 < 0:
fxy1_val_0 = 0
elif fxy1_0 > grayscale - 1:
fxy1_val_0 = grayscale - 1
else:
fxy1_val_0 = fxy1_0
if fxy1_1 < 0:
fxy1_val_1 = 0
elif fxy1_1 > grayscale - 1:
fxy1_val_1 = grayscale - 1
else:
fxy1_val_1 = fxy1_1
if fxy1_2 < 0:
fxy1_val_2 = 0
elif fxy1_2 > grayscale - 1:
fxy1_val_2 = grayscale - 1
else:
fxy1_val_2 = fxy1_2
newimg[x, y, 0] = fxy_val_0
newimg[x, y, 1] = fxy_val_1
newimg[x, y, 2] = fxy_val_2
newimg[x, y + 1, 0] = fxy1_val_0
newimg[x, y + 1, 1] = fxy1_val_1
newimg[x, y + 1, 2] = fxy1_val_2
#newimg = cv2.cvtColor(newimg, cv2.COLOR_GRAY2RGB)
cv2.destroyAllWindows()
return newimg
#i = 0
file_dir = "/home/xn/caffe/examples/facetestquestions/ImageDatainc/"
for class_name in os.listdir(file_dir):
#for index,name in enumerate(classes):
class_path = file_dir+class_name+"/"
for img_name in os.listdir(class_path):
img_path = class_path + img_name
image = cv2.imread(img_path)
#Simple rotation 90 degrees
rotated = rotate(image, 90)
cv2.imwrite(class_path + '/' + img_name[0:7] +'_ro90.jpg', rotated)
#Rotate 180 degrees and add Gaussian noise
rotated = rotate(image, 180)
# if __name__ == '__main__':
#print 'load %s ...' % fn
#img = cv2.imread(rotated)
# coutn = 100000
# for k in xrange(0, coutn):
# get the random point
# xi = int(np.random.uniform(0, rotated.shape[1]))
# xj = int(np.random.uniform(0, rotated.shape[0]))
# # add noise
# if rotated.ndim == 2:
# rotated[xj, xi] = 255
# elif rotated.ndim == 3:
# rotated[xj, xi, 0] = 25
# rotated[xj, xi, 1] = 20
# rotated[xj, xi, 2] = 20
#cv2.namedWindow('img')
#cv2.imshow('img', img)
#cv2.waitKey()
# cv2.destroyAllWindows()
#newimg = skimage.util.random_noise(rotated, mode='salt', seed=None, clip=False)
newimg = noiseing(rotated)
#newimg = cv2.cvtColor(newing, cv2.COLOR_GRAY2BGR)
cv2.imwrite(class_path + '/' + img_name[0:7] + '_rono.jpg', newimg)
#Image processing
size = image.shape
#Get an image that is the same as the original image, note this to use deep copy
iLR = copy.deepcopy(image)
h = size[0]
w = size[1]
for i in range(h): # row and col
for j in range(w):
iLR[i, w - 1 - j] = image[i, j] # Mirror formula
cv2.imwrite(class_path + '/' + img_name[0:7] + '_mirr.jpg', iLR)
————————————————
版权声明:本文为CSDN博主「xunan003」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/xunan003/article/details/80377373
SSD 图像处理数据增强方法。相关推荐
- 没有足够多的数据怎么办?计算机视觉数据增强方法总结
©PaperWeekly 原创 · 作者|燕皖 单位|渊亭科技 研究方向|计算机视觉.CNN 当没有足够多的数据量时该怎么办?学者们针对这一问题已经研发看各种巧妙的解决方案,以避在深度学习模型中数据少 ...
- 自动搜索数据增强方法分享——fast-autoaugment
前言 简短的介绍下分享fast-autoaugment的原因 毫无疑问数据增强对于训练CNN非常有效,大家也在不断发明新的数据增强方法 拿到一份数据集,我们凭借之前的经验组合不同的增强方法形成一个数据 ...
- python ssd目标检测_目标检测算法之SSD的数据增强策略
前言 这篇文章是对前面<目标检测算法之SSD代码解析>,推文地址如下:点这里的补充.主要介绍SSD的数据增强策略,把这篇文章和代码解析的文章放在一起学最好不过啦.本节解析的仍然是上篇SSD ...
- cut out数据增强_谷歌大脑提出自动数据增强方法AutoAugment:可迁移至不同数据集...
近日,来自谷歌大脑的研究者在 arXiv 上发表论文,提出一种自动搜索合适数据增强策略的方法 AutoAugment,该方法创建一个数据增强策略的搜索空间,利用搜索算法选取适合特定数据集的数据增强策略 ...
- 基于图像的数据增强方法发展现状综述
基于图像的数据增强方法发展现状综述 人工智能技术与咨询 2022-03-22 20:57 点击蓝字 · 关注我们 来源:< 计算机科学与应用> ,作者冯晓硕等 关键词: 数据增强:图像数据 ...
- NLP中的数据增强方法
目录 1 概述 2. 方法 2.1 随机drop和shuffle 2.2 同义词替换 2.3 回译 2.4 文档裁剪 2.5 生成对抗网络 2.6 预训练的语言模型 1 概述 NLP中的数据是离散的. ...
- 水下目标检测之数据集和数据增强方法
水下目标检测之数据集和数据增强方法 通过之前对yolov5的简单学习,发现yolov5的训练和调试都比较方便,因此希望将其运用到水下目标检测的任务中.那么首要任务就是寻找比较合适的数据集作为训练样本, ...
- 二、深度学习数据增强方法汇总
深度学习模型训练数据增强方法汇总 一.随机裁剪 二.RGB-->BGR通道互换 三.仿射变换(缩放) 三.随机旋转 四.对比度调整 五.随机抠图 六.bound box 中心点随机抠图 七.随机 ...
- 各种 AI 数据增强方法,都在这儿了
来源 | 算法进阶 责编 | 寇雪芹 头图 | 下载于视觉中国 数据.算法.算力是人工智能发展的三要素.数据决定了Ai模型学习的上限,数据规模越大.质量越高,模型就能够拥有更好的泛化能力. 然而在实际 ...
最新文章
- 下一代搜索引擎长啥样?Google 给出了TA的答案
- centos7安装vsftpd
- Linux中防火墙(二)
- lua io详细操作
- Java文件路径及文件名乱码_javaweb文件下载及文件名中文乱码处理
- LinuxKit for ARM64 - on packet.net
- 插入排序(Insert Sort)
- fortran调用MKL函数库中的gemm的fortran95接口计算矩阵相乘
- solr为什么比MySQL快_Solr原理?为什么要用Solr?Solr为什么比较快?
- 云服务器ASF挂卡(1)——steamcommunity社区本地反代
- 10本经典的管理学书籍推荐,关于管理学的书都在这里了
- 单独使用mybatis整合mysql案例
- 智渔课堂官方免费教程二十六:Java基础教程之数组
- 关于int.prase的一些解析
- 快速Ps在线P图#稿定
- 【PP-2】定义生产调度员
- Android4.4 XML解析死循环异常导致的开机无法正常启动
- MySQL约束条件和多表查询方式详解
- Android定位失败解决方法
- 实验吧-后台登录 Writeup
热门文章
- 1024程序员节,带你解锁过节新方式
- Prometheus+Grafana监控告警配置
- android hid 编程,Android Bluetooth HID完成详解,androidhid
- js三座大山----(第二座山)
- 发光字招牌制作底板的种类
- Go语言处理Windows系统的图标ICO文件(上)
- 教师计算机考试模块有哪些内容有哪些内容,教师资格考试信息与信息技术模块知识点...
- unity新粒子系统的碰撞和触发
- 【Python爬虫案例学习21】爬取某站上海租房图片
- 一些国内可用的高质量壁纸网站,免翻~