www.pudn.com > jpegtool_matlab.rar > psumgrid.m
% psumgrid - calculate partial sum grid
%
% SYNOPSIS
% psumgrid(X)
%
% DESCRIPTION
% The partial sums for X are collected (in zigzag order) in a matrix.
%
% SEE ALSO
% basisgrid
% Copyright (C) 1995-1997 Darrel Hankerson and Greg A. Harris
%
% This file is part of the JPEGtool collection of scripts for Octave
% and Matlab; see http://www.dms.auburn.edu/compression
%
% The JPEGtool collection is free software; you can redistribute it
% and/or modify it under the terms of the GNU General Public License
% as published by the Free Software Foundation; either version 2, or
% (at your option) any later version.
%
% The collection is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this package; see the file COPYING. If not, write to the
% Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
% 02111-1307, USA.
function G = psumgrid(X)
if ~exist('X')
X = ans;
end
N = min(size(X));
if N > 16
error('psumgrid: image size limited to 16x16');
end
S = zeros(N); G = ones(N*(N+1)+1)*min(min(X)); z = zigzag(N);
G = zeros(N*(N+1)+1);
X = dct(X(1:N, 1:N), N);
c = sqrt(2/N) * ones(1,N); c(1) = c(1)/sqrt(2);
for n = 1:N*N
v = z(n,1); u = z(n,2);
S = S + c(v)*c(u) * X(v,u) * basis(v,u,N);
v = (v-1)*(N+1)+1; u = (u-1)*(N+1)+1;
G(v+1:v+N, u+1:u+N) = S;
end