二值图像游程长编码
clear all
%图像压缩
I=imread('dou.tif');
[m,n]=size(I);
I=im2bw(I);
figure(1);
imshow(I);title('原始图像');
J=[ ];
I1=I';
I1=I1(:);
S=length(I1);
num=1;
V1=double(I1(1));
J=[J V1];
for i=2:S
V=I1(i);
if V==V1
num=num+1;
else
num=double(num);
J=[J num];
num=1;
V1=I1(i);
end
end
J=[J num];
%以下代码为解压缩图像
L=length(J);
%获取图像第 1 个像素值
St=J(1);
I2=[];
num0=1;
for i=2:L
num=J(i);
num1=num0+num;
I2(num0:num1-1)=St;
St=~St;