ref=参考np数组
meas=要与之比较的np数组
创建numpy数组的直方图[[data][weights]],并将其转换为[data[i],weight[i]]格式。然后转换到一个cv数组,然后将其转换为EMD函数的信号函数。在
这不是一个理想的解决方案-任何进一步的改进/建议将不胜感激为教育目的!!!在#reference array:
j = np.histogramdd(ref, bins = 80)
a = np.zeros((len(j[0]), 2))
for i, x in enumerate(j[0]):
a[i][0] = x
a[i][1] = j[1][0][i]
cv_array_ref = cv2.cv.fromarray(a)
a32 = cv2.cv.CreateMat(cv_array_ref.rows, cv_array_ref.cols,cv2.cv.CV_32FC1)
cv2.cv.Convert(cv_array_ref, a32)
#measured array:
jj = np.histogramdd(amplitude_norm_data[0], bins = 80)
aa = np.zeros((len(jj[0]), 2))
for ii, xx in enumerate(jj[0]):
aa[ii][0] = xx
aa[i][1] = jj[1][0][ii]
cv_array_meas = cv2.cv.fromarray(aa)
a322 = cv2.cv.CreateMat(cv_array_meas.rows, cv_array_meas.cols, cv2.cv.CV_32FC1)
cv2.cv.Convert(cv_array_meas, a322)
cv2.cv.CalcEMD2(a32, a322,cv2.cv.CV_DIST_L1)