Paga
Paga

Reputation: 103

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

i am trying to calculate the MSE in order to gain the output of 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)

I encounter a weird situation while i use for loop to calculate 1~6 pictures it appears 'numpy.float64' object is not callable on 2~6 pictures enter image description here

However when I change str(i) into number such as 2,3... it works i have no idea what is going on please help me

you can see form the pictures above that console show the first output of the loop while the following are encounter 'numpy.float64' object is not callable

However i simply change str(i) into 2,3 and so on it works?? enter image description here

Upvotes: 0

Views: 343

Answers (1)

John Gordon
John Gordon

Reputation: 33335

You define a function named mse(), but later on you call this line of code:

mse=mse(result,recover)

In doing so, you have redefined mse to be something else, and it isn't a function anymore.

Use a different name for storing the result of calling mse().

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

Upvotes: 1

Related Questions