图像处理-离散傅里叶变换-数字图像处理第三版第四章内容

  图像傅里叶变换方法有很多,可以通过空间光调制器输入图像后在通过平行光照明经过傅里叶变换透镜进行傅里叶变换,另一个方法就是利用计算机进行傅里叶变换,其中傅里叶变换有两种算法一种是DFT还有一种是FFT(快速傅里叶变换)。

  首先我介绍一下图像的定义,图像是怎么去得到的呢?图像是物体与点扩散函数卷积的结果加上一个噪声项(具体想了解可以查看“傅里叶光学"-吕乃光)。

  在这里我谈谈离散傅里叶变换的一些问题,以及离散傅里叶变换的MATLAB代码。首先谈谈傅里叶变换,想必大家一听到傅里叶变换整个人都不好了,傅里叶变换是做什么的呢,个人的理解就是通过无数个正交的向量去描述一个任意的曲线或者信号,最简单的理解就是我们可以通过xy直角坐标系通过一个关系建立一个二维曲线,这样我们就可以通过一个正交的向量去描述这个线上的任意一个点。

  在傅里叶变换中所谓的空间频率的高频与低频分别代表什么呢?高频代表的就是图像中灰度突变速度快的地方,说白了就是看起来密集的地方就是高频,看起来平坦的地方就是低频。这是最简单的理解方式。离散傅里叶变换可以处理任意大小的图像,FFT只能处理2^n*2^n大小的图像,当图像大小不够的时候需要填补空缺的地方。

一下为DFT函数的matlab代码,

function [out_dft_image,out_ab_dft_pic]=dft(input_image,mode)
%%  [out_dft_image,out_ab_dft_pic]=dft_test(input_image)     this function can make dft transform
% F(u-M/2,v-N/2)<=>f(x,y)*(-1).^(x+y)   or you can make dft transform like
% F(u,v)<=>f(x,y)
%     input_image:  had batter less than 150*150 large
%     mode:   if mode==1  this function is to do comfortable visable result   
%             else mode=~1 the result maybe make you uncomfortable 
%     out_dft_image: this is the complex matrix it can make the idft and
%                   get the surse image in spetial domain 
%     out_ab_dft_pic: this is the frequency spectrum picture matrix
%     design by baiyinhao 2015.9.28    20:07 Email:[email protected]
%
%     作  者:光电科技协会     2015.9.28    20:07  白银浩
%


%空域变换到频率域
pic=double(input_image);
[u_p,v_p]=size(pic);%  F(u,v)中的u,v
%f(x,y)*(-1).^(x+y)   即对原图进行一次运算
if mode==1
    
    for x=1:u_p
        for y=1:v_p
            pic(x,y)=pic(x,y)*(-1)^(x+y);%在此处对输入的pic进行了改变  即变成f(x,y)*(-1).^(x+y) 白  添加 
        end
    end
    
    %居中傅里叶变换
    [x_p,y_p]=size(pic);
    dft_pic=zeros(u_p,v_p);
    flag=0;
    temp1=0;
    for u=1:u_p
        for v=1:v_p
            for x=1:x_p
                for y=1:y_p
                    temp1=temp1+pic(x,y)*exp(-1j*2*pi*(u*x/u_p+v*y/v_p));
                end
            end
            dft_pic(u,v)=temp1;
            temp1=0;
        end
        flag=flag+1;
        sprintf('运行到了图像的第:%d 行',flag)
    end
    %输出傅里叶变换 后的实部虚部
    R_dft_pic=real(dft_pic);%求出傅里叶变换后的实部
    I_dft_pic=imag(dft_pic);%求出傅里叶变换后的虚部

    %傅里叶谱
    ab_dft_pic(u_p,v_p)=0;
    for u=1:u_p
        for v=1:v_p
            ab_dft_pic(u,v)=sqrt(R_dft_pic(u,v).^2+I_dft_pic(u,v).^2);
       end
    end
    %最后输出值 
    m_dft_pic=max(max(ab_dft_pic));
    ab_dft_pic1=ab_dft_pic/m_dft_pic*255;



else
   %正常傅里叶变换
    [x_p,y_p]=size(pic);
    dft_pic=zeros(u_p,v_p);
    flag=0;
    temp1=0;
    for u=1:u_p
        for v=1:v_p
            for x=1:x_p
                for y=1:y_p
                    temp1=temp1+pic(x,y)*exp(-1j*2*pi*(u*x/u_p+v*y/v_p));
                end
            end
            dft_pic(u,v)=temp1;
            temp1=0;
        end
        flag=flag+1;
        sprintf('运行到了图像的第:%d 行',flag)
    end
    %输出傅里叶变换 后的实部虚部 白银浩添加
    R_dft_pic=real(dft_pic);%求出傅里叶变换后的实部
    I_dft_pic=imag(dft_pic);%求出傅里叶变换后的虚部

    %傅里叶谱
    ab_dft_pic(u_p,v_p)=0;
    for u=1:u_p
        for v=1:v_p
            ab_dft_pic(u,v)=sqrt(R_dft_pic(u,v).^2+I_dft_pic(u,v).^2);
        end
    end
    %最后输出值 
    m_dft_pic=max(max(ab_dft_pic));
    ab_dft_pic1=ab_dft_pic/m_dft_pic*255;
 end


    out_dft_image=dft_pic;
    out_ab_dft_pic=uint8(ab_dft_pic1);


end

由于运行速度慢,有助于理解,如果有实际用途建议使用FFT。


2016.11.9   12:09

白银浩    

E-mail:[email protected]

Q    Q:792499178

你可能感兴趣的:(图像处理)