资源简介
jpeg压缩matlab实现,包含im2jpeg.m,jpeg2im.m,mat2huff.m三个文件。
代码片段和文件信息
function y = im2jpeg(x quality)
%IM2JPEG Compresses an image using a JPEG approximation.
% Y = IM2JPEG(X QUALITY) compresses image X based on 8 x 8 DCT
% transforms coefficient quantization and Huffman symbol
% coding. Input QUALITY determines the amount of information that
% is lost and compression achieved. Y is an encoding structure
% containing fields:
%
% Y.size Size of X
% Y.numblocks Number of 8-by-8 encoded blocks
% Y.quality Quality factor (as percent)
% Y.huffman Huffman encoding structure as returned by
% MAT2HUFF
%
% See also JPEG2IM.
% Copyright 2002-2006 R. C. Gonzalez R. E. Woods & S. L. Eddins
% Digital Image Processing Using MATLAB Prentice-Hall 2004
% $Revision: 1.5 $ $Date: 2006/07/15 20:44:34 $
%
% Revised: 3/20/06 by R.Woods to correct an ‘eob‘ coding problem to
% check the ‘quality‘ input for <= 0 and to fix a warning when
% struct y is created.
error(nargchk(1 2 nargin)); % Check input arguments
if ndims(x) ~= 2 | ~isreal(x) | ~isnumeric(x) | ~isa(x ‘uint8‘)
error(‘The input must be a UINT8 image.‘);
end
if nargin ==2 && quality <= 0
error(‘Input parameter QUALITY must be greater than zero.‘);
end
if nargin < 2
quality = 1; % Default value for quality.
end
m = [16 11 10 16 24 40 51 61 % JPEG normalizing array
12 12 14 19 26 58 60 55 % and zig-zag redordering
14 13 16 24 40 57 69 56 % pattern.
14 17 22 29 51 87 80 62
18 22 37 56 68 109 103 77
24 35 55 64 81 104 113 92
49 64 78 87 103 121 120 101
72 92 95 98 112 100 103 99] * quality;
order = [1 9 2 3 10 17 25 18 11 4 5 12 19 26 33 ...
41 34 27 20 13 6 7 14 21 28 35 42 49 57 50 ...
43 36 29 22 15 8 16 23 30 37 44 51 58 59 52 ...
45 38 31 24 32 39 46 53 60 61 54 47 40 48 55 ...
62 63 56 64];
[xm xn] = size(x); % Get input size.
x = double(x) - 128; % Level shift input
t = dctmtx(8); % Compute 8 x 8 DCT matrix
% Compute DCTs of 8x8 blocks and quantize the coefficients.
y = blkproc(x [8 8] ‘P1 * x * P2‘ t t‘);
y = blkproc(y [8 8] ‘round(x ./ P1)‘ m);
y = im2col(y [8 8] ‘distinct‘); % Break 8x8 blocks into columns
xb = size(y 2); % Get number of blocks
y = y(order :); % Reorder column elements
eob = max(y(:)) + 1; % Create end-of-block symbol
r = zeros(numel(y) + size(y 2) 1);
count = 0;
for j = 1:xb % Process 1 block (col) at a time
i = max(find(y(: j))); % Find last non-zero element
if isempty(i) % No nonzero block values
i = 0;
end
p = count + 1;
q = p + i;
r(p:q) = [y(1:i j); eob]; % Truncate trailing 0‘s add EOB
count = count + i + 1;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2007-12-04 12:46 jpeg\
文件 3259 2006-07-15 17:06 jpeg\im2jpeg.m
文件 2472 2006-07-15 17:06 jpeg\jpeg2im.m
文件 2817 2006-07-15 17:06 jpeg\mat2huff.m
- 上一篇:bp神经网络matlab代码82083
- 下一篇:pam仿真
相关资源
- pam仿真
- bp神经网络matlab代码82083
- ASKFSKPSK的matlab仿真对比
- 2015年研究生数学建模竞赛B题MATLAB代码
- 添加椒盐和高斯噪声的MATLAB代码
- matlab2009b破解文件
- 用MATLAB实现MSK的调制与解调
- yalmip-cplex集成版
- Matlab 协同进化遗传算法解决多阶段决
- 三维装箱和VRP结合的MATLAB算法
- 传统传染病建模的matlab程序
- BFS 广度优先搜索算法 matlab
- matlab写的人工神经网络BP股价预测模型
- k-mean matlab
- 短时傅里叶变换的MATLAB代码
- 用Matlab实现的数字音频水印嵌入与提
- 信息论中各种熵的matlab实现
-
simuli
nk仿真bldc控制 - Harris算子 Matlab源代码 直接可以运行
- 《粒子滤波原理及应用-MATLAB仿真》程
- 无标度网络 BA模型 MATLAB
- 随机过程一步转移矩阵初始分布得到
- 卷积编码译码Matlab仿真程序保证可以
- M序列产生与卷积编码译码的设计实验
- 利用遗传算法进行图像分割(matlab源
- MATLAB的转子振动计算代码
- MATLAB 2018b windows破解文件
- MATLAB 2018b linux破解文件
- NURBS malab入门程序 实现字母 NURBS
- matlab 实现fastica源代码
评论
共有 条评论