对于小波图像压缩编码分析,小波一级分解,分解成水平,垂直和斜线方向的梯度值,编程如下: - %第一层小波分解
- clc,clear,close all % 清屏、清工作区、关闭窗口
- warning off % 消除警告
- feature jit off % 加速代码执行
- load wbarb;
- image(X);
- colormap(map);
- colorbar;
- % 小波分解
- [cA1,cH1,cV1,cD1] = dwt2(X,'bior3.7');
- % 第一层小波逼近系数--cA1
- % 水平系数--cH1
- % 垂直系数--cV1
- % 对角系数--cD1
- A1 = upcoef2('a',cA1,'bior3.7',1);
- H1 = upcoef2('h',cH1,'bior3.7',1);
- V1 = upcoef2('v',cV1,'bior3.7',1);
- D1 = upcoef2('d',cD1,'bior3.7',1);
- %显示第一层小波分解图形
- colormap(map);
- subplot(2,2,1); image(wcodemat(A1,192));
- title('Approximation A1')
- subplot(2,2,2); image(wcodemat(H1,192));
- title('Horizontal Detail H1')
- subplot(2,2,3); image(wcodemat(V1,192));
- title('Vertical Detail V1')
- subplot(2,2,4); image(wcodemat(D1,192));
- title('Diagonal Detail D1')
复制代码对该图像进行第二层小波分解,同样的得到水平,垂直和斜线方向的梯度值,编程如下:
- %% 由单层逆小波变换重新产生一副图像
- % 逆变换
- Xsyn = idwt2(cA1,cH1,cV1,cD1,'bior3.7');
- %图像2级小波分解
- [C,S] = wavedec2(X,2,'bior3.7');
- %提取第二层小波逼近系数
- cA2 = appcoef2(C,S,'bior3.7',2);
- %提取第一层、第二层小波系数
- cH2 = detcoef2('h',C,S,2);
- cV2 = detcoef2('v',C,S,2);
- cD2 = detcoef2('d',C,S,2);
- cH1 = detcoef2('h',C,S,1);
- cV1 = detcoef2('v',C,S,1);
- cD1 = detcoef2('d',C,S,1);
- %重构 the level 2 approximation from C
- A2 = wrcoef2('a',C,S,'bior3.7',2);
- %重构 the level 1 and 2 details from C
- H1 = wrcoef2('h',C,S,'bior3.7',1);
- V1 = wrcoef2('v',C,S,'bior3.7',1);
- D1 = wrcoef2('d',C,S,'bior3.7',1);
- H2 = wrcoef2('h',C,S,'bior3.7',2);
- V2 = wrcoef2('v',C,S,'bior3.7',2);
- D2 = wrcoef2('d',C,S,'bior3.7',2);
- %显示2级小波分解结果
- colormap(map);
- subplot(2,4,1);image(wcodemat(A1,192));
- title('Approximation A1')
- subplot(2,4,2);image(wcodemat(H1,192));
- title('Horizontal Detail H1')
- subplot(2,4,3);image(wcodemat(V1,192));
- title('Vertical Detail V1')
- subplot(2,4,4);image(wcodemat(D1,192));
- title('Diagonal Detail D1')
- subplot(2,4,5);image(wcodemat(A2,192));
- title('Approximation A2')
- subplot(2,4,6);image(wcodemat(H2,192));
- title('Horizontal Detail H2')
- subplot(2,4,7);image(wcodemat(V2,192));
- title('Vertical Detail V2')
- subplot(2,4,8);image(wcodemat(D2,192));
- title('Diagonal Detail D2')
复制代码第一层小波压缩和第二层小波压缩以及采用wdencmp小波压缩方法得到的结果及图,程序如下:
- %% 重构 the original image from the wavelet decomposition structure
- X0 = waverec2(C,S,'bior3.7');
- % 压缩图像X
- [thr,sorh,keepapp]= ddencmp('cmp','wv',X);
- % 降噪 or 压缩 using wavelets.
- [Xcomp,CXC,LXC,PERF0,PERFL2] = ...
- wdencmp('gbl',C,S,'bior3.7',2,thr,sorh,keepapp);
- % 对比查看压缩前后图像
- colormap(map);
- subplot(121); image(X); title('Original Image');
- axis square
- subplot(122); image(Xcomp); title('Compressed Image');
- axis square
- PSNR(X,Xcomp)
复制代码
|