Image similarity evaluation: SSIM, PSNR, MES, python code implementation

SSIM: The closer the value is to 1, the more similar the image
is PSNR: The larger the PSNR, the less distortion and the better the quality of the generated image
MES: The smaller the MSE value, the more similar the image

Environment installation:

pip install scikit-image
from skimage.metrics import structural_similarity as compare_ssim
from skimage.metrics import peak_signal_noise_ratio as compare_psnr
from skimage.metrics import mean_squared_error as compare_mse
import cv2
import os


def getSimi(img1,img2):
    print(img1.shape)
    print(img2.shape)
    # ssim = compare_ssim(img1, img2, multichannel=True)
    ssim = compare_ssim(img1, img2, channel_axis=-1)
    psnr = compare_psnr(img1, img2)
    mse = compare_mse(img1, img2)
    return ssim, psnr,mse

img1 = cv2.imread(img_path)
img1 = cv2.resize(img1, (512, 512), interpolation=cv2.INTER_AREA)  #resize images
ssim, psnr,mse = getSimi(img1,source_img)

It should be noted that the calculation of these similarity evaluation indicators requires that the images have the same shape.

Guess you like

Origin blog.csdn.net/NGUever15/article/details/130974571