⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mat2huff.m

📁 jpeg在matlab下的仿真实现
💻 M
字号:
function y = mat2huff(x)

if ndims(x) ~= 2 | ~isreal(x) | (~isnumeric(x)  &  ~islogical(x))
    error('X must be a 2-D real numeric or logical matrix');
end
%
y.size = unit32(size(x));

%
%
x = round(double(x));
ximn = min(x(:));
xmax = max(x(:));
pmin = double(int16(xmin));
pmin = uint16(pmin + 32768);   y.min = pmin;
%
%
x = x(:)';
h = histc(x, xmin:xmax);
if max(h) > 65535
    h = 65535 * h / max(h);
end
h = uint16(h); y.hist = h;
%
map = huffman(double(h));
hx = map(x(:) - xmin + 1);
hx = char(hx)';
hx = hx(:)';
hx(hx == ' ') = [];
ysize = ceil(length(hx) / 16);
hx16 = repmat('0', 1, ysize * 16);
hx16(1:length(hx)) = hx;
hx16 = reshape(hx16, 16, ysize);
hx16 = hx16' - '0';
twos = pow2(15:-1:0);
y.code = uint16(sum(hx16 * twos(ones(ysize, 1), :), 2))';

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -