初探FFT在数字图像处理中的应用
一般FFT在通信等领域都做的一维变换就可以了,但是在图像处理方面,需要做二维变换,这个时候就需要用到FFT2.
在利用Octave(或者matlab)里面的fft2()函数的时候,观察频率领域的图像还是要点额外的技巧的.下面的图像是我们想要的,也是我们人类才可以理解的(图片的中心表示低频区域,越是远离中心,频率越高,这里下面图片中,中心区域很亮,value很高,中心周围越来越暗,表示低频信号强,高频信号慢慢减弱)
>> result = fft2(dark_channel);
>> imshow(uint8(real(result)));
直接输出fft2的结果如下(正常人应该看不出什么吧~)
怎么得到之前我们给出的结果呢?
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % code writer : EOF % code date : 2014.09.27 % code file : fft2_demo.m % e-mail : [email protected] % % If there is something wrong with my code, please % touch me by e-mail. Thank you :) % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% clear all clc Original_img = imread('/home/jasonleaster/Picture/hand.png'); float_Orignal_img = double(Original_img); F64_WHITE = 255.0; F64_BLACK = 0.000; Original_img_row = size(Original_img,1); Original_img_col = size(Original_img,2); Original_img_channel = size(Original_img,3); for row = 1:Original_img_row for col = 1:Original_img_col min_piexl = F64_WHITE; for channel = 1: Original_img_channel if(min_piexl > Original_img(row,col,channel)) min_piexl = Original_img(row,col,channel); end end dark_channel(row,col) = min_piexl; end end result = fft2(dark_channel); %spectrum = fftshift(abs(result)); spectrum = result; figure(1); spectrum = spectrum*255/max(spectrum(:)); imshow(spectrum);
这里一定记得fftshift,不然会出现下面的结果,低频结果分散在四个角落
正确结果如下
时间: 2024-10-09 19:46:06