# 图像压缩编码码matlab实现——一维无损预测编码压缩图像

MATLAB 同时被 2 个专栏收录
755 篇文章 64 订阅
159 篇文章 13 订阅

function y = LPCencode(x, f)
%LPCencode函数用一维无损预测编码压缩图像x，f为预测系数，如果f默认，则f=1，
%就是前值预测。

error(nargchk(1, 2, nargin))
if nargin < 2
f = 1;
end
x = double(x);
[m, n] = size(x);
p = zeros(m, n);    %存放预测值
xs = x;
zc = zeros(m, 1);
for j = 1: length(f)
xs = [zc xs(:, 1: end-1)];
p = p + f(j) * xs;
end
y = x - round(p);

function x = LPCdecode(y, f)
%LPCdecode函数是解码程序，与编码程序用的是一个预测器。

error(nargchk(1, 2, nargin));
if nargin < 2
f = 1;
end
f = f(end: -1: 1);
[m, n] = size(y);
order = length(f);
f = repmat(f, m, 1);
x = zeros(m, n + order);
for j = 1: n
jj = j + order;
x(:, jj) = y(:, j) + round(sum(f(:, order: -1: 1).* x(:, (jj-1):-1:(jj-order)), 2));
end
x = x(:, order + 1: end);

X = double(X);
Y = LPCencode(X);
XX = LPCdecode(Y);

%显示预测误差图
figure(1); imshow(mat2gray(Y));

%显示原图直方图
figure(2);
[h, x] = hist(X(:));
subplot(121);bar(x, h, 'k');

%显示预测误差的直方图
[h, x] = hist(Y(:));
subplot(122); bar(x, h, 'k');

• 3
点赞
• 1
评论
• 4
收藏
• 一键三连
• 扫一扫，分享海报

09-16
04-17

05-10 2691
04-10 6114
03-08
04-10 2184
04-08 990
12-25 9514
03-25 1万+
05-03
04-16