代码如下,上一篇中的问题终于找到了,mask是点乘,而不是乘,修改后合matlab自带程序实现的效果一样。不过还是有个小问题没弄明白,就是wbarb是索引图像,为什么使用imshow()显示,什么也没有?希望以后得到解决,本方案在cameraman.if上实现也没问题,只需要把tif中的数据转换成double类型。
clear;
clear all;
clc;
load wbarb;
subplot(1,3,1);
image(X);
colormap(map);
axis square;
%Imagesc(I,[0,256]);
%Colormap(gray);
title('源图像')
A=X-127;
B=mat2cell(A,8*ones(1,32),8*ones(1,32));
T=dctmtx(8);
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 ];
for i=1:32
for j=1:32
D{i,j}=T*B{i,j}*T';
E{i,j}=mask.*D{i,j};
F{i,j}=T'*E{i,j}*T;
end
end
G=cell2mat(F)+127;
subplot(1,3,2);
image(G);
axis square;
%Imagesc(G,[0,256]);
Colormap(gray);
title('压缩后图像')
%matlab自带程序实现
M= blkproc(X,[8 8],'P1*x*P2',T,T');
M2 = blkproc(M,[8 8],'P1.*x',mask);
I2 = blkproc(M2,[8 8],'P1*x*P2',T',T);
subplot(1,3,3);
image(I2);
title('matlab自带程序实现')
axis square;