如何使用Python计算图像的能量?

时间:2019-03-28 11:11:11

标签: python opencv dwt pywt

我正在尝试计算图像的能量。我想使用python。我从网站上获得了一个解决方案,但是有一个 有点让发布问题的人感到困惑,就是告诉他程序的输出与Matlab相比是错误的。

I referred this link  我已经尝试了这两个代码,但是给出了相同的答案。

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)

此代码给出的输出为0.5311041623967175,下一个代码为

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)

此代码还提供了相同的输出0.5311041623967174

所以我很困惑是对还是错。

代码输出的屏幕截图 Screenshot of code output

试图从中计算能量的图像 Image attempting to calculate energy from

0 个答案:

没有答案