[关闭]
@BruceWang 2018-01-08T22:01:47.000000Z 字数 1742 阅读 1617

图像扭曲代码

数据增强
[TOC]


1.图像增强

  1. # _*_ coding:utf-8 _*_
  2. """
  3. Deep learning image augmentation
  4. cited from https://scottontechnology.com/flip-image-opencv-python/
  5. http://augmentor.readthedocs.io/en/master/userguide/mainfeatures.html
  6. """
  7. import cv2
  8. import glob
  9. import random
  10. import os
  11. from multiprocessing import Pool as ProcessPool
  12. from multiprocessing.dummy import Pool as ThreadPool
  13. import Augmentor
  14. import numpy as np

2.终极执行扩增函数

  1. def augmentation():
  2. path = r'C:\Users\aixin\Desktop\all_my_learning\match\niu_qu\original_path'
  3. output_path = r'C:\Users\aixin\Desktop\all_my_learning\match\niu_qu\niuqu_path'
  4. p = Augmentor.Pipeline(path, output_directory=output_path)
  5. # p.flip_left_right(probability=0.4)
  6. # p.flip_top_bottom(probability=0.6)
  7. # p.flip_random(probability=0.5)
  8. # p.crop_centre(probability=0.2, percentage_area=0.8)
  9. # p.crop_random(probability=0.6, percentage_area=0.7)
  10. # p.rotate(probability=0.2, max_left_rotation=10, max_right_rotation=16)
  11. # p.rotate_random_90(probability=0.5)
  12. # p.rotate180(probability=0.4)
  13. # p.rotate270(probability=0.3)
  14. p.zoom(probability=0.3, min_factor=1.1, max_factor=1.5)
  15. p.random_distortion(probability=0.5, grid_height=4, grid_width=4, magnitude=4)
  16. p.shear(probability=0.2, max_shear_left=15, max_shear_right=15)
  17. p.shear(probability=0.5, max_shear_left=15, max_shear_right=15)
  18. p.skew(probability=0.1, magnitude=0.6)
  19. p.skew_tilt(probability=0.2, magnitude=0.6)
  20. p.skew_corner(probability=0.2, magnitude=0.6)
  21. p.skew_top_bottom(probability=0.3, magnitude=0.6)
  22. p.skew_left_right(probability=0.2, magnitude=0.6)
  23. # SIZE = 4 * 5
  24. # 这里的size表示的是random_distortion随机产生的扩展个数
  25. p.sample(10)
  26. if __name__ == '__main__':
  27. augmentation()
  28. pass

如果你有什么疑问,欢迎联系我哈,我会给大家慢慢解答啦~~~
怎么联系我? 笨啊~ ~~ 你留言也行。

你关注微信公众号1.听朕给你说:2.tzgns666,3.或者扫那个二维码,后台联系我也行啦!
tzgns666

终于写完了,赞赏一下下嘛!

(爱心.gif) 么么哒~么么哒~么么哒
爱心从我做起,贫困山区捐衣服,为开源社区做贡献!

码字不易啊,如果你觉得本文有帮助,三毛也是爱!真的就三毛,呜呜。。。我祝各位帅哥,和美女,你们永远十八岁,嗨嘿嘿~~~

weiChat
Alibaba

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注