def upsample_and_correlate(im, filt, stride=(2,2), apron=(0,0)): #print 'u&c shapes', im.shape, filt.shape if im.ndim is 2: tmp = zeros( array(im.shape) * array(stride) + (array(apron)*2+1)) tmp[apron[0]:-apron[0]:stride[0], apron[0]:-apron[0]:stride[0]] = im elif im.ndim is 3: target_shape = concatenate(((array(im.shape[0:2]) * array(stride) + array(apron)), [im.shape[2]])) tmp = zeros(target_shape) tmp[apron[0]-1:-apron[0]+2:stride[0], apron[1]-1:-apron[1]+2:stride[1],:] = im f = filt.copy() f.shape = (1, f.shape[0], f.shape[1], 1) return fbcorr(tmp, f, mode='same')
def correlate_and_downsample(im, filt, stride=1): #print 'c&d shapes', im.shape, filt.shape f = filt.copy() if f.ndim is not 4 and f.ndim - im.ndim != 1: if im.ndim is 2: f.shape = (1, filt.shape[0], filt.shape[1]) elif im.ndim is 3: f.shape = (1, filt.shape[0], filt.shape[1], 1) use_cthor = True if use_cthor: p='cthor' pkw = {'variant':'simple:debug'} else: p = 'scipy_naive' pkw = {} result = fbcorr(im, f, mode='same', stride=stride, plugin=p, plugin_kwargs=pkw) return result