I got ValueError: operands could not be broadcast together with shapes (194,259,3) (600,800,3) with the below code:

import numpy 
import math
import cv2
original = cv2.imread("original.png")
contrast = cv2.imread("compressed.png",1)
def psnr(img1, img2):
    mse = numpy.mean( (img1 - img2) ** 2 )
    if mse == 0:
        return 100
    PIXEL_MAX = 255.0
    return 20 * math.log10(PIXEL_MAX / math.sqrt(mse))


What was the problem with the implementation?


1 Answer 1


It sounds like the error is indicating that the two images aren't the same size. So you can't subtract them point for point.


Not the answer you're looking for? Browse other questions tagged or ask your own question.