600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > 数字图像处理|Matlab-灰度和彩色图像的离散余弦变换-通过离散余弦逆变换 还原出图像

数字图像处理|Matlab-灰度和彩色图像的离散余弦变换-通过离散余弦逆变换 还原出图像

时间:2020-08-03 02:07:33

相关推荐

数字图像处理|Matlab-灰度和彩色图像的离散余弦变换-通过离散余弦逆变换 还原出图像

Matlab-灰度和彩色图像的离散余弦变换

代码链接:/download/qq_43571150/12033265

问题1:对输入的灰度和彩色图像进行分块,每一块图像为8*8像素的大小。对分块图像进行离散余弦变换,输出频谱图(DCT系数);

问题2:尝试改变部分的DCT系数;

问题3:通过离散余弦逆变换,还原出图像,观察与原图像之间的区别。

图像结果👇

Matlab代码👇

I1=imread('05.jpg');I2=rgb2gray(I1);mask0=[1 0 0 0 0 0 0 00 0 0 0 0 0 0 00 0 0 0 0 0 0 00 0 0 0 0 0 0 00 0 0 0 0 0 0 00 0 0 0 0 0 0 00 0 0 0 0 0 0 00 0 0 0 0 0 0 0];mask9=[1 1 1 1 0 0 0 01 1 1 0 0 0 0 01 1 0 0 0 0 0 01 0 0 0 0 0 0 00 0 0 0 0 0 0 00 0 0 0 0 0 0 00 0 0 0 0 0 0 00 0 0 0 0 0 0 0];mask35=[1 1 1 1 1 1 1 11 1 1 1 1 1 1 01 1 1 1 1 1 0 01 1 1 1 1 0 0 01 1 1 1 0 0 0 01 1 1 0 0 0 0 01 1 0 0 0 0 0 01 0 0 0 0 0 0 0];mask53=[1 1 1 1 1 1 1 11 1 1 1 1 1 1 11 1 1 1 1 1 1 11 1 1 1 1 1 1 11 1 1 1 1 1 1 01 1 1 1 1 1 0 01 1 1 1 1 0 0 01 1 1 1 0 0 0 0];I0=DCTRGB(I1,mask0);I9=DCTRGB(I1,mask9);I35=DCTRGB(I1,mask35);I53=DCTRGB(I1,mask53);g0=DCTgary(I2,mask0);g9=DCTgary(I2,mask9); g35=DCTgary(I2,mask35); g53=DCTgary(I2,mask53);subplot(2,5,1);imshow(I1);title('彩色图像')subplot(2,5,2);imshow(I0);title('彩色图像DCT系数进行遮罩 0')subplot(2,5,3);imshow(I9);title('彩色图像DCT系数进行遮罩 9')subplot(2,5,4);imshow(I35);title('彩色图像DCT系数进行遮罩 35')subplot(2,5,5);imshow(I53);title('彩色图像DCT系数进行遮罩 53')subplot(2,5,6);imshow(I2);title('灰度图像')subplot(2,5,7);imshow(g0);title('灰度图像DCT系数进行遮罩 0')subplot(2,5,8);imshow(g9);title('灰度图像DCT系数进行遮罩 9')subplot(2,5,9);imshow(g35);title('灰度图像DCT系数进行遮罩 35')subplot(2,5,10);imshow(g53);title('灰度图像DCT系数进行遮罩 53')imwrite(I0,'05 彩色图像DCT系数进行遮罩 0.jpg');imwrite(I9,'05 彩色图像DCT系数进行遮罩 9.jpg');imwrite(I35,'05 彩色图像DCT系数进行遮罩 35.jpg');imwrite(I53,'05 彩色图像DCT系数进行遮罩 53.jpg');imwrite(g0,'05 灰度图像DCT系数进行遮罩 0.jpg');imwrite(g9,'05 灰度图像DCT系数进行遮罩 9.jpg');imwrite(g35,'05 灰度图像DCT系数进行遮罩 35.jpg');imwrite(g53,'05 灰度图像DCT系数进行遮罩 53.jpg');function RGB_rec = DCTRGB( RGB,mask )%进行彩色图像的DCT变换%返回重构的图像%亮度量化表m=0.5*[ 16 11 10 16 24 40 51 61;12 12 14 19 26 58 60 55;14 13 16 24 40 57 69 56;14 17 22 29 51 87 80 62;18 22 37 56 68 109 103 77;24 35 55 64 81 104 113 92;49 64 78 87 103 121 120 101;72 92 95 98 112 100 103 99];%RGB图分层处理 得到3个分量图R = RGB(:,:,1);G = RGB(:,:,2);B = RGB(:,:,3);%转换为双精度IR = double(R);IG = double(G);IB = double(B);%建立8*8的DCT变换矩阵T=dctmtx(8);%进行DCT变换RR = blkproc(IR,[8,8],'P1*x*P2',T,T');GG = blkproc(IG,[8,8],'P1*x*P2',T,T');BB = blkproc(IB,[8,8],'P1*x*P2',T,T');%量化LR = blkproc(RR,[8 8], 'round(x./P1)',m);LG = blkproc(GG,[8 8], 'round(x./P1)',m);LB = blkproc(BB,[8 8], 'round(x./P1)',m);%对DCT系数进行遮罩处理mR=blkproc(LR,[8 8],'x.*P1.*P2',mask,m);mG=blkproc(LG,[8 8],'x.*P1.*P2',mask,m);mB=blkproc(LB,[8 8],'x.*P1.*P2',mask,m);%反DCT变化 IDCTYR =blkproc(mR,[8 8],'P1*x*P2',T',T);YG =blkproc(mG,[8 8],'P1*x*P2',T',T);YB =blkproc(mB,[8 8],'P1*x*P2',T',T);%转换为uint8YR = uint8(YR);YG = uint8(YG);YB = uint8(YB);%重构图像RGB_rec =cat(3,YR,YG,YB);endfunction gary_rec = DCTgary(gary,mask ) %进行灰度图像的DCT变换%返回重构的图像%亮度量化表m=0.5*[ 16 11 10 16 24 40 51 61;12 12 14 19 26 58 60 55;14 13 16 24 40 57 69 56;14 17 22 29 51 87 80 62;18 22 37 56 68 109 103 77;24 35 55 64 81 104 113 92;49 64 78 87 103 121 120 101;72 92 95 98 112 100 103 99];%转换为双精度I = double(gary);%建立8*8的DCT变换矩阵T=dctmtx(8);%进行DCT变换RR = blkproc(I,[8,8],'P1*x*P2',T,T');%量化LR = blkproc(RR,[8 8], 'round(x./P1)',m);%对DCT系数进行遮罩处理mR=blkproc(LR,[8 8],'x.*P1.*P2',mask,m);%反DCT变化 IDCTYR =blkproc(mR,[8 8],'P1*x*P2',T',T);%转换为uint8YR = uint8(YR);%重构图像gary_rec = YR;end

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。