此页面上的内容需要较新版本的 Adobe Flash Player。

获取 Adobe Flash Player

第二章  第二题答案

答:傅立叶变换

help fourier 
FOURIER Fourier integral transform.
    F = FOURIER(f) is the Fourier transform of the sym scalar f
    with default independent variable x.  The default return is
    a function of w.
    If f = f(w), then FOURIER returns a function of t:  F = F(t).
    By definition, F(w) = int(f(x)*exp(-i*w*x),x,-inf,inf), where
    the integration above proceeds with respect to x (the symbolic
    variable in f as determined by FINDSYM).
 
    F = FOURIER(f,v) makes F a function of the sym v instead of 
        the default w:
    FOURIER(f,v) <=> F(v) = int(f(x)*exp(-i*v*x),x,-inf,inf).
 
    FOURIER(f,u,v) makes f a function of u instead of the
        default x. The integration is then with respect to u.
    FOURIER(f,u,v) <=> F(v) = int(f(u)*exp(-i*v*u),u,-inf,inf).
 
    Examples:
     syms t v w x
     fourier(1/t)   returns   i*pi*(Heaviside(-w)-Heaviside(w))
     fourier(exp(-x^2),x,t)   returns   pi^(1/2)*exp(-1/4*t^2)
     fourier(exp(-t)*sym('Heaviside(t)'),v)   returns   1/(1+i*v)

     fourier(diff(sym('F(x)')),x,w)   returns   i*w*fourier(F(x),x,w)

离散余弦变换

function Jpeg
I=imread('D:\MATLAB7\toolbox\images\imdemos\cameraman.tif');
%该图片在安装matlab的目录中找,原图为灰度图象 
I=im2double(I);%图像存储类型转换 
T=dctmtx(8);%离散余弦变换矩阵 
B=blkproc(I,[8 8],'P1*x*P2',T,T');
%对原图像进行DCT变换 
mask=[1 1 1 1 0 0 0 0
      1 1 1 0 0 0 0 0
      1 1 0 0 0 0 0 0
      1 0 0 0 0 0 0 0
      0 0 0 0 0 0 0 0
      0 0 0 0 0 0 0 0
      0 0 0 0 0 0 0 0
      0 0 0 0 0 0 0 0];
B2=blkproc(B,[8 8],'P1.*x',mask);
%数据压缩,丢弃右下角高频数据 
I2=blkproc(B2,[8 8],'P1*x*P2',T',T);
%进行DCT反变换,得到压缩后的图像 
imshow(I)
title('原始图像')
figure;
imshow(I2)

title('压缩后的图像')

小波变换

clear;clc;
%%%%%%%%%%测试图像只能是方形图像,长宽像素一样。 
f=imread('Lena.bmp');%%读取图像数据,图像只能保存在m文件所在的路径下 
d=size(f);
if length(d)>2
    f=rgb2gray((f));%%%%%%%%如果是彩色图像则转化为灰度图 
end
T=d(1);
SUB_T=T/2;
%  2.进行二维小波分解 
l=wfilters('db10','l');    %  db10(消失矩为10)低通分解滤波器冲击响应(长度为20) 
L=T-length(l);
l_zeros=[l,zeros(1,L)];    %  矩阵行数与输入图像一致,为2的整数幂 
h=wfilters('db10','h');    %  db10(消失矩为10)高通分解滤波器冲击响应(长度为20) 
h_zeros=[h,zeros(1,L)];    %  矩阵行数与输入图像一致,为2的整数幂 
for i=1:T;   %  列变换 
    row(1:SUB_T,i)=dyaddown( ifft( fft(l_zeros).*fft(f(:,i)') ) ).';    %  圆周卷积<->FFT
    row(SUB_T+1:T,i)=dyaddown( ifft( fft(h_zeros).*fft(f(:,i)') ) ).';  %  圆周卷积<->FFT
end;
for j=1:T;   %  行变换 
    line(j,1:SUB_T)=dyaddown( ifft( fft(l_zeros).*fft(row(j,:)) ) );    %  圆周卷积<->FFT
    line(j,SUB_T+1:T)=dyaddown( ifft( fft(h_zeros).*fft(row(j,:)) ) );  %  圆周卷积<->FFT
end;
decompose_pic=line;  %  分解矩阵 
%  图像分为四块 
lt_pic=decompose_pic(1:SUB_T,1:SUB_T);      %  在矩阵左上方为低频分量--fi(x)*fi(y)
rt_pic=decompose_pic(1:SUB_T,SUB_T+1:T);    %  矩阵右上为--fi(x)*psi(y)
lb_pic=decompose_pic(SUB_T+1:T,1:SUB_T);    %  矩阵左下为--psi(x)*fi(y)
rb_pic=decompose_pic(SUB_T+1:T,SUB_T+1:T);  %  右下方为高频分量--psi(x)*psi(y)
%  3.分解结果显示 
figure(1);
subplot(2,1,1);
imshow(f,[]);  %  原始图像  
title('original pic');
subplot(2,1,2);
image(abs(decompose_pic));  %  分解后图像 
title('decomposed pic');
figure(2);
% colormap(map);
subplot(2,2,1);
imshow(abs(lt_pic),[]);  %  左上方为低频分量--fi(x)*fi(y)
title('\Phi(x)*\Phi(y)');
subplot(2,2,2);
imshow(abs(rt_pic),[]);  %  矩阵右上为--fi(x)*psi(y)
title('\Phi(x)*\Psi(y)');
subplot(2,2,3);
imshow(abs(lb_pic),[]);  %  矩阵左下为--psi(x)*fi(y)
title('\Psi(x)*\Phi(y)');
subplot(2,2,4);
imshow(abs(rb_pic),[]);  %  右下方为高频分量--psi(x)*psi(y)
title('\Psi(x)*\Psi(y)');
%  5.重构源图像及结果显示 
% construct_pic=decompose_matrix'*decompose_pic*decompose_matrix;
l_re=l_zeros(end:-1:1);   %  重构低通滤波 
l_r=circshift(l_re',1)';  %  位置调整 
h_re=h_zeros(end:-1:1);   %  重构高通滤波 
h_r=circshift(h_re',1)';  %  位置调整 
top_pic=[lt_pic,rt_pic];  %  图像上半部分 
t=0;
for i=1:T;  %  行插值低频 
    if (mod(i,2)==0)
        topll(i,:)=top_pic(t,:); %  偶数行保持 
    else
        t=t+1;
        topll(i,:)=zeros(1,T);   %  奇数行为零 
    end
end;
for i=1:T;  %  列变换 
    topcl_re(:,i)=ifft( fft(l_r).*fft(topll(:,i)') )';  %  圆周卷积<->FFT
end;
bottom_pic=[lb_pic,rb_pic];  %  图像下半部分 
t=0;
for i=1:T;  %  行插值高频 
    if (mod(i,2)==0)
        bottomlh(i,:)=bottom_pic(t,:);  %  偶数行保持 
    else
        bottomlh(i,:)=zeros(1,T);       %  奇数行为零 
        t=t+1;
    end 
end