图像小波变换的Matlab代码:
clc; clear; close all; Xa =[40,10,56,46]; % 56*2=112,46*2-92(图片分辨率为112*92) Xh =[40,10,56,46]; Xv =[40,10,56,46]; Xd =[40,10,56,46]; for i = 1:40 % 40个人脸 for j = 1:10 % 1人10个表情 I = imread(strcat('D:\Faces\ORL\s',num2str(i),'\',num2str(j),'.bmp')); [c1,s1]=wavedec2(double(I),1,'db1'); % 分别做4个方向的小波分解 ca = appcoef2(c1,s1,'db1',1); ch = detcoef2('h',c1,s1,1); cv = detcoef2('v',c1,s1,1); cd = detcoef2('d',c1,s1,1); % A = uint8([wcodemat(ca,255),wcodemat(ch,255);wcodemat(cv,255),wcodemat(cd,255)]); % subplot(2,5,j),imshow(A,[],'InitialMagnification',100); for k = 1:56 for l = 1:46 Xa(i,j,k,l) = ca(k,l); Xh(i,j,k,l) = ch(k,l); Xv(i,j,k,l) = cv(k,l); Xd(i,j,k,l) = cd(k,l); end end end end for i = 1:1 % 查看第1个人的10个表情图的小波分解效果 for j = 1:10 xa = [56,46]; xh = [56,46]; xv = [56,46]; xd = [56,46]; for k = 1:56 for l = 1:46 xa(k,l) = Xa(i,j,k,l); xh(k,l) = Xh(i,j,k,l); xv(k,l) = Xv(i,j,k,l); xd(k,l) = Xd(i,j,k,l); end end A = uint8([wcodemat(xa,255),wcodemat(xh,255);wcodemat(xv,255),wcodemat(xd,255)]); subplot(2,5,j),imshow(A,[],'InitialMagnification',100); end end
效果图: