def mask(self,index,margin=0): """Return the mask for component index.""" b = self.objects[index] #print "@@@mask",index,b m = self.labels[b] m[m!=index] = 0 if margin>0: m = improc.pad_by(m,margin) return array(m!=0,'B')
def best_correlation(u,l,pad=1): """Given an image `u` and a list of images `l`, finds the image with the best normalized cross correlation in `l`. Correlation is carried out with `mode="valid"` after padding with size pad, and only for images whose dimensions are within `pad` of each other.""" def normalize(u): u = u-mean(u) return u/norm(u) u = normalize(u) padded = improc.pad_by(u,pad) normalized = [] for v in l: if amax(abs(array(u.shape)-array(v.shape)))<=pad: normalized.append(normalize(v)) convs = [] for v in normalized: convs.append(signal.correlate(padded,v,mode='valid')) global _convs _convs += sum([c.size for c in convs]) return amax([amax(c) for c in convs]) if len(convs)>0 else 0.0