[Python] How to find PSNR from two images with different size in python [closed]

Discussão em 'Python' iniciado por Stack, Julho 22, 2025.

  1. Stack

    Stack Membro Participativo

    I have 2 images, one original and other is reconstructed from the original via some processing. I want to find the PSNR for the reconstructed image The original has a size of (180, 180) but the reconstructed image has size of (71,81). I am using cv2.reshape() to reshape the reconstructed image.

    shape = 180
    reconstructed = cv2.resize(reconstructed, (shape,shape))
    reconstructed = cv2.normalize(reconstructed, None, alpha=0, beta = 255, norm_type= cv2.NORM_MINMAX, dtype=cv2.CV_32F)
    original = cv2.normalize(original, None, alpha=0, beta = 255, norm_type= cv2.NORM_MINMAX, dtype=cv2.CV_32F)
    MSE = np.mean((original - reconstructed)**2)
    PSNR = 10*np.log10(255**2/MSE)
    print(PSNR)


    Since the sizes do not match and I have to calculate PSNR, I'm afraid that there might be some alignment issues and thus it may give wrong PSNR. What can be done to do calculate the PSNR accurately?

    Continue reading...

Compartilhe esta Página