首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于信噪比的图像加白噪声

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

Stack Overflow用户
提问于 2019-01-23 08:43:22
回答 1查看 1.5K关注 0票数 2

我想添加白噪声到原始图像的不同信噪比水平,但不确定如何做。

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

代码语言:javascript
复制
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))算作信噪比吗?(根据维基 )
  2. 如果是这样的话,我可以修改*255这个数字来修改信噪比吗?
  3. 如果没有,如何计算信噪比值?
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-01-23 09:02:39

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

代码语言:javascript
复制
SNR = mean(s) / std(n)

将噪声乘以某些恒定的A会产生一种新的信噪比- SNR_new

代码语言:javascript
复制
mean(s) / std(A*n) 
= mean(s) / (A * std(n)) 
= (1 / A) * (mean(s) / std(n)) 
= SNR / A
= SNR_new

因此,在python中,我认为这是正确的方法是:

代码语言:javascript
复制
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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54323143

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档