資源簡介
利用matlab實(shí)現(xiàn)的lzw編碼,能夠高效無損壓縮圖片,gif——lzw
代碼片段和文件信息
function?[outputout_combtable]?=?lzwencode(X)
%函數(shù)輸入
%?X?:?輸入二維圖像矩陣
%函數(shù)輸出
%?output?:壓縮后的十進(jìn)制碼流
%?out_comb?:轉(zhuǎn)換成二進(jìn)制碼流并且合并后在轉(zhuǎn)換成十進(jìn)制碼流
%?table?:?編碼過程中形成的字串表
%創(chuàng)建時(shí)間?2015.05.16
X=im2uint8(X);
[mn]=size(X);
vector=reshape(X1m*n);
vector=double(vector);
tmp.c=0;
tmp.lastCode=-1;
tmp.prefix=[];
tmp.codeLength=1;
%初始化字串表
function?[]=newTable
tmp.c=0;
tmp.lastCode=-1;
tmp.prefix=[];
tmp.codeLength=1;
table.nextCode=2;
table.codes(1:65538)=tmp;
for?c=1:257
????tmp.c=c;
????tmp.lastCode=-1;
????tmp.prefix=[];
????tmp.codeLength=1;
????table.codes(table.nextCode)=tmp;
????table.nextCode=table.nextCode+1;
end;
end
%執(zhí)行添加字串表項(xiàng)工作
????function?[]=addCode(lastCodec)
????????tmp.c=c;
????????tmp.lastCode=lastCode;
????????tmp.prefix=[];
????????tmp.codeLen
評論
共有 條評論