我执行JPEG压缩这个代码,但我得到的错误huffmandict错误符号和概率向量必须具有相同的长度
???使用错误==> huffmandict在97 符号和概率向量必须具有相同的长度
这是代码,请大家帮忙:
function y = mat2huff(x)
y.size = uint32(size(x));
x = round(double(x));
x = unique(x)
xmin = 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
[map , w] = huffmandict(x,h);
hx = map(x(:) - xmin + 1); % Map image
hx = char(hx)'; % Convert to 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 to 16-character words
hx16 = hx16' - '0'; % Convert binary string to decimal
twos = pow2(15 : - 1 : 0);
y.code = uint16(sum(hx16 .* twos(ones(ysize ,1), :), 2))';
是'大小(x)的大小==(H)'? –
使用[MATLAB的调试器](http://www.mathworks.com/help/matlab/matlab_prog/debugging-process-and-features.html#brqxeeu-177)遍历代码并检查数据的大小。 – excaza
这是问题,它们不是平等的,如果它们不相等,我该如何调用这个函数! – user3818372