【问题标题】:adding noise to an area in the image向图像中的区域添加噪点
【发布时间】:2020-03-20 10:55:48
【问题描述】:

作为图像预处理的一部分,我想通过将随机像素值添加到使用掩码指定的图像的一部分来破坏图像。我正在使用python。有什么常见的方法可以做到这一点,或者是否有一篇论文发表了这些信息?非常感谢所有帮助

【问题讨论】:

    标签: python image-processing noise generative-adversarial-network image-preprocessing


    【解决方案1】:

    随机像素值只是 0 到 255 之间的随机整数(对于彩色图片)。因此,您可以在图像上选择一个随机像素,并将其替换为 3 个随机 RGB 值。假设您有一张图片(全黑,以便我们可视化):

    import numpy as np
    import matplotlib.pyplot as plt
    
    pic = np.full((10, 10, 3), 0)
    

    然后您可以将图像尺寸内的坐标(此处为 10 x 10)替换为 0 到 255 之间的 3 个随机 RGB 值。

    pic[np.random.randint(0, 10, 5), 
        np.random.randint(0, 10, 5 )] = \
        np.random.randint(0, 256, (5, 3))
    

    逻辑如下:在X、Y中取5个随机点,用0到255之间的3个随机值替换。

    【讨论】:

      猜你喜欢
      • 2012-07-08
      • 2014-02-23
      • 2014-09-05
      • 2013-10-17
      • 2019-09-12
      • 1970-01-01
      • 1970-01-01
      • 2014-11-01
      • 2019-07-23
      相关资源
      最近更新 更多