代码:

# -*-coding = utf-8 -*-
"""
1. Image_flip:翻转图片
2. Image_traslation:平移图片
3. Image_rotate:旋转图片
4. Image_noise:添加噪声
"""
import os
import cv2
import numpy as np
from random import choice
import randomdef Image_flip(img):""":param img:原始图片矩阵:return: 0-垂直; 1-水平; -1-垂直&水平"""if img is None:returnparas = [0, 1, -1]img_new = cv2.flip(img, choice(paras))return img_newdef Image_traslation(img):""":param img: 原始图片矩阵:return: [1, 0, 100]-宽右移100像素; [0, 1, 100]-高下移100像素"""paras_wide = [[1, 0, 100], [1, 0, -100]]paras_height = [[0, 1, 100], [0, 1, -100]]rows, cols = img.shape[:2]img_shift = np.float32([choice(paras_wide), choice(paras_height)])border_value = tuple(int(x) for x in choice(choice(img)))img_new = cv2.warpAffine(img, img_shift, (cols, rows), borderValue=border_value)return img_newdef Image_rotate(img):""":param img:原始图片矩阵:return:旋转中心,旋转角度,缩放比例"""rows, cols = img.shape[:2]rotate_core = (cols / 2, rows / 2)rotate_angle = [60, -60, 45, -45, 90, -90, 210, 240, -210, -240]paras = cv2.getRotationMatrix2D(rotate_core, choice(rotate_angle), 1)border_value = tuple(int(x) for x in choice(choice(img)))img_new = cv2.warpAffine(img, paras, (cols, rows), borderValue=border_value)return img_newdef Image_noise(img):""":param img:原始图片矩阵:return: 0-高斯噪声,1-椒盐噪声"""paras = [0, 1]gaussian_class = choice(paras)noise_ratio = [0.05, 0.06, 0.08]if gaussian_class == 1:output = np.zeros(img.shape, np.uint8)prob = choice(noise_ratio)thres = 1 - prob# print('prob', prob)for i in range(img.shape[0]):for j in range(img.shape[1]):rdn = random.random()if rdn < prob:output[i][j] = 0elif rdn > thres:output[i][j] = 255else:output[i][j] = img[i][j]return outputelse:mean = 0var = choice([0.001, 0.002, 0.003])img = np.array(img / 255, dtype=float)noise = np.random.normal(mean, var ** 0.5, img.shape)out = img + noiseif out.min() < 0:low_clip = -1else:low_clip = 0out = np.clip(out, low_clip, 1.0)out = np.uint8(out * 255)return outif __name__ == "__main__":"""path_read: 读取原始数据集图片的位置;path_write:图片扩增后存放的位置;picture_size:图片之后存储的尺寸;enhance_hum: 需要通过扩增手段增加的图片数量"""p_r = "/home/barry/PycharmProjects/Lab/train_dataset/"p_w = "/home/barry/PycharmProjects/Lab/train_dataset_new2/"for i in range(1,11):path_read = p_r+str(i)path_write = p_w+str(i)enhance_num = 500image_list = os.listdir(path_read)existed_img = len(image_list)for j,img_src in enumerate(image_list):img_src = path_read+'/'+img_srcimg = cv2.imread(img_src)image_dir2 = path_write + '/' + str(random.random()*1000)+'.png'cv2.imwrite(image_dir2, img)while enhance_num > 0:img = choice(image_list)image = cv2.imread(path_read + '/' + img, cv2.IMREAD_COLOR)algorithm = [1, 3, 4]random_process = choice(algorithm)if random_process == 1:image = Image_flip(image)elif random_process == 3:image = Image_rotate(image)else:image = Image_noise(image)image_dir = path_write + '/' + str(enhance_num + existed_img - 1).zfill(5) + '.png'cv2.imwrite(image_dir, image)enhance_num -= 1

参考资料:
https://blog.csdn.net/Celibrity/article/details/106297733

