【发布时间】:2020-10-06 02:07:38
【问题描述】:
我正在尝试生成如下噪声图像:
我已经知道如何生成带有随机噪声的图像,但不知道如何更改噪声颜色。
import numpy as np
import cv2
import matplotlib.pyplot as plt
img = cv2.imread('/home/pourya/face/os.jpg')[...,::-1]/255.0
noise = np.random.normal(loc=-1, scale=1, size=img.shape)
# noise overlaid over image
noisy = np.clip((img + noise*1.7),0,1)
noisy2 = np.clip((img + noise*1.6),0,1)
# noise multiplied by image:
# whites can go to black but blacks cannot go to white
noisy2mul = np.clip((img*(1 + noise*1.5)),0,1)
noisy4mul = np.clip((img*(1 + noise*1.4)),0,1)
noisy2mul = np.clip((img*(1 + noise*1.8)),0,1)
noisy4mul = np.clip((img*(1 + noise*1.7)),0,1)
# noise multiplied by bottom and top half images,
# whites stay white blacks black, noise is added to center
img2 = img*2
n2 = np.clip(np.where(img2 <= 1, (img2*(1 + noise*0.2)), (1-img2+1)*(1 + noise*0.2)*-1 + 2)/2, 0,1)
n4 = np.clip(np.where(img2 <= 1, (img2*(1 + noise*0.4)), (1-img2+1)*(1 + noise*0.4)*-1 + 2)/2, 0,1)
# norm noise for viz only
noise2 = (noise - noise.min())/(noise.max()-noise.min())
plt.figure(figsize=(20,20))
plt.imshow(np.vstack((np.hstack((img, noise2)),
np.hstack((noisy, noisy2)),
np.hstack((noisy2mul, noisy4mul)),
np.hstack((n2, n4)))))
plt.show()
plt.hist(noise.ravel(), bins=100)
plt.show()
使用上面的代码,我得到了以下结果。
如何生成与第一张图像相似的单色噪点? 谢谢
【问题讨论】:
-
也许在 HSV 颜色空间中做,让 H 通道变成一种颜色
标签: python opencv noise-generator