基于信噪比的图像加白噪声

2024-06-02 06:58:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我想添加白噪声的原始图像与不同的信噪比水平,但不知道怎么做。在

原始图像是(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))是否算作信噪比?(根据wiki

  2. 如果是这样的话,我可以修改*255这个数字来修改信噪比吗?

  3. 如果没有,如何计算信噪比值?


Tags: path图像水平outmeangeneratorcv2噪声
1条回答
网友
1楼 · 发布于 2024-06-02 06:58:29

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

SNR = mean(s) / std(n)

将噪声乘以某个常数A得到一个新的SNR SNR_new

^{pr2}$

所以向后看,我认为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

相关问题 更多 >