欢迎来到天天文库
浏览记录
ID:51893138
大小:61.52 KB
页数:2页
时间:2020-03-18
《matlab实现RGB与YCBCR色空间的相互转换并实现图像压缩.pdf》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、%RGB空间与YCbCr空间的互换%实现图像压缩clearcloseall;I=imread('avatar.bmp');I=im2double(I);%RGB转换到YCbCrR=I(:,:,1);G=I(:,:,2);B=I(:,:,3);Y=16+(0.256789*R+0.504129*G+0.097906*B);Cb=128+(-0.148223*R-0.290992*G+0.439215*B);Cr=128+(0.439215*R-0.367789*G-0.071426*B);rebuilt_Cb=1:300;r
2、ebuilt_Cr=1:300;%图像压缩与解压fori=1:2:299forj=1:2:299press_Cb=(Cb(i,j)+Cb(i+1,j)+Cb(i,j+1)+Cb(i+1,j+1))/4;press_Cr=(Cr(i,j)+Cr(i+1,j)+Cr(i,j+1)+Cr(i+1,j+1))/4;fork=i:(i+1)forl=j:(j+1)rebuilt_Cb(i,j)=press_Cb;rebuilt_Cb(i+1,j)=press_Cb;rebuilt_Cb(i,j+1)=press_Cb;rebuilt
3、_Cb(i+1,j+1)=press_Cb;rebuilt_Cr(i,j)=press_Cr;rebuilt_Cr(i+1,j)=press_Cr;rebuilt_Cr(i,j+1)=press_Cr;rebuilt_Cr(i+1,j+1)=press_Cr;endendendend%YCbCr转换到RGBrebuilt_img(:,:,1)=1.164383*(Y-16)+1.596027*(rebuilt_Cr-128);rebuilt_img(:,:,2)=1.164383*(Y-16)-0.391762*(rebu
4、ilt_Cb-128)-0.812969*(rebuilt_Cr-128);rebuilt_img(:,:,3)=1.164383*(Y-16)+2.017230*(rebuilt_Cb-128);%显示图像figure(1);subplot(1,2,1);imshow(I);title('原图像');subplot(1,2,2);imshow(rebuilt_img);title('解压后图像');%压缩损失值e=abs(rebuilt_img-I)*255;e=sum(e(:))/(300*300)
此文档下载收益归作者所有