相关代码 |
|
I = imread('cameraman.tif'); I = im2double(I); T = dctmtx(8); %产生DCT变换矩阵 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]; %二值掩模,用来压缩DCT的系数 B2 = blkproc(B,[8 8],'P1.*x',mask); %只保留DCT的10个系数 I2 = blkproc(B2,[8 8],'P1*x*P2',T',T); %逆DCT,用来重构图像 imshow(I), figure, imshow(I2)