我创建了一个脚本,将高斯噪声添加到图像中,如何计算该图像的SNR?
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发布于 2021-04-05 16:01:21
SNR =μ/σ
其中:μ是平均值或期望值,σ是标准差
所以..。
image_sd = np.std(noisy_img_clipped);
image_mean = np.mean(noisy_img_clipped);
image_snr = image_mean / image_sd;如果你想在dB中获得它,这可能会很棘手,因为你需要额外的常量,这取决于你正在测量的东西。如果你不知道它是什么,你可以使用1,但通常情况下,对于未知源,在dB中显示信噪比被认为是一个糟糕的方法。
import math
image_snr_db = 1 * math.log(image_snr,2);如果你问的是PSNR,等式是不同的,它需要2个图像。原始的和模糊的。使用OpenCV,你可以这样计算它:
import cv2
img1 = cv2.imread(original_image)
img2 = cv2.imread(noisy_image)
psnr = cv2.PSNR(img1, img2)https://stackoverflow.com/questions/66949839
复制相似问题