matlab fft2补零位置,[转载]matlab 每日学习 fft2 ifft2函数

作者:曾维

图像处理,使用时注意 :

如下图图片进行处理,读者可以将该图片保存下来,再进行如下处理。笔者试过,有些图片不存在本文所说的问题。

rgbfile=imread('1.png');a4c26d1e5885305701be709a3d33442f.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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值