def _get_gabor_filters(self, params): """ Return a Gabor filterbank (generate it if needed) Inputs: params -- filters parameters (dict) Outputs: filt_l -- filterbank (list) """ if self._filt_l is None: # -- get parameters fh, fw = params['kshape'] orients = params['orients'] freqs = params['freqs'] phases = params['phases'] nf = len(orients) * len(freqs) * len(phases) fbshape = nf, fh, fw gsw = fw/5. gsh = fw/5. xc = fw/2 yc = fh/2 filt_l = [] # -- build the filterbank for freq in freqs: for orient in orients: for phase in phases: # create 2d gabor filt = v1s_math.gabor2d(gsw,gsh, xc,yc, freq,orient,phase, (fw,fh)) # vectors for separable convolution U,S,V = v1s_math.fastsvd(filt) tot = 0 vectors = [] idx = 0 S **= 2. while tot <= params['sep_threshold']: row = (U[:,idx]*S[idx])[:, newaxis] col = (V[idx,:])[newaxis, :] vectors += [(row,col)] tot += S[idx]/S.sum() idx += 1 filt_l += [vectors] self._filt_l = filt_l return self._filt_l
def _dimr(self,fvectors,pca_threshold): # -- Reduce dimensionality using a pca / eigen subspace projection nvectors, vsize = fvectors.shape if nvectors < vsize: print "pca...", print fvectors.shape, "=>", U,S,V = v1s_math.fastsvd(fvectors) eigvectors = V.T i = tot = 0 S **= 2. while (tot <= pca_threshold) and (i < S.size): tot += S[i]/S.sum() i += 1 eigvectors = eigvectors[:, :i+1] fvectors = scipy.dot(fvectors, eigvectors) return fvectors, eigvectors