title: How to calculate energy of an image using Python?
body: <p>I am trying to calculate the energy of an image. I want to use python. I got one solution from the website but there is a 
  little bit confusing the person who posted the question is telling output of his program is the wrong to compare to Matlab.</p>
  
  <p><a href="https://stackoverflow.com/questions/37971371/calculating-energy-of-image-frame-using-dwt-in-python-shows-wrong-value">I referred this link</a>
   I have tried both of this code but giving the same answer.</p>
  
  <pre><code>import cv2
  from pywt import dwt2
  import pywt
  import numpy as np
  img=cv2.imread("/home/raviraj/PycharmProjects/Diabetic/SYMPTOMS/1369_right.jpeg")
  im = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  _, (cH, cV, cD) = dwt2(im.T, 'db1')
  # a - LL, h - LH, v - HL, d - HH as in matlab
  Energy = (cH**2 + cV**2 + cD**2).sum()/im.size
  
  print(Energy)
  </code></pre>
  
  <p>this code giving output 0.5311041623967175 and next code is </p>
  
  <pre><code>im = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
  m,n = im.shape
  print(im.shape)
  print(m)
  print(n)
  cA, (cH, cV, cD) = pywt.dwt2(im,'db1')
  # a - LL, h - LH, v - HL, d - HH as in matlab
  cHsq = [[elem * elem for elem in inner] for inner in cH]
  cVsq = [[elem * elem for elem in inner] for inner in cV]
  cDsq = [[elem * elem for elem in inner] for inner in cD]
  Energy = (np.sum(cHsq) + np.sum(cVsq) + np.sum(cDsq))/(m*n)
  print (Energy)
  </code></pre>
  
  <p>this code is also giving same output <code>0.5311041623967174</code>.</p>
  
  <p>So I am confused is it right or wrong.  </p>
  
  <p>Screenshot of code output
  <a href="https://i.stack.imgur.com/3pIr0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3pIr0.png" alt="Screenshot of code output"></a></p>
  
  <p>Image attempting to calculate energy from
  <a href="https://i.stack.imgur.com/ycyoY.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ycyoY.jpg" alt="Image attempting to calculate energy from"></a></p>