我想添加白噪声到原始图像的不同信噪比水平,但不确定如何做。
原始图像是(256, 128),我正在使用acoustics包添加噪声。
original = cv2.imread(path)
white = acoustics.generator.white(256*128).reshape(256, 128)
out = original + white*255
cv2.imwrite(path, out)我的问题:
log10(mean(original)/ std(original + white*255))算作信噪比吗?(根据维基 )*255这个数字来修改信噪比吗?发布于 2019-01-23 09:02:39
关键的事实是(这是数学,不是代码)
SNR = mean(s) / std(n)将噪声乘以某些恒定的A会产生一种新的信噪比- SNR_new。
mean(s) / std(A*n)
= mean(s) / (A * std(n))
= (1 / A) * (mean(s) / std(n))
= SNR / A
= SNR_new因此,在python中,我认为这是正确的方法是:
def add_noise(signal, snr):
'''
signal: np.ndarray
snr: float
returns -> np.ndarray
'''
# Generate the noise as you did
noise = acoustics.generator.white(signal.size).reshape(*signal.shape)
# For the record I think np.random.random does exactly the same thing
# work out the current SNR
current_snr = np.mean(signal) / np.std(noise)
# scale the noise by the snr ratios (smaller noise <=> larger snr)
noise *= (current_snr / snr)
# return the new signal with noise
return signal + noisehttps://stackoverflow.com/questions/54323143
复制相似问题