2

我想在具有不同 SNR 级别的原始图像中添加白噪声,但不知道该怎么做。

原始图像是(256, 128)我正在使用acoustics包添加噪声。

original = cv2.imread(path)
white = acoustics.generator.white(256*128).reshape(256, 128)
out = original + white*255

cv2.imwrite(path, out)

我的问题:

  1. log10(mean(original)/ std(original + white*255))算作 SNR 吗?(根据wiki

  2. 如果是这样,我可以只修改*255这个数字来修改 SNR 吗?

  3. 如果不是,我如何计算 SNR 值?

4

1 回答 1

1

关键事实是(这是数学,不是代码)

SNR = mean(s) / std(n)

将噪声乘以某个常数A会得到一个新的 SNR——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 + noise
于 2019-01-23T09:02:39.913 回答