深度学习-扩展数据集相关推荐

  1. MATLAB深度学习(1) --- 想要做好深度学习?数据集是第一步

    MATLAB深度学习(1) --- 想要做好深度学习?数据集是第一步 创作目的 项目简介 本期重点---数据集构建 本文所使用数据集简介 用table来搭建训练集 总结 创作目的 大家好,这里是微信公 ...

  2. 快速构建深度学习图像数据集,微软Bing和Google哪个更好用?

    译者 | Serene 编辑 | 明明 出品 | AI 科技大本营(公众号ID:rgznai100) [AI 科技大本营导读]在本文中,作者将利用微软的 Bing Image Search API 来 ...

  3. python爬取百度图片(用于深度学习中数据集的收集)

    6_python爬取百度图片(用于深度学习中数据集的收集)(6-20181225-) 参考: https://blog.csdn.net/guyuealian/article/details/7873 ...

  4. camvid数据集介绍_深度学习图像数据集介绍(MSCOCO)

    深度学习图像数据集介绍(MSCOCO) MSCOCO数据集是微软开发维护的大型图像数据集,次数聚集的任务包括识别(recognition),分割(segementation),及检测(detectio ...

  5. 25个深度学习开源数据集

    简介 学习深度学习最重要的就是数据集啦.小编在刚开始学习深度学习的时候最头疼的一件事就是没有数据,徒有很多想法,但却无法实现,这里小编给大家介绍25个常用的深度学习开源数据集,这是从国外的一篇博客中看 ...

  6. 国内外深度学习开放数据集下载集合(值得收藏,不断更新)

    国内外深度学习开放数据集下载集合(值得收藏,不断更新) 一.Image processing data set 1.MNIST ,是最流行的深度学习数据集之一.这是一个手写数字数据集,包含一个有着 6 ...

  7. Duplicate Cleaner - 重复文件 / 相似文件扫描 - 构建深度学习标注数据集

    Duplicate Cleaner - 重复文件 / 相似文件扫描 - 构建深度学习标注数据集 https://www.duplicatecleaner.com/ Duplicate Cleaner ...

  8. 深度学习 大数据集处理_大规模深度学习数据集管理系统

    深度学习 大数据集处理 Machine learning is data-driven. Most artificial intelligence (AI) practitioners would a ...

  9. 图像处理 语音识别 深度学习 开放数据集

    从图像处理到语音识别,25款数据科学家必知的深度学习开放数据集 本文介绍了 25 个深度学习开放数据集,包括图像处理.自然语言处理.语音识别和实际问题数据集. 介绍 深度学习(或生活中大部分领域)的关 ...

  10. 从图像处理到语音识别,25款数据科学家必知的深度学习开放数据集

    选自Analytics Vidhya,作者:Pranav Dar,机器之心编译. 本文介绍了 25 个深度学习开放数据集,包括图像处理.自然语言处理.语音识别和实际问题数据集. 介绍 深度学习(或生活 ...

最新文章

  1. linux 雷电接口,Intel完全开放雷电技术:底层融合USB 4
  2. 自考总结-2019-4-14
  3. php mssql image,php5连接mssql2005数据库表中的image字段图片显示
  4. Vue后台管理系统实现登录功能
  5. 【ArcGIS微课1000例】0017:ArcGIS测量距离和面积工具的巧妙使用
  6. 1,滑动验证,前后台接口
  7. python 折线图 尾部_Matplotlib 折线图plot()所有用法详解
  8. springboot的aop里的 @Pointcut()里的配置
  9. python是一门高级的计算机语言_为有抱负的开发者推荐的最佳 10 门编程语言
  10. s5p6818开发板uboot网络开通
  11. asp 保存listbox已有的值_使用Asp.net实现信息管理系统的数据统计功能
  12. HDFView 3.1.2win10百度云资源
  13. 程序员成长的10条体会
  14. ios 默认字体加粗
  15. 几何结构因子(Geometrical structure factor)和原子形状因子(atomic form factor)
  16. 从零开始安装ubuntu22.04并搭建远程深度学习环境
  17. 需求分析挑战之旅(疯狂的订餐系统)(2)——需求分析的大道理
  18. vivo 云原生容器探索和落地实践
  19. 推荐一款工作学习中十分好用的插件--uTools
  20. PLSQL——条件控制(IF、CASE WHNE)

热门文章

  1. HadoopLearning
  2. 数据挖掘中最易犯的10个错误,请绕行!
  3. MVC去掉传参时的验证:从客户端中检测到有潜在危险的Request.QueryString值
  4. OZ Report 오즈 리포트 개발
  5. 牢记31种CSS选择器
  6. linux下的hosts文件
  7. 应用多元统计分析第五章判别分析例题python代码
  8. 初识面向对象(钻石继承,super,多态,封装,method,property,classmethod,staticmethod)...
  9. HTML(超文本语言)
  10. ansibe tower的开源替代品semaphore