matlab下rle算法的简单实现

matlab下rle算法的简单实现

ID:34724335

大小:123.68 KB

页数:4页

时间:2019-03-10

matlab下rle算法的简单实现_第1页
matlab下rle算法的简单实现_第2页
matlab下rle算法的简单实现_第3页
matlab下rle算法的简单实现_第4页
资源描述:

《matlab下rle算法的简单实现》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库

1、BY:mayadong7349游程长度编码编码函数:functionret_dat=rle_encode(in_dat)%Runlengthencoding%PCXisakindofimagetypeinwhichRLEiswidelyused.%Compressanimagebyusingrun-length-encodingalgorithm.%BY:mayadong73492011-12-10ret_dat=int32([]);ifndims(in_dat)==3,%RGBisgivenerror('Unsu

2、pportedimagetype.');end;%nothingtodoforintensityimage,indexedimagein_dat=in_dat';in_dat=in_dat(:);len=length(in_dat);c=1;whilec<=len,pix_dat=in_dat(c);count=0;while(c<=len)&&(in_dat(c)==pix_dat),count=count+1;c=c+1;end;ret_dat=[ret_dat,pix_dat,count];end;end%e

3、ndoffunctionrle_encode解码函数:functionret_dat=rle_decode(in_dat,lines,cols,dat_type)%Runlengthdecoding%Uncompressanimagewhichisencodedbyusingrun-length-encodingalgorithm.%BY:mayadong73492011-12-10ret_dat=int32([]);[height,width]=size(in_dat);ifheight~=1,BY:mayado

4、ng7349error('Unsupportedinputdatatype.');elseifmod(width,2)~=0,error('Unsupportedinputdatatype.');end;if~strcmp(dat_type,'uint8')&&~strcmp(dat_type,'logical'),error('Cannotrecognisetheinputdatatype.');endc=1;forindex=1:2:widthpix_count=in_dat(index+1);forn=1:p

5、ix_countret_dat(c)=in_dat(index);c=c+1;endendret_dat=reshape(ret_dat,cols,lines);ret_dat=ret_dat';switchdat_typecase'uint8'ret_dat=uint8(ret_dat);case'logical'ret_dat=logical(ret_dat);endend%endoffunctionrle_decode测试脚本:%examplecloseall;clear;clc;warningoffall;

6、forcount=1:4,ifcount==1,filename='bw_logical.bmp';elseifcount==2,filename='bw_gray.bmp';elseifcount==3,filename='rice_logical.bmp';elseifcount==4,filename='rice_gray.bmp';BY:mayadong7349end;[img_data,map]=imread(filename);[h,w]=size(img_data);time_elapsed=cput

7、ime;arr_encode=rle_encode(img_data);img_data_decode=rle_decode(arr_encode,h,w,class(img_data));time_elapsed=cputime-time_elapsed;figure;imshow(img_data,map);figure;imshow(img_data_decode,map);drawnow;disp([filename,'压缩比例',num2str(length(arr_encode)/length(img_

8、data(:)))]);disp(['对',filename,'进行编码、解码,花费总时间为',num2str(time_elapsed),'秒']);end;%a=[0,0,0,0,0,0,0,0,0,0;...0,0,0,1,1,1,1,1,1,1;...1,1,1,1,1,1,0,0,0,0];a=logical(a)[h,w]=size(a);a_e

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。