exDCT.m
上传用户:hwtw888
上传日期:2016-03-15
资源大小:177k
文件大小:1k
- % 设置压缩比,cr=0.5为2:1压缩;cr=0.1250为8:1压缩
- cr = 0.125;
- initialimage = imread('lena512.bmp');
- initialimage = double(initialimage)/255;
- figure();
- subplot(121);
- imshow(initialimage);
- %对图像进行DCT变换
- t = dctmtx(8);
- dctcoe = blkproc(initialimage, [8 8], 'P1*x*P2', t, t');
- %将DCT变换后的矩阵转换成列,并按升序排列
- coevar = im2col(dctcoe, [8 8], 'distinct');
- coe = coevar;
- [y, ind] = sort(coevar);
- [m, n] = size(coevar);
- %舍去不重要的系数
- snum = 64-64 * cr;
- for i = 1:n
- coe(ind(1:snum), i) = 0;
- end
- %把列变换为二维矩阵
- b2 = col2im(coe, [8 8], [512 512], 'distinct');
- %逆DCT变换
- i2 = blkproc(b2, [8 8], 'P1*x*P2', t', t);
- subplot(122);
- imshow(i2);
- e = double(initialimage)-double(i2);
- [m, n] = size(e);
- erms = sqrt(sum(e(:).^2)/(m*n))