資源描述:
《matlab實(shí)現(xiàn)RGB與YCBCR色空間的相互轉(zhuǎn)換并實(shí)現(xiàn)圖像壓縮.pdf》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫(kù)。
1、%RGB空間與YCbCr空間的互換%實(shí)現(xiàn)圖像壓縮clearcloseall;I=imread('avatar.bmp');I=im2double(I);%RGB轉(zhuǎn)換到Y(jié)CbCrR=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轉(zhuǎn)換到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)