我创建了一个脚本,将高斯噪声添加到图像中,如何计算该图像的信噪比
def noisy(img,sigma): # noise function
# ...
img = np.asarray(img,'double') # numpy-array of shape (N, M);
embeadead_line = img[0] # first line/row should not be changed
img = np.delete(img, (0), axis=0)
mean = 0.0 # some constant
std = sigma # some constant (standard deviation)double
noisy_img = img + np.random.normal(mean, std, img.shape).astype(np.double)
noisy_img_clipped = np.clip(noisy_img, 0, 255).astype(np.uint8) # we might get out of bounds due to noise
noisy_img_clipped = np.insert(noisy_img_clipped, 0, embeadead_line, 0) # insert embedead line back
return noisy_img_clipped
信噪比=μ/σ
其中:
μ
是平均值或期望值,σ
是标准偏差所以
如果你想得到dB,这可能会很棘手,因为你需要额外的常数,这取决于你测量的是什么。如果您不知道它是什么,您可以使用1,但对于未知源,通常以dB为单位显示SNR被认为是一种不好的方法
如果你问的是PSNR,等式是不同的,它需要2张图像。原来的和模糊的。使用OpenCV,您可以这样计算:
相关问题 更多 >
编程相关推荐