【问题标题】:How to estimate motion with FTT and Cross-Correlation?如何使用 FTT 和互相关估计运动?
【发布时间】:2020-04-09 04:34:14
【问题描述】:

我正在使用 RGB GOES 卫星图像估计用于风能目的的云位移。我从这篇论文“使用互相关从地球同步卫星数据中获取云运动的自动化技术”中找到了以下方法来实现它。我不知道这是否是计算它的好方法。该代码基本上从傅立叶变换中获取互相关,以计算roi_aroi_b 图像之间的云位移。

import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt

img_a = cv.imread('2019.1117.1940.goes-16.rgb.tif', 0)
img_b = cv.imread('2019.1117.1950.goes-16.rgb.tif', 0)

roi_a = img_a[700:900, 1900:2100]
roi_b = img_b[700:900, 1900:2100]

def Fou(image):
    fft_roi= np.fft.fft2(image)
    return fft_roi

def inv_Fou(C_w):
    c_t = np.fft.ifft2(C_w)
    c_t = np.abs(c_t)
    return c_t

#Step 1: gets the FFT
G_t0 = Fou(roi_a)##t_0    
fft_roiA_conj = np.conj(G_t0) #Conjugate
G_t1 = Fou(roi_b)##t_1

#Step 2: Compute C(m, v)
prod = np.dot(fft_roiA_conj, G_t1)

#Step 3: Perform the inverse FFT
inv = inv_Fou(prod)

plt.imshow(inv, cmap = 'gray', )
plt.title('C (m,v) --> Cov(p,q)')
plt.xticks([])
plt.yticks([]) 
plt.show()

#Step 4: Compute cross correlation coefficient and the maximum cross correlation coefficient
def rms(sigma):
    "Compute the standar deviation of an image"
    rms = np.std(sigma)
    return rms

R_t = inv / (rms(roi_a) * rms(roi_b))  

这是我第一次在图像上使用 FFT,所以我对此有一些疑问:

  • 我不加fftshift,会不会影响结果?
  • 在第 2 步中使用 np.dot 和简单的 '*' 有什么区别,例如 prod = fft_roiA_conj * G_t1
  • 如何解释第 3 步的图像结果 (C(m, v) -> Cov (p, q))?
  • 如何从R_t获取最大系数p'和q'(x和y方向的最大系数)?

【问题讨论】:

    标签: python image-processing fft cross-correlation


    【解决方案1】:

    1 - fftshift 是一个圆形旋转,如果你有一个两侧的信号,你正在计算相关性被移动(循环),重要的是你正确地将你的索引映射到位移,有或没有fftshift .

    2 - numpy.dot 是矩阵乘积(相当于最近的 python 版本的 @ 运算符),* 运算符执行元素乘法,据我了解,您希望在第 2 步得到元素乘积.

    3 - 一旦您更正了第 2 步,您将拥有一个图像,使得 inv[i, j] 图像 roi_a 和图像 roi_b 滚动的相关性由 i 行和 j 列滚动

    为了回答最后一个问题,我将举一个例子。

    我将使用图像scipy.misc.face,它是一个RGB图像,所以它带来了三个高度相关的矩阵。

    import scipy
    import numpy as np
    import matplotlib.pyplot as plt
    
    f = scipy.misc.face()
    plt.figure(figsize=(12, 4))
    plt.subplot(131), plt.imshow(f[:,:, 0])
    plt.subplot(132), plt.imshow(f[:,:, 1])
    plt.subplot(133), plt.imshow(f[:,:, 2])
    

    函数img_corr结合了互相关的三个步骤(对于相同大小的图像),注意我使用rfft2irfft2,这是真实数据的FFT,利用频域对称。

    def img_corr(foi_a, foi_b):
        return np.fft.irfft2(np.fft.rfft2(foi_a) * np.conj(np.fft.rfft2(foi_b)))
    
    C = img_corr(f[:,:,1], f[:,:,2])
    plt.figure(figsize=(12, 4))
    plt.subplot(121), plt.imshow(C), plt.title('FFT indices')
    plt.subplot(122), plt.imshow(np.fft.fftshift(C, (0, 1))), plt.title('fftshift ed version')
    

    检索位置

    # this returns the indice in the vector of all pixels
    best_corr = np.argmax(C)
    # unravel index gives the 2D index
    best_pos = np.unravel_index(best_corr, C.shape)
    
    # this get the positions as a fraction of the image size
    relative_pos = [np.fft.fftfreq(size)[index] for index, size in zip(best_pos, C.shape)]
    

    我希望这可以完成答案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-10
      • 2012-12-27
      • 1970-01-01
      • 1970-01-01
      • 2018-09-11
      • 2018-07-21
      • 2014-03-06
      • 2021-04-29
      相关资源
      最近更新 更多