Matlab Huffman Encoding in matrix -
i trying encode matrix have (after calculating frame differences) huffman code having difficulties completing it
the matrix wish encode huffman called "amp"
something found this:
function y = mat2huff(x) %mat2huff huffman encodes matrix. % y = mat2huff(x) huffman encodes matrix x using symbol % probabilities in unit-width histogram bins between x's minimum % , maximum values. encoded data returned structure % y: % y.code huffman-encoded values of x, stored in % uint16 vector. other fields of y contain % additional decoding information, including: % y.min minimum value of x plus 32768 % y.size size of x % y.hist histogram of x % % if x logical, uint8, uint16, uint32, int8, int16, or double, % integer values, can input directly mat2huff. % minimum value of x must representable int16. % % if x double non-integer values---for example, image % values between 0 , 1---first scale x appropriate % integer range before call. example, use y = % mat2huff(255*x) 256 gray level encoding. % % note: number of huffman code words round(max(x(:))) - % round(min(x(:))) + 1. may need scale input x generate % codes of reasonable length. maximum row or column dimension % of x 65535. % % see huff2mat. % copyright 2002-2004 r. c. gonzalez, r. e. woods, & s. l. eddins % digital image processing using matlab, prentice-hall, 2004 % $revision: 1.5 $ $date: 2003/11/21 15:21:12 $ if ndims(x) ~= 2 | ~isreal(x) | (~isnumeric(x) & ~islogical(x)) error('x must 2-d real numeric or logical matrix.'); end % store size of input x. y.size = uint32(size(x)); % find range of x values , store minimum value biased % +32768 uint16. x = round(double(x)); xmin = min(x(:)); xmax = max(x(:)); pmin = double(int16(xmin)); pmin = uint16(pmin + 32768); y.min = pmin; % compute input histogram between xmin , xmax unit % width bins, scale uint16, , store. x = x(:)'; h = histc(x, xmin:xmax); if max(h) > 65535 h = 65535 * h / max(h); end h = uint16(h); y.hist = h; % code input matrix , store result. map = huffman(double(h)); % make huffman code map hx = map(x(:) - xmin + 1); % map image hx = char(hx)'; % convert char array hx = hx(:)'; hx(hx == ' ') = []; % remove blanks ysize = ceil(length(hx) / 16); % compute encoded size hx16 = repmat('0', 1, ysize * 16); % pre-allocate modulo-16 vector hx16(1:length(hx)) = hx; % make hx modulo-16 in length hx16 = reshape(hx16, 16, ysize); % reshape 16-character words hx16 = hx16' - '0'; % convert binary string decimal twos = pow2(15:-1:0); y.code = uint16(sum(hx16 .* twos(ones(ysize, 1), :), 2))'; ...
but in above code how declare use matrix called "amp"?
thanks in advance
just call function huf_amp = mat2huf(amp);
huf_amp being structure detailed in code sample.
Comments
Post a Comment