gpt4 book ai didi

python - 高斯噪声没有覆盖主图像-Python

转载 作者:太空宇宙 更新时间:2023-11-03 21:28:17 24 4
gpt4 key购买 nike

我正在尝试向图像(“pepper.jpg”)添加高斯噪声。它有效,如结果所示(“noisypepper.png”);但噪音并没有覆盖“辣椒”,而是在它周围。我在应用噪音时缺少什么吗?任何建议将不胜感激。

import cv2
import numpy as np

img = cv2.imread("pepper.jpg",0)
row, col = img.shape
mean = 0
var = 0.3
sigma = var ** 0.5
gauss = np.random.normal(mean, sigma, (row, col))
gauss = gauss.reshape(row, col)
noisyp = gauss + img
noisyp = noisyp.astype('uint8')
cv2.imwrite('noisy pepper.png', noisyp)

enter image description here

enter image description here

问候,贝鲁兹

最佳答案

uint8 的转换并不复杂。这是您要寻找的内容:

import cv2
import numpy as np


def convert_to_uint8(image_in):
temp_image = np.float64(np.copy(image_in))
cv2.normalize(temp_image, temp_image, 0, 255, cv2.NORM_MINMAX, dtype=-1)

return temp_image.astype(np.uint8)


img = cv2.imread("pepper.jpg", 0)
row, col = img.shape
mean = 0
var = 0.3
sigma = var ** 0.5
gauss = np.random.normal(mean, sigma, (row, col))
gauss = gauss.reshape(row, col)
noisy_pepper = gauss + img

cv2.imwrite('noisy pepper.png', convert_to_uint8(noisy_pepper))

enter image description here

当然,这样的sigma你不会看到噪音。请看一下这个(西格玛约为 14):

..
var = 200
sigma = var ** 0.5
..

enter image description here

关于python - 高斯噪声没有覆盖主图像-Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53703066/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com