我正在尝试计算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张图片时遇到奇怪的情况
在2〜6张图片上似乎无法调用'numpy.float64'对象
但是,当我将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)
关于python - 'numpy.float64'对象的特殊条件不可调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55186383/