作者:曾维
图像处理,使用时注意 :
如下图图片进行处理,读者可以将该图片保存下来,再进行如下处理。笔者试过,有些图片不存在本文所说的问题。
rgbfile=imread('1.png');
grayfile=rgb2gray(rgbfile);
subplot(2,2,1);
imshow(grayfile);%显示刚输入的图片的灰度图
Ft=fft2(grayfile);%进行ft变换
iFt=real(ifft2(Ft));%进行反变换
subplot(2,2,2);
imshow(iFt,[ ]);%显示复原的图片,可结果却不是原图片
可结果却不是原图片,这是为什么呢?理论上说经过fft2变换后再反变换(ifft2)是可以完全复原图像的。我们再来看看问题出在哪了。
不防先拿一个小的矩阵来试试
A=uint8(magic(3))%模拟图片矩阵,256灰度级
B=ifft2(fft2(A))
A =
8 1 6
3 5 7
4 9 2
B =
8.000000000000000e+000 1.000000000000000e+000 6.000000000000000e+000
3.000000000000000e+000 5.000000000000000e+000 7.000000000000000e+000
4.000000000000000e+000 9.000000000000000e+000 2.000000000000000e+000
可以看到,结果A与B唯一的不同点为,B是double型数据,而A是uint8型数据。
我们再来试试,将上面例子的代码最后加一个数据类型转换。
再加如下代码
iFt2=uint8(iFt);
subplot(2,2,3);
imshow(iFt2)
这下输出的图片和原灰度图看上去是一样的了。我们再验正一下。对两个图作一个差
D=abs(grayFile-iFt2);
sum(D(:));
ans =
0
结果等于0,即图片经过反变换复原了
附fft2 和ifft2在matlab 2010帮助
FFT2 Two-dimensional discrete Fourier
Transform.
FFT2(X)
returns the two-dimensional Fourier transform of matrix X.
If X is a
vector, the result will have the same orientation.
FFT2(X,MROWS,NCOLS) pads matrix X with zeros to size
MROWS-by-NCOLS
before
transforming.
Class
support for input X:
float: double, single
See also
fft, fftn, fftshift, fftw, ifft, ifft2, ifftn.
Reference
page in Help browser
doc fft2
IFFT2 Two-dimensional inverse discrete Fourier
transform.
IFFT2(F)
returns the two-dimensional inverse Fourier transform of
matrix
F. If F is a vector, the result will have the
same orientation.
IFFT2(F,MROWS,NCOLS) pads matrix F with zeros to size
MROWS-by-NCOLS
before
transforming.
IFFT2(...,
'symmetric') causes IFFT2 to treat F as conjugate symmetric
in two
dimensions so that the output is purely real. This option is
useful when
F is not exactly conjugate symmetric merely because of
round-off
error. See the reference page for the specific
mathematical
definition
of this symmetry.
IFFT2(...,
'nonsymmetric') causes IFFT2 to make no assumptions about the
symmetry of
F.
Class
support for input F:
float: double, single
See also
fft, fft2, fftn, fftshift, fftw, ifft, ifftn.
Reference
page in Help browser
doc ifft2