我想找到图像帧的能量。这就是我在 Matlab 中计算的方式。
[~,LH,HL,HH] = dwt2(rgb2gray(maskedImage),'db1'); % applying dwt
E = HL.^2 + LH.^2 + HH.^2; % Calculating the energy of each pixel.
Eframe = sum(sum(E))/(m*n); % m,n row and columns of image.
当我在 python 中为相同的图像编程时,Energy 的值显示为 170,预期为 0.7 我的程序哪里出错了请建议
#!usr/bin/python
import numpy as np
import cv2
import pywt
im = cv2.cvtColor(maskedimage,cv2.COLOR_BGR2GRAY)
m,n = im.shape
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