计算SNR

import cv2
import numpy as np

def calculate_snr(image):
    # 读取图像
    img = cv2.imread(image, cv2.IMREAD_GRAYSCALE)
    
    # 计算信号功率
    signal_power = np.mean(img) ** 2
    
    # 计算噪声功率
    noise = img - np.mean(img)
    noise_power = np.mean(noise ** 2)
    
    # 计算信噪比(SNR)
    snr = 10 * np.log10(signal_power / noise_power)
    
    return snr

# 图片路径
image_path = "your_image.jpg"

# 计算图像的信噪比
snr_value = calculate_snr(image_path)
print("SNR of the image:", snr_value)

你可能感兴趣的:(人工智能)