0
点赞
收藏
分享

微信扫一扫

【OpenCV 完整例程】73. 二维连续傅里叶变换

【OpenCV 完整例程】73. 二维连续傅里叶变换

2.1 二维连续傅里叶变换

f ( t , z ) f(t,z) f(t,z) 是二维连续变量 t , z t, z t,z 的连续函数,则其二维连续傅里叶变换和逆变换为:

F ( μ , ν ) = ∫ − ∞ + ∞ ∫ − ∞ + ∞ f ( t , z ) e − j 2 π ( μ t + ν z ) d t   d z f ( t , z ) = ∫ − ∞ + ∞ ∫ − ∞ + ∞ F ( μ , ν ) e j 2 π ( μ t + ν z ) d μ   d ν \begin{aligned} F(\mu,\nu) &= \int_{-\infty}^{+\infty} \int_{-\infty}^{+\infty} f(t,z) e^{-j 2\pi (\mu t + \nu z)} dt \ dz\\ f(t,z) &= \int_{-\infty}^{+\infty} \int_{-\infty}^{+\infty} F(\mu,\nu) e^{j 2\pi (\mu t + \nu z)} d\mu \ d\nu \end{aligned} F(μ,ν)f(t,z)=++f(t,z)ej2π(μt+νz)dt dz=++F(μ,ν)ej2π(μt+νz)dμ dν
对于图像处理,式中的 t , z t, z t,z 表示连续空间变量, μ , ν \mu, \nu μ,ν 表示连续频率变量。


例程 8.7:二维连续函数的傅里叶变换(二维盒式函数)

以盒式函数为例,其傅里叶变换为:

F ( μ , ν ) = ∫ − ∞ + ∞ ∫ − ∞ + ∞ f ( t , z ) e − j 2 π ( μ t + ν z ) d t   d z = ∫ − T / 2 + T / 2 ∫ − Z / 2 + Z / 2 A e − j 2 π ( μ t + ν z ) d t   d z = A T Z [ s i n ( π μ T ) π μ T ] [ s i n ( π ν Z ) π ν Z ] \begin{aligned} F(\mu,\nu) &= \int_{-\infty}^{+\infty} \int_{-\infty}^{+\infty} f(t,z) e^{-j 2\pi (\mu t + \nu z)} dt \ dz\\ &= \int_{-T/2}^{+T/2} \int_{-Z/2}^{+Z/2} A e^{-j 2\pi (\mu t + \nu z)} dt \ dz\\ &= ATZ[\frac{sin(\pi \mu T)}{\pi \mu T}][\frac{sin(\pi \nu Z)}{\pi \nu Z}] \end{aligned} F(μ,ν)=++f(t,z)ej2π(μt+νz)dt dz=T/2+T/2Z/2+Z/2Aej2π(μt+νz)dt dz=ATZ[πμTsin(πμT)][πνZsin(πνZ)]

    # 8.7:二维连续函数的傅里叶变换(二维盒式函数)
    # 二维盒式函数 (2D-Box_function)
    t = np.arange(-5, 5, 0.1)  # start, end, step
    z = np.arange(-5, 5, 0.1)
    height, width = len(t), len(z)
    tt, zz = np.meshgrid(t, z)  # 将一维数组 xnew, ynew 转换为网格点集(二维数组)

    f = np.zeros([len(t), len(z)])  # 初始化,置零
    f[30:70, 30:70] = 1  # 二维盒式函数

    fu = np.sinc(t)
    fv = np.sinc(z)
    fuv = np.outer(np.sinc(t), np.sinc(z))  # 由公式计算连续傅里叶变换
    print(fu.shape, fv.shape, fuv.shape)

    fig = plt.figure(figsize=(10, 6))
    ax1 = plt.subplot(121, projection='3d')
    ax1.set_title("2D-Box function")
    ax1.plot_wireframe(tt, zz, f, rstride=2, cstride=2, linewidth=0.5, color='c')
    ax1.set_xticks([]), ax1.set_yticks([]), ax1.set_zticks([])
    ax2 = plt.subplot(122, projection='3d')
    ax2.set_title("2D-Fourier transform")
    ax2.plot_wireframe(tt, zz, fuv, rstride=2, cstride=2, linewidth=0.5, color='c')
    ax2.set_xticks([]), ax2.set_yticks([]), ax2.set_zticks([])
    plt.show()

在这里插入图片描述


例程 8.8:二维连续函数的傅里叶变换(不同参数的盒式函数)

    # 8.8:二维连续函数的傅里叶变换(不同参数的盒式函数)
    # 二维盒式函数 (2D-Box_function)
    height, width = 128, 128
    m = int((height - 1) / 2)
    n = int((width - 1) / 2)

    fig = plt.figure(figsize=(9, 6))
    T = [5, 10, 20]
    print(len(T))
    for i in range(len(T)):
        f = np.zeros([height, width])  # 初始化,置零
        f[m-T[i]:m+T[i], n-T[i]:n+T[i]] = 1  # 不同尺寸的盒式函数
        fft = np.fft.fft2(f)
        shift_fft = np.fft.fftshift(fft)
        amp = np.log(1 + np.abs(shift_fft))

        plt.subplot(2,len(T),i+1), plt.xticks([]), plt.yticks([])
        plt.imshow(f, "gray"), plt.title("Box Filter (T={})".format(T[i]))
        #
        plt.subplot(2,len(T),len(T)+i+1), plt.xticks([]), plt.yticks([])
        plt.imshow(amp, "gray"), plt.title("FFT Spectrum")

    plt.tight_layout()
    plt.show()

在这里插入图片描述



(本节完)


版权声明:

youcans@xupt 原创作品,转载必须标注原文链接

Copyright 2021 youcans, XUPT

Crated:2022-1-15


举报

相关推荐

0 条评论