回 帖 发 新 帖 刷新版面

主题:[讨论]那位仁兄会JBIG二值图像压缩

我这里有C的代码,谁能帮我写个matlab的?主要压缩和解压缩二值图像的!谢谢

回复列表 (共3个回复)

沙发

看来是没什么辙了

板凳

自己用了个游程编码
function [val,len] = rle(x)

if (size(x,2)==1)
    x = x.';
end


if (size(x,1)~=1)
    error('RLE can only process vectors, not matrices')
end

% Encode
i = [ find(x(1:end-1) ~= x(2:end)), length(x) ];
len = diff([ 0 i ]); 
val = x(i);

3 楼

解码
function [x] = rld(val,len)
if ~any(size(len)==1) | ~any(size(val)==1)
    error('len and val must be vectors.')
end
if (length(len)~=length(val))
    error('len and val vectors must be the same length.')
end

if (size(len,2)==1)
    len = len.';
end

% Decode
i = cumsum([ 1 len ]);
k = zeros(1, i(end)-1);
k(i(1:end-1)) = 1;
x = val(cumsum(k));

我来回复

您尚未登录,请登录后再回复。点此登录或注册