(2016版)圖像處理實(shí)驗(yàn)3._第1頁
(2016版)圖像處理實(shí)驗(yàn)3._第2頁
(2016版)圖像處理實(shí)驗(yàn)3._第3頁
(2016版)圖像處理實(shí)驗(yàn)3._第4頁
(2016版)圖像處理實(shí)驗(yàn)3._第5頁
已閱讀5頁,還剩4頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、實(shí)驗(yàn)三、圖像壓縮編碼技術(shù)一、實(shí)驗(yàn)?zāi)康?1、理解有損壓縮和無損壓縮的概念;2、理解圖像壓縮的主要原則和目的;3、了解幾種常用的圖像壓縮編碼方式;4、利用matlab程序進(jìn)行圖像壓縮編碼。二、實(shí)驗(yàn)原理1、圖像壓縮原理圖像壓縮主要目的是為了節(jié)省存儲空間,增加傳輸速度。圖像壓縮的理想標(biāo)準(zhǔn)是信息丟失最少,壓縮比例最大。不損失圖像質(zhì)量的壓縮稱為無損壓縮,無損壓縮不可能達(dá)到很高的壓縮比;損失圖像質(zhì)量的壓縮稱為有損壓縮,高的壓縮比是以犧牲圖像質(zhì)量為代價的。壓縮的實(shí)現(xiàn)方法是對圖像重新進(jìn)行編碼,希望用更少的數(shù)據(jù)表示圖像。信息的冗余量有許多種,如空間冗余,時間冗余,結(jié)構(gòu)冗余,知識冗余,視覺冗余等,數(shù)據(jù)壓縮實(shí)質(zhì)上是減

2、少這些冗余量。高效編碼的主要方法是盡可能去除圖像中的冗余成分,從而以最小的碼元包含最大的圖像信息。編碼壓縮方法有許多種,從不同的角度出發(fā)有不同的分類方法,從信息論角度出發(fā)可分為兩大類。 (1)冗余度壓縮方法,也稱無損壓縮、信息保持編碼或熵編碼。具體說就是解碼圖像和壓縮編碼前的圖像嚴(yán)格相同,沒有失真,從數(shù)學(xué)上講是一種可逆運(yùn)算。 (2)信息量壓縮方法,也稱有損壓縮、失真度編碼或煙壓縮編碼。也就是說解碼圖像和原始圖像是有差別的,允許有一定的失真。應(yīng)用在多媒體中的圖像壓縮編碼方法,從壓縮編碼算法原理上可以分為以下3類: (1)無損壓縮編碼種類哈夫曼(huffman)編碼,算術(shù)編碼,行程(rle)編碼,

3、lempel zev編碼。 (2)有損壓縮編碼種類預(yù)測編碼,dpcm,運(yùn)動補(bǔ)償;頻率域方法:正交變換編碼(如dct),子帶編碼; 空間域方法:統(tǒng)計(jì)分塊編碼;模型方法:分形編碼,模型基編碼;基于重要性:濾波,子采樣,比特分配,向量量化; (3)混合編碼。有jbig,h.261,jpeg,mpeg等技術(shù)標(biāo)準(zhǔn)。本實(shí)驗(yàn)主要利用matlab程序進(jìn)行赫夫曼(huffman)編碼和行程編碼(run length encoding, rle)。三、實(shí)驗(yàn)內(nèi)容 1、實(shí)現(xiàn)基本jpeg的壓縮和編碼分三個步驟: (1)首先通過dct變換去除數(shù)據(jù)冗余; (2)使用量化表對dct系數(shù)進(jìn)行量化; (3)對量化后的系數(shù)進(jìn)行hu

4、ffman編碼。四、實(shí)驗(yàn)步驟1打開計(jì)算機(jī),啟動matlab程序;2選擇一幅圖像,并進(jìn)行赫夫曼和行程編碼壓縮處理;3 將原圖像在photoshop軟件中打開,分別以不同的位圖文件格式進(jìn)行“另保存”,比較它們的數(shù)據(jù)量。4記錄和整理實(shí)驗(yàn)報(bào)告五、實(shí)驗(yàn)儀器1計(jì)算機(jī);2 matlab、photoshop等程序;3移動式存儲器(軟盤、u盤等)。4記錄用的筆、紙。六、實(shí)驗(yàn)報(bào)告內(nèi)容原圖片1、 赫夫曼處理源程序function huffman()clearx=imread(456.jpg);data=uint8(x);zipped,info=huffencode(data); unzipped=huffdecod

