基于 FFT 的关联,使用 numpy 覆盖图像和模板(内核映像)



我正在尝试计算图像与模板图像的相关性。(一些类似 ref 链接:https://www.mathworks.com/examples/image/mw/images-ex92197313-perform-fft-based-correlation-to-locate-image-features(在代码片段下方。

img = cv2.imread ("/home/engineer/Desktop/Ai/tracking/KCFpy_learning/demoimags/text.png", 0) #grayscale image read
a = img[32:45,88:98]
a_rot = np.rot90(a, 2)
def pad_with(vector, pad_width, iaxis, kwargs):
pad_value = kwargs.get('padder', 0)
# print("val : ", pad_value, ", width : ", pad_width)
vector[:pad_width[0]] = pad_value
vector[-pad_width[1]:] = pad_value
return vector
reshape_a = np.pad(a_rot, 123, pad_with)
reshape_a = cv2.resize(reshape_a, (img.shape), interpolation = cv2.INTER_CUBIC)
print("shape : ", img.shape, " , resh : ", reshape_a.shape)
dft_img = cv2.dft(np.float32(img), flags = cv2.DFT_COMPLEX_OUTPUT)
dft_templ_img = cv2.dft(np.float32(reshape_a), flags = cv2.DFT_COMPLEX_OUTPUT)
conv_res = cv2.mulSpectrums(dft_img, dft_templ_img, 0, conjB=False)
img_back = cv2.idft(conv_res)
real = img_back[:,:,0]
r = np.max(real)
print("max val : ", r)
cv2.imshow("real_part", real)

来自真实值的最大值非常。 如何验证我的输出? 或者是否有其他方法可以确定频域中图像和模板之间最可能的相关性。

谢谢 维维克·

尝试使用 OpenCV 和 phaseCorrelate。

最新更新