图像可以看作许多点冲击函数的累加,图像通过系统的效果就是每一点冲激函数通过系统的响应之和
傅里叶变换只是图像正交变换的一种,正交变换同时还包括方波型变换,基于特征向量的变换等等
图像可以使用离散二维傅立叶变换,将灰度化的图像表示为频谱图。然后用二维离散傅立叶逆变换将图像复原。在这里先引一下B站up主会飞的吴克对此总结的数学公式方面的推导
首先引出傅里叶级数

1.png
对三角函数系正交性的证明

2.png
根据三角函数正交性推出各个频率ak与bk的推出法则

3.png
利用欧拉公式将傅里叶级数推至复数域

4.png
进一步化简之后得到

5.png

6.png

10.png
推出傅里叶变换对,正变换与逆变换

7.png
介绍DFT与FFT

8.png
对DFT公式进一步简化

9.png

11.png

12.png
一维傅里叶正变换
def FFT_1d(Img,axis):
Wr = np.zeros(Img.shape,dtype=complex)
if axis == 0:
Wr = np.zeros((Img.shape[0]//2,Img.shape[1]), dtype=complex)
temp = np.array([
np.cos(2*np.pi*i/Img.shape[0]) - 1j*np.sin(2*np.pi*i/Img.shape[0]) for i in range(Img.shape[0]//2)])
for i in range(Wr.shape[1]):
Wr[:,i] = temp
elif axis == 1:
Wr = np.zeros((Img.shape[0], Img.shape[1]//2), dtype=complex)
temp = np.array([
np.cos(2 * np.pi * i / Img.shape[1]) - 1j * np.sin(2 * np.pi * i / Img.shape[1]) for i in
range(Img.shape[1] // 2)])
for i in range(Wr.shape[0]):
Wr[i,:] = temp
return rawFFT(Img, Wr,axis)
一维傅里叶逆变换
def iFFT_1d(Img,axis):
Wr = np.zeros(Img.shape,dtype=complex)
if axis == 0:
Wr = np.zeros((Img.shape[0]//2,Img.shape[1]), dtype=complex)
temp = np.array([
np.cos(2*np.pi*i/Img.shape[0]) + 1j*np.sin(2*np.pi*i/Img.shape[0]) for i in range(Img.shape[0]//2)])
for i in range(Wr.shape[1]):
Wr[:,i] = temp
elif axis == 1:
Wr = np.zeros((Img.shape[0], Img.shape[1]//2), dtype=complex)
temp = np.array([
np.cos(2 * np.pi * i / Img.shape[1]) + 1j * np.sin(2 * np.pi * i / Img.shape[1]) for i in
range(Img.shape[1] // 2)])
for i in range(Wr.shape[0]):
Wr[i,:] = temp
return rawFFT(Img, Wr,axis)*(1.0/Img.shape[axis])
二维傅里叶正变换
def FFT_2d(Img):
'''
only for gray scale 2d-img. otherwise return 0 img with the same size of Img
:param Img: img to be fourior transform
:return: img been transformed
'''
imgsize = Img.shape
pic = np.zeros(imgsize, dtype=complex)
if len(imgsize) == 2:
N = 2
while N < imgsize[0]:
N = N << 1
num1 = N - imgsize[0]
N = 2
while N < imgsize[1]:
N = N << 1
num2 = N - imgsize[1]
pic = FFT_1d(np.pad(Img, ((num1 // 2, num1 - num1 // 2), (0, 0)), 'edge'), 0)[
num1 // 2:num1 // 2 + imgsize[0], :]
pic = FFT_1d(np.pad(pic, ((0, 0), (num2 // 2, num2 - num2 // 2)), 'edge'), 1)[:,
num2 // 2:num2 // 2 + imgsize[1]]
return pic
二维傅里叶逆变换
def iFFT_2d(Img):
'''
only for gray scale 2d-img. otherwise return 0 img with the same size of Img
:param Img: img to be fourior transform
:return: img been transformed
'''
imgsize = Img.shape
pic = np.zeros(imgsize, dtype=complex)
if len(imgsize) == 2:
N = 2
while N < imgsize[0]:
N = N << 1
num1 = N - imgsize[0]
N = 2
while N < imgsize[1]:
N = N << 1
num2 = N - imgsize[1]
pic = iFFT_1d(np.pad(Img,((num1//2,num1-num1//2),(0,0)),'edge'),0)[num1//2:num1//2+imgsize[0],:] # ,constant_values=(255,255)
pic = iFFT_1d(np.pad(pic,((0,0),(num2//2,num2-num2//2)),'edge'),1)[:,num2//2:num2//2+imgsize[1]] # ,constant_values=(255,255)
return pic
网友评论