'numpy.float64' 对象的特殊条件不可调用

special condition of 'numpy.float64' object is not callable

我正在尝试计算 MSE 以获得 PSNR 的输出

def mse(imageA, imageB):
  err = np.sum((imageA.astype("float") - imageB.astype("float")) ** 2)
  err /= float(imageA.shape[0] * imageA.shape[1])
  return err

if __name__ == '__main__':

  for i in range(1,7):
      result=cv2.imread('./ct-result/tr' + str(i) + '.bmp')
      recover = cv2.imread('./rs' + str(i) + '.bmp')
      mse=mse(result,recover)
      psnr=10*math.log10((255**2)/mse)
      print(psnr)

我用for循环计算1~6张图片时遇到了奇怪的情况 看起来 'numpy.float64' 对象在 2~6 张图片上不可调用

然而,当我将 str(i) 更改为诸如 2,3 之类的数字时...它起作用了 我不知道发生了什么 请帮助我

你可以从上面的图片中看到控制台显示循环的第一个输出,而下面是遇到'numpy.float64'对象不可调用

但是我只是简单地将 str(i) 更改为 2,3 等等就可以了吗?

您定义了一个名为 mse() 的函数,但稍后您调用了这行代码:

mse=mse(result,recover)

这样做,您已经将 mse 重新定义为其他东西,它不再是一个函数。

使用不同的名称来存储调用 mse() 的结果。

mse_output = mse(result,recover)
psnr=10*math.log10((255**2)/mse_output)