idamnjanovic@60: function cnt = countcover(sz,blocksize,stepsize) idamnjanovic@60: %COUNTCOVER Covering of signal samples by blocks idamnjanovic@60: % CNT = COUNTCOVER(SZ,BLOCKSIZE,STEPSIZE) assumes a p-dimensional signal idamnjanovic@60: % of size SZ=[N1 N2 ... Np] covered by (possibly overlapping) blocks of idamnjanovic@60: % size BLOCKSIZE=[M1 M2 ... Mp]. The blocks start at position (1,1,..,1) idamnjanovic@60: % and are shifted between them by steps of size STEPSIZE=[S1 S2 ... Sp]. idamnjanovic@60: % COUNTCOVER returns a matrix the same size as the signal, containing in idamnjanovic@60: % each entry the number of blocks covering that sample. idamnjanovic@60: % idamnjanovic@60: % See also IM2COLSTEP, COL2IMSTEP, IM2COL. idamnjanovic@60: idamnjanovic@60: idamnjanovic@60: % Ron Rubinstein idamnjanovic@60: % Computer Science Department idamnjanovic@60: % Technion, Haifa 32000 Israel idamnjanovic@60: % ronrubin@cs idamnjanovic@60: % idamnjanovic@60: % August 2008 idamnjanovic@60: idamnjanovic@60: idamnjanovic@60: cnt = ones(sz); idamnjanovic@60: for k = 1:length(sz) idamnjanovic@60: idamnjanovic@60: % this code is modified from function NDGRID, so it computes one idamnjanovic@60: % output argument of NDGRID at a time (to conserve memory) idamnjanovic@60: ids = (1:sz(k))'; idamnjanovic@60: s = sz; s(k) = []; idamnjanovic@60: ids = reshape(ids(:,ones(1,prod(s))),[length(ids) s]); idamnjanovic@60: ids = permute(ids,[2:k 1 k+1:length(sz)]); idamnjanovic@60: idamnjanovic@60: cnt = cnt .* max( min(floor((ids-1)/stepsize(k)),floor((sz(k)-blocksize(k))/stepsize(k))) - ... idamnjanovic@60: max(ceil((ids-blocksize(k))/stepsize(k)),0) + 1 , 0 ); idamnjanovic@60: end