5、e(zipped,info); subplot(121);imshow(data);subplot(122);imshow(unzipped);%erms = compare(data(:),unzipped(:);erms=0cr=info.ratiowhos data unzipped zippedfunction zipped,info=huffencode(vector)if isa(vector,uint8) error(input argument must be a uint8 vector);endm,n=size(vector); vector=vector(:);f=fre

6、quency(vector); simbols=find(f=0);f=f(simbols);f,sortindex=sort(f); simbols=simbols(sortindex);len=length(simbols);simbols_index=num2cell(1:len);codeword_tmp=cell(len,1);while length(f)1 index1=simbols_index1; index2=simbols_index2; codeword_tmp(index1)=addnode(codeword_tmp(index1),uint8(0); codewor

7、d_tmp(index2)=addnode(codeword_tmp(index2),uint8(1); f=sum(f(1:2) f(3:end); simbols_index=index1,index2 simbols_index(3:end); f,sortindex=sort(f); simbols_index=simbols_index(sortindex);endcodeword=cell(256,1);codeword(simbols)=codeword_tmp;len=0;for index=1:length(vector) len=len+length(codeworddou

8、ble(vector(index)+1);endstring=repmat(uint8(0),1,len);pointer=1;for index=1:length(vector) code=codeworddouble(vector(index)+1; len=length(code); string(pointer+(0:len-1)=code; pointer=pointer+len;endlen=length(string);pad=8-mod(len,8); if pad0 string=string uint8(zeros(1,pad);endcodeword=codeword(s

9、imbols);codelen=zeros(size(codeword);weights=2.(0:23);maxcodelen=0;for index=1:length(codeword) len=length(codewordindex); if lenmaxcodelen maxcodelen=len; end if len0 code=sum(weights(codewordindex=1); code=bitset(code,len+1); codewordindex=code; codelen(index)=len; endendcodeword=codeword:;cols=le

10、ngth(string)/8;string=reshape(string,8,cols);weights=2.(0:7);zipped=uint8(weights*double(string);huffcodes=sparse(1,1);for index=1:nnz(codeword) huffcodes(codeword(index),1)=simbols(index);endinfo.pad=pad;info.huffcodes=huffcodes;info.ratio=cols./length(vector);info.length=length(vector);info.maxcod

11、elen=maxcodelen;info.rows=m;info.cols=n;function vector=huffdecode(zipped,info,image)if isa(zipped,uint8) error(input argument must be a uint8 vector);endlen=length(zipped);string=repmat(uint8(0),1,len.*8);bitindex=1:8;for index=1:len string(bitindex+8.*(index-1)=uint8(bitget(zipped(index),bitindex)

12、;endstring=logical(string(:);len=length(string);string(len-info.pad+1):end)=; len=length(string);weights=2.(0:51);vector=repmat(uint8(0),1,info.length);vectorindex=1;codeindex=1;code=0;for index=1:len code=bitset(code,codeindex,string(index); codeindex=codeindex+1; byte=decode(bitset(code,codeindex)

13、,info); if byte0 vector(vectorindex)=byte-1; codeindex=1; code=0; vectorindex=vectorindex+1; endendvector=reshape(vector,info.rows,info.cols); function codeword_new=addnode(codeword_old,item)codeword_new=cell(size(codeword_old);for index=1:length(codeword_old) codeword_newindex=item codeword_oldinde

14、x;endfunction f=frequency(vector)if isa(vector,uint8) error(input argument must be a uint8 vector);endf=repmat(0,1,256);len=length(vector);for index=0:255 f(index+1)=sum(vector=uint8(index);endf=f./len;function byte=decode(code,info)byte=info.huffcodes(code); 2、 行程編碼壓縮處理 原圖片 3、 源程序 function rle()i =

15、 imread(123.jpg); i0=rgb2gray(i);i0=double(i0);zipped,info=rlencode(i);%調(diào)用rle進(jìn)行編碼unzipped=rledecode(zipped,info);%調(diào)用解碼程序進(jìn)行編碼%顯示原始圖像和經(jīng)編碼解碼后的圖像,顯示壓縮比,并計(jì)算均方根誤差得erms=0,表示ele是無失真編碼subplot(121);imshow(i);subplot(122);imshow(unzipped);%erms=compare(i(:),unzipped(:)cr=info.ratiowhos i unzipped zippedfunctio

16、nzipped,info=rlencode(vector)m,n=size(vector);vector=vector(:);l=length(vector);c=vector(1);e(1,1)=c;e(1,2)=0;%e(:,1)存放灰度,e(:,2)存放行程t1=1for j=1:l if(vector(j)=c) e(t1,2)=double(e(t1,2)+1; else c=vector(j); t1=t1+1; e(t1,1)=c; e(t1,2)=1; endendzipped=e;info.rows=m;info.cols=n;m,n=size(e);info.ratio=m

17、*n/(info.rows*info.cols); function unzipped=rledecode(zip,info)zip=uint8(zip);m,n=size(zip);unzipped=;for i=1:m section=repmat(zip(i,1),1,double(zip(i,2); unzipped=unzipped section;endunzipped=reshape(unzipped,info.rows,info.cols);%程序結(jié)束七、思考題1圖像中哪些信息是主要的,哪些信息是次要的? 答:需要傳達(dá)給別人的部分是主要的。其他是次要的。例如肖像圖片,肖像部分是主要的,其背景是次要的。為了證明當(dāng)時的場景,場景就是主要的了,而人物就變成次要的。描述風(fēng)景,人物是次要的,背景是主要的。主要和次要是相對的。沒有絕對的主要,也沒有絕對的次要。2簡述赫夫曼編碼和行程編碼的原理。 答:赫夫曼編碼:先統(tǒng)計(jì)數(shù)據(jù)中各字符出現(xiàn)的概率,再按字符出現(xiàn)頻率高低的順序分別賦以由短到長的代碼

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論