資源簡介
利用matlab實現圖像的行程編碼,內含主函數和編碼函數,運行通過且能夠給出壓縮比、判斷是否失真。

代碼片段和文件信息
%%%RLE.m
function?[CRdistortion]=RLE(Xmap)??????%CR是壓縮率;distortion是編解碼的失真
Image1=X(1:2401:240);??????%X為輸入圖像
Image2=Image1‘;
image_1D=Image2(:);?????%將原始圖像寫為一維的數據并設為image_1D
nx=length(image_1D);
run_len(1)=1;
j=1;
for?i=1:1:nx-1;??????%將image_1D所包含的像素進行比對
????if?image_1D(i)==image_1D(i+1);??????%run_len(j)記錄相對應的重復次數
????????run_len(j)=run_len(j)+1;
????else
????????data(j)=image_1D(i);????????%data(j)代表相對應的像素數據
????????j=j+1;
????????run_len(j)=1;
????end
end
data(j)=image_1D(nx);
r=1;
for?j=1:length(run_len);????????%此循環目的在于利用上述得到的重復次數與
????????????????????????????????%對應數據重建原始數據,以驗證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);??????%計算run_len所占字節數
CR=nx/(2*d);????????%計算出全部數據經處理后是壓縮還是膨脹
%?CR;
%?distortion;
imshow(Image1map)
end
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????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
評論
共有 條評論