資源簡(jiǎn)介
利用matlab實(shí)現(xiàn)圖像的行程編碼,內(nèi)含主函數(shù)和編碼函數(shù),運(yùn)行通過且能夠給出壓縮比、判斷是否失真。

代碼片段和文件信息
%%%RLE.m
function?[CRdistortion]=RLE(Xmap)??????%CR是壓縮率;distortion是編解碼的失真
Image1=X(1:2401:240);??????%X為輸入圖像
Image2=Image1‘;
image_1D=Image2(:);?????%將原始圖像寫為一維的數(shù)據(jù)并設(shè)為image_1D
nx=length(image_1D);
run_len(1)=1;
j=1;
for?i=1:1:nx-1;??????%將image_1D所包含的像素進(jìn)行比對(duì)
????if?image_1D(i)==image_1D(i+1);??????%run_len(j)記錄相對(duì)應(yīng)的重復(fù)次數(shù)
????????run_len(j)=run_len(j)+1;
????else
????????data(j)=image_1D(i);????????%data(j)代表相對(duì)應(yīng)的像素?cái)?shù)據(jù)
????????j=j+1;
????????run_len(j)=1;
????end
end
data(j)=image_1D(nx);
r=1;
for?j=1:length(run_len);????????%此循環(huán)目的在于利用上述得到的重復(fù)次數(shù)與
????????????????????????????????%對(duì)應(yīng)數(shù)據(jù)重建原始數(shù)據(jù),以驗(yàn)證RLE為無失真編碼
????for?s=1:1:run_len(j);
????????rec_1Dimag(r)=data(j);
????????r=r+1;
????end
end
error=rec_1Dimag(:)-image_1D;
%distortion=norm(error2)
flag=0;
for?i=1:nx-1;
????if(error(i)==0)
????else
????????flag=flag+1;
????end
end
distortion=flag/nx
rec_1Dimag;
d=length(run_len);??????%計(jì)算run_len所占字節(jié)數(shù)
CR=nx/(2*d);????????%計(jì)算出全部數(shù)據(jù)經(jīng)處理后是壓縮還是膨脹
%?CR;
%?distortion;
imshow(Image1map)
end
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件???????3587??2018-03-19?15:02??RLE(MATLAB)\c.bmp
?????文件??????10647??2018-03-19?14:17??RLE(MATLAB)\lena.bmp
?????文件???????1156??2018-03-29?14:16??RLE(MATLAB)\RLE.m
?????文件???????1032??2018-03-21?17:04??RLE(MATLAB)\RLE2.m
?????文件????????720??2018-03-21?17:11??RLE(MATLAB)\RLE2_main.m
?????文件????????294??2018-03-29?14:16??RLE(MATLAB)\RLE_main.m
?????目錄??????????0??2018-03-21?18:23??RLE(MATLAB)
-----------?---------??----------?-----??----
????????????????17436????????????????????7
評(píng)論
共有 條評(píng)論