# 简单图像处理——傅立叶变换

import cv

def FFT(image,flag = 0):
w
= image.width
h
= image.height
iTmp
= cv.CreateImage((w,h),cv.IPL_DEPTH_32F,1)
cv.Convert(image,iTmp)
iMat
= cv.CreateMat(h,w,cv.CV_32FC2)
mFFT
= cv.CreateMat(h,w,cv.CV_32FC2)
for i in range(h):
for j in range(w):
if flag == 0:
num
= -1 if (i+j)%2 == 1 else 1
else:
num
= 1
iMat[i,j]
= (iTmp[i,j]*num,0)
cv.DFT(iMat,mFFT,cv.CV_DXT_FORWARD)
return mFFT

def FImage(mat):
w
= mat.cols
h
= mat.rows
size
= (w,h)
= cv.CreateImage(size,cv.IPL_DEPTH_8U,1)
for i in range(h):
for j in range(w):
= mat[i,j][1]/h + mat[i,j][0]/h

image
mAfterFFT
= FFT(image)
mBeginFFT
= FFT(image,1)
iAfter
= FImage(mAfterFFT)
iBegin
= FImage(mBeginFFT)

cv.ShowImage(
'image',image)
cv.ShowImage(
'iAfter',iAfter)
cv.ShowImage(
'iBegin',iBegin)

cv.WaitKey(0)

import cv

def FFT(image,flag = 0):
w
= image.width
h
= image.height
iTmp
= cv.CreateImage((w,h),cv.IPL_DEPTH_32F,1)
cv.Convert(image,iTmp)
iMat
= cv.CreateMat(h,w,cv.CV_32FC2)
mFFT
= cv.CreateMat(h,w,cv.CV_32FC2)
for i in range(h):
for j in range(w):
if flag == 0:
num
= -1 if (i+j)%2 == 1 else 1
else:
num
= 1
iMat[i,j]
= (iTmp[i,j]*num,0)
cv.DFT(iMat,mFFT,cv.CV_DXT_FORWARD)
return mFFT

def IFFT(mat):
mIFFt
= cv.CreateMat(mat.rows,mat.cols,cv.CV_32FC2)
cv.DFT(mat,mIFFt,cv.CV_DXT_INVERSE)
return mIFFt

def Restore(mat):
w
= mat.cols
h
= mat.rows
size
= (w,h)
iRestore
= cv.CreateImage(size,cv.IPL_DEPTH_8U,1)
for i in range(h):
for j in range(w):
num
= -1 if (i+j)%2 == 1 else 1
iRestore[i,j]
= mat[i,j][0]*num/(w*h)
return iRestore

def FImage(mat):
w
= mat.cols
h
= mat.rows
size
= (w,h)
# iReal = cv.CreateImage(size,cv.IPL_DEPTH_8U,1)
# iIma = cv.CreateImage(size,cv.IPL_DEPTH_8U,1)
for i in range(h):
for j in range(w):
# iReal[i,j] = mat[i,j][0]/h
# iIma[i,j] = mat[i,j][1]/h

def Filter(mat,flag = 0,num = 10):
mFilter
= cv.CreateMat(mat.rows,mat.cols,cv.CV_32FC2)
for i in range(mat.rows):
for j in range(mat.cols):
if flag == 0:
mFilter[i,j]
= (0,0)
else:
mFilter[i,j]
= mat[i,j]
for i in range(mat.rows/2-num,mat.rows/2+num):
for j in range(mat.cols/2-num,mat.cols/2+num):
if flag == 0:
mFilter[i,j]
= mat[i,j]
else:
mFilter[i,j]
= (0,0)
return mFilter

image
mFFT
= FFT(image)
mIFFt
= IFFT(mFFT)
iAfter
= FImage(mFFT)
mLP
= Filter(mFFT)
mIFFt1
=IFFT(mLP)
iLP
= FImage(mLP)
iRestore
= Restore(mIFFt1)

mHP
= Filter(mFFT,1)
mIFFt2
= IFFT(mHP)
iHP
= FImage(mHP)
iRestore2
= Restore(mIFFt2)

cv.ShowImage(
'image',image)
cv.ShowImage(
'iAfter',iAfter)
cv.ShowImage(
'iLP',iLP)
cv.ShowImage(
'iHP',iHP)
cv.ShowImage(
'iRestore',iRestore)
cv.ShowImage(
'iRestore2',iRestore2)

cv.WaitKey(0)

#### MFC数字图像处理（BMP格式读取 保存 DFT FFT 直方图 色调均化 缩放 模糊 锐化 滤镜 形态学处理 曲线 裁剪 灰度图 彩色图 自动阈值）

2014年07月23日 7.76MB 下载

#### 利用DSP实现图像的二维傅里叶变换FFT2d、IFFT以及全逆滤波、维纳滤波

2016-04-07 11:50:02

#### 数字图像处理之二维图像的傅里叶变换（1）

2017-10-11 15:18:40

#### 第10章 图像变换-图像傅里叶变换

2012-03-19 18:56:20

#### 6. 对一幅灰度图像进行离散傅里叶变换，用图像的形式显示其（中心化后的）频谱。改变频谱，在进行 反变换，观察变换前后的区别

2016-05-03 09:49:35

#### 5.14 图像频域处理

2015-02-10 20:07:21

#### 图像傅里叶变换

2015-06-09 16:49:45

#### 图像处理中的傅里叶变换

2017-04-15 19:34:01

#### 图像处理——图像的傅里叶变换

2015-11-16 17:30:22

#### matlab安装使用出错解决方案集锦

2011-12-01 12:25:44