python-3.x - 从单个图像生成图像数据集

标签 python-3.x opencv deep-learning computer-vision photoshop

我有一张如下所示的图像:

enter image description here

我需要生成一个图像数据集,保留该图像的基本特征,但添加一些噪声,例如我们在图像中看到 1:30 时间的一条线。

主要是图像的粉红色部分(垂直线)、蓝色部分(中央蓝色色调)和边缘的黄/绿色部分。我希望以一种可以控制这三件事并随机生成的方式“学习”图像:

  • 蓝色中心色调的小颜色变化和大小
  • 粉红色垂直线的粗细和颜色
  • 黄色/绿色边缘及其大小(我可以以牺牲中间的蓝色为代价来扩展它们,反之亦然
  • 约束:黄色圆圈(半导体晶圆的图像)的大小或形状不能改变。但它可以在黑色方 block 的顶部移动。正如上面三点所述,它内部的结构也会发生变化。
对于具有计算机视觉经验的人来说,这可能是一个简单的问题,但不幸的是,我在这个领域没有太多经验。因此,我很想获得有关在这个方向取得进展的任何想法。谢谢。

最佳答案

一种方法是使用 kerasImageDataGenerator

    1. 确定您需要多少样本?假设5。
    • total_number = 5
  • 初始化ImageDataGenerator类。例如
    • data_gen = ImageDataGenerator(rescale=1. / 255, shear_range=0.2,
                                     zoom_range=0.2, horizontal_flip=True)
      
  • 将图像转换为张量。
    • img = load_img("xIzEG.png", grayscale=False)  # You can also create gray-images.
      arr = img_to_array(img)
      tensor_img = arr.reshape((1, ) + arr.shape)
      
  • 创建一个要存储结果的文件夹,即填充,然后填充
    • for i, _ in enumerate(data_gen.flow(x=tensor_img,
                                          batch_size=1,
                                          save_to_dir="populated",
                                          save_prefix="generated",
                                          save_format=".png")):
      if i > total_number:
          break
      

现在,如果您查看您的已填充文件夹:

enter image description here enter image description here enter image description here enter image description here enter image description here

代码


from keras.preprocessing.image import load_img, img_to_array
from keras.preprocessing.image import ImageDataGenerator

# Total Generated number
total_number = 5

data_gen = ImageDataGenerator(rescale=1. / 255, shear_range=0.2,
                              zoom_range=0.2, horizontal_flip=True)

# Create image to tensor
img = load_img("xIzEG.png", grayscale=False)
arr = img_to_array(img)
tensor_image = arr.reshape((1, ) + arr.shape)

for i, _ in enumerate(data_gen.flow(x=tensor_image,
                                    batch_size=1,
                                    save_to_dir="populated",
                                    save_prefix="generated",
                                    save_format=".png")):
    if i > total_number:
        break

关于python-3.x - 从单个图像生成图像数据集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64383540/

相关文章:

python - 过滤列表。仅在项目之间有一定距离的情况下获取列表元素?

python-3.x - 如何验证 QTableWidget 中的单元格?

opencv - 训练分类器以仅检测睫毛/ Nose 功能dlib和opencv?

python - 在Azure函数中导入python cv2时出错

Python-串行读取并使用正则表达式对数据进行分组

使用 Input() 的 Python 代码在 Sublime REPL 中给出语法错误,但可以与 Python Shell 一起使用

c++ - OpenCV RGB值检测?

deep-learning - Pytorch/cuda : CPU error and map_location

python - Pytorch: AttributeError: 'function' 对象没有属性 'copy'

docker - 如何以非root用户身份运行正式的Tensorflow Docker Image?