【图像处理】MATLAB:图像压缩
2017-10-20 20:23
411 查看
图像压缩背景知识
图像冗余包括编码冗余、像素间冗余、心理视觉冗余。编码冗余
减少编码冗余function h = entropy(x, n) % 熵 error(nargchk(1, 2, nargin)); % Check input arguments if nargin < 2 n = 256; % Default for n. end x = double(x); % Make input double xh = hist(x(:), n); % Compute N-bin histogram xh = xh / sum(xh(:)); % Compute probabilities % Make mask to eliminate 0's since log2(0) = -inf. i = find(xh); h = -sum(xh(i) .* log2(xh(i))); % Compute entropy
霍夫曼编码
function CODE = huffman(p) % 虽然递归比较绕,但仔细分析还是能懂 % Check the input arguments for reasonableness. error(nargchk(1, 1, nargin)); if (ndims(p) ~= 2) | (min(size(p)) > 1) | ~isreal(p) | ~isnumeric(p) error('P must be a real numeric vector.'); end % Global variable surviving all recursions of function 'makecode' global CODE CODE = cell(length(p), 1); % Init the global cell array if length(p) > 1 % When more than one symbol ... p = p / sum(p); % Normalize the input probabilities s = reduce(p); % Do Huffman source symbol reductions makecode(s, []); % Recursively generate the code else CODE = {'1'}; % Else, trivial one symbol case! end; %-------------------------------------------------------------------% function s = reduce(p); % Create a Huffman source reduction tree in a MATLAB cell structure % by performing source symbol reductions until there are only two % reduced symbols remaining s = cell(length(p), 1); % Generate a starting tree with symbol nodes 1, 2, 3, ... to % reference the symbol probabilities. for i = 1:length(p) s{i} = i; end while numel(s) > 2 [p, i] = sort(p); % Sort the symbol probabilities p(2) = p(1) + p(2); % Merge the 2 lowest probabilities p(1) = []; % and prune the lowest one s = s(i); % Reorder tree for new probabilities s{2} = {s{1}, s{2}}; % and merge & prune its nodes s(1) = []; % to match the probabilities end %-------------------------------------------------------------------% function makecode(sc, codeword) % Scan the nodes of a Huffman source reduction tree recursively to % generate the indicated variable length code words. % Global variable surviving all recursive calls global CODE if isa(sc, 'cell') % For cell array nodes, makecode(sc{1}, [codeword 0]); % add a 0 if the 1st element makecode(sc{2}, [codeword 1]); % or a 1 if the 2nd else % For leaf (numeric) nodes, CODE{sc} = char('0' + codeword); % create a char code string % 字符串'0' + codeword即为'codeword' end
像素间冗余
心理视觉冗余
function y = quantize(x, b, type) error(nargchk(2, 3, nargin)); % Check input arguments if ndims(x) ~= 2 | ~isreal(x) | ... ~isnumeric(x) | ~isa(x, 'uint8') error('The input must be a UINT8 numeric matrix.'); end % Create bit masks for the quantization lo = uint8(2 ^ (8 - b) - 1); hi = uint8(2 ^ 8 - double(lo) - 1); % Perform standard quantization unless IGS is specified if nargin < 3 | ~strcmpi(type, 'igs') y = bitand(x, hi); else [m, n] = size(x); c2ed s = zeros(m, 1); hitest = double(bitand(x, hi) ~= hi); x = double(x); for j = 1:n s = x(:, j) + hitest(:, j) .*double(bitand(uint8(s), lo)); y(:, j) = bitand(uint8(s), hi); end end
JPEG
相关文章推荐
- Matlab 图像处理 形态学 腐蚀 膨胀 开闭运算 连通分量
- 形态学图像处理(matlab代码测试)
- Matlab图像处理(03)-基本概念
- 【MATLAB图像处理】在MATLAB中图像的坐标以及rectangle的坐标
- matlab 在图像处理中常用的函数使用(2)
- matlab图像处理 笔记
- Matlab 之图像处理相关函数
- 数字图像处理matlab版第十章(重要)
- 部分matlab处理图像代码
- 在利用matlab处理图像时务必慎用abs函数
- MATLAB图像处理_统计最大/最小/平均灰度
- php图像处理类,上传,压缩,添加文字、图片水印
- matlab图像处理命令(一)
- 图像处理 加法练习 Matlab 图像叠加求平均去噪
- Matlab 图像处理 形态学 腐蚀 膨胀 开闭运算 连通分量
- MATLAB实现图像羽化处理(图像羽化处理)
- 红外图像处理之直方图均衡的matlab源码与效果验证
- matlab中图像数据类型及处理函数
- 数字图像处理-提取A4纸中线条-matlab的轮廓提取方法
- Matlab图像处理学习笔记(三):基于匹配的目标识别