图像处理 之 一维快速傅里叶变换(FFT)

# -*- coding: utf-8 -*-
"""
Created on Sun Jul  8 21:05:51 2018

@author: Diko
"""

import numpy

def FFT_v1(Img,Wr):
    if Img.shape[0]==2:
        pic = numpy.zeros([2],dtype=complex)
        pic = pic*(1+0j)
        pic[0]=Img[0]+Img[1]*Wr[0]
        pic[1]=Img[0]-Img[1]*Wr[0]
        return pic
    else:
        pic = numpy.empty([Img.shape[0]],dtype=complex)
        pic[0:Img.shape[0]//2] = FFT_v1(Img[::2],Wr[::2])+Wr*FFT_v1(Img[1::2],Wr[::2])
        pic[Img.shape[0]//2:Img.shape[0]]=FFT_v1(Img[::2],Wr[::2])-Wr*FFT_v1(Img[1::2],Wr[::2])
        return pic;


def FFT_1d(Img):
    Wr = numpy.ones([Img.shape[0]//2])*[numpy.cos(2*numpy.pi*i/Img.shape[0])-1j*numpy.sin(2*numpy.pi*i/Img.shape[0]) for i in numpy.arange(Img.shape[0]/2)]
    return FFT_v1(Img,Wr)

 

你可能感兴趣的:(图像处理)