def extractWithMask(self, source, i, grow=0, bg=0, margin=None, dtype=None): """Extract the image and mask corresponding to group i""" if dtype is None: dtype = source.dtype if self.isEmpty(i): return None if margin is None: margin = grow box, labels = self.groups[i] image = sl.cut(source, box, margin=margin, bg=bg, dtype=dtype) mask = sl.cut(self.segmentation, box, margin=grow, bg=0) mask = in1d(mask, array(labels, 'i')).reshape(image.shape) mask = morphology.binary_dilation(mask, iterations=grow) return where(mask, image, bg), mask
def getMask(self, i, margin=0): """Get the mask image for group i.""" box, labels = self.groups[i] if sl.empty(box): return None mask = sl.cut(self.segmentation, box, margin=margin) shape = mask.shape mask = in1d(mask, array(labels, 'i')) mask.shape = shape return mask
def cut(image, box, margin=0, bg=0, dtype=None): """Cuts out subimages with margins and background. The box is given as (row0,column0,row1,column1). This uses sl.cut (but with different conventions for the box).""" (r0, c0, r1, c1) = box return sl.cut(image, sl.box(r0, r1, c0, c1), margin=margin, bg=bg, dtype=dtype)
def extractWithBackground(self, source, dflt, i, grow=0, dtype=None): """Extract the image corresponding to group i. Background pixels are filled in with dflt.""" if dtype is None: dtype = source.dtype if self.isEmpty(i): return None image = sl.cut(source, self.boundingBox(i), margin=grow, bg=dflt, dtype=dtype) return image
def extractMasked(self,image,index,grow=0,bg=None,margin=0,dtype=None): """Return the masked subimage for component index, elsewhere the bg value.""" if bg is None: bg = amax(image) h,w = image.shape[:2] mask = self.mask(index,margin=margin) # FIXME ... not circular if grow>0: mask = morphology.binary_dilation(mask,iterations=grow) mh,mw = mask.shape box = self.bbox(index) r0,c0,r1,c1 = box subimage = sl.cut(image,(r0,c0,r0+mh-2*margin,c0+mw-2*margin),margin,bg=bg) return where(mask,subimage,bg)
def cut(image,box,margin=0,bg=0,dtype=None): """Cuts out subimages with margins and background. The box is given as (row0,column0,row1,column1). This uses sl.cut (but with different conventions for the box).""" (r0,c0,r1,c1) = box return sl.cut(image,sl.box(r0,r1,c0,c1),margin=margin,bg=bg,dtype=dtype)