/usr/share/psychtoolbox-3/PsychOneliners/ShrinkMatrix.m is in psychtoolbox-3-common 3.0.9+svn2579.dfsg1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | function out = ShrinkMatrix(in,fac)
% out = ShrinkMatrix(IN, FAC)
% Shrinks a 2-D or 3-D matrix IN (an image) by a factor FAC.
% matrix will be truncated horizontally and vertically so that the
% resultant shrunk matrix would have integer sizes in the x an y dimension.
% size of 3rd dimension will not be scaled.
% shrinking is performed by mean computation.
% 05/09/08 DN Wrote it.
% input checking
if ndims(in)>3
error('input is not an image');
end
ys = size(in,1);
xs = size(in,2);
if fac ~= round(fac)
error('scaling factor must be an integer');
end
hcut = mod(xs,fac);
vcut = mod(ys,fac);
if hcut~=0
disp(sprintf('Warning: right edge of input will be truncated by %d pixels',hcut));
end
if vcut~=0
disp(sprintf('Warning: lower edge of input will be truncated by %d pixels',vcut));
end
if hcut~=0 || vcut~=0
in = in(1:end-vcut,1:end-hcut,:);
xs = xs-hcut;
ys = ys-vcut;
end
out = zeros(ys/fac,xs/fac,size(in,3));
for p=1:fac
out = out + in(p:fac:ys,p:fac:xs,:);
end
out = out./fac;
|