【发布时间】:2020-06-17 20:04:23
【问题描述】:
我想使用 de Fast Fourier Transform 计算互相关,以便按照下图的步骤进行云运动跟踪。
def roi_image(image):
image = cv.imread(image, 0)
roi = image[700:900, 1900:2100]
return roi
def FouTransf(image):
img_f32 = np.float32(image)
d_ft = cv.dft(img_f32, flags = cv.DFT_COMPLEX_OUTPUT)
d_ft_shift = np.fft.fftshift(d_ft)
rows, cols = image.shape
opt_rows = cv.getOptimalDFTSize(rows)
opt_cols = cv.getOptimalDFTSize(cols)
opt_img = np.zeros((opt_rows, opt_cols))
opt_img[:rows, :cols] = image
crow, ccol = opt_rows / 2 , opt_cols / 2
mask = np.zeros((opt_rows, opt_cols, 2), np.uint8)
mask[int(crow-50):int(crow+50), int(ccol-50):int(ccol+50)] = 1
f_mask = d_ft_shift*mask
return f_mask
def inv_FouTransf(image):
f_ishift = np.fft.ifftshift(image)
img_back = cv.idft(f_ishift)
img_back = cv.magnitude(img_back[:, :, 0], img_back[:, :, 1])
return img_back
def rms(sigma):
rms = np.std(sigma)
return rms
# Step 1: Import images
a = roi_image(path_a)
b = roi_image(path_b)
# Step 2: Convert the image to frequency domain
G_t0 = FouTransf(a)
G_t0_conj = G_t0.conj()
G_t1 = FouTransf(b)
# Step 3: Compute C(m, v)
C = G_t0_conj * G_t1
# Step 4: Convert the image to space domain to obtain Cov (p, q)
c_w = inv_FouTransf(C)
# Step 5: Compute Cross correlation
R_pq = c_w / (rms(a) * rms(b))
我有点困惑,因为我从未使用过这种技术。 ¿ 应用程序准确吗?
提示:eq (1) 是:R(p,q) = Cov(p,q) / (sigma_t0 * sigma_t1)。如果需要更多信息,请参阅论文:“一种自动化技术或使用互相关从地球静止卫星数据中获取云运动”。
我找到了this 来源,但我不知道我是否正在尝试做某事。
【问题讨论】:
-
这是convolution theorem 的示例,是的,它是正确的。不确定 OpenCV,但 Scipy 已经实现了这个:
scipy.signal.correlate。 -
我注意到您在 Stackoverflow 上提出了几个问题,但都忘记了单击答案附近的复选框以将其选为官方问题解决者。这种机制的存在是为了帮助未来的访问者更快地找到他们的答案。请花时间检查您的所有问题并执行此操作:单击帮助您解决特定问题的答案附近的复选框。通过跟上网站的运作方式,您不仅可以帮助网站保持井井有条,还可以增加其他人在未来再次帮助您的机会。
标签: python image-processing fft cross-correlation