matlab 实现行程编码 对二值图像进行编解码

 何为行程压缩呢?很简单:

例如:aaabccccccddeee 可以表示为 3a1b6c2d3e

行程压缩对二值图像的压缩非常有效

close all;clear all;clc;
% matlab 行程编解码 二值图像
I1 = imread('lena.jpg');
I2 = I1(:);
I2length = length(I2);
I3 = im2bw(I1,0.5);  %将原图像转换为二值图像,阈值为0.5
X = I3(:);
L = length(X);
j = 1;
I4(1) = 1;
for z=1:1:(length(X)-1)
    if X(z) == X(z+1)
        I4(j) = I4(j) + 1;
    else
        data(j) = X(z);
        j = j+1;
        I4(j) = 1;
    end
end
data(j) = X(length(X));
I4length = length(I4);
CR = I2length/I4length;  %压缩前与压缩后的比值
% 行程编码解压
l = 1;
for m=1:I4length
    for n=1:1:I4(m)
        decode_image1(l) = data(m);
        l = l+1;
    end
end
decode_image = reshape(decode_image1,300,300);
figure,
x = 1:1:length(X);
subplot(131),plot(x,X(x));
y = 1:1:I4length;
subplot(132),plot(y,I4(y));
u = 1:1:length(decode_image1);
subplot(133),plot(u,decode_image1(u));
figure,
subplot(121),imshow(I3);
subplot(122);imshow(decode_image);
disp('压缩比:')
disp(CR);
disp('原图像数据的长度:')
disp(L);
disp('压缩后图像数据的长度:')
disp(I4length);
disp('解压后图像数据的长度:')
disp(length(decode_image1));

 

 

  • 2
    点赞
  • 41
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值