From: Matt J on
"Young Ryu" <ryuyr77(a)gmail.com> wrote in message <hfbl9m$pv1$1(a)fred.mathworks.com>...

Here's a function for downsampling, but it works only when the new pixel sizes are integer multiples of the old ones. If this is enough for you, it might be faster than resizem, if the latter is trying to do something interpolation-based.

function M=downsamp2d(M,bindims)
%DOWNSAMP2D - simple tool for 2D downsampling
%
% M=downsamp2d(M,bindims)
%
%in:
%
% M: a matrix
% bindims: a vector [p,q] specifying pxq downsampling
%
%out:
%
% M: the downsized matrix

p=bindims(1); q=bindims(2);
[m,n]=size(M); %M is the original matrix

M=sum( reshape(M,p,[]) ,1 );
M=reshape(M,m/p,[]).'; %Note transpose

M=sum( reshape(M,q,[]) ,1);
M=reshape(M,n/q,[]).'; %Note transpose

M=M/(p*q);
 | 
Pages: 1
Prev: drawnow slow in animation
Next: Garbled zlabel