def label_image_iterator(self, key=None, labellist=None, background=None, accumulate=False, area=None, relabel=False): if accumulate: lblim = np.zeros(self[key].shape, dtype=self[key].dtype) c = 1 for lbl in self.label_iterator(key=key, labellist=labellist, background=background, area=area): if relabel: lblim[lib.getlabel(self[key], lbl) == 1] = c yield [c, lblim] c += 1 else: lblim[lib.getlabel(self[key], lbl) == 1] = lbl yield [lbl, lblim] else: for lbl in self.label_iterator(key=key, labellist=labellist, background=background, area=area): # changed 'self[key]' to 'self.subset(*key).yield_an_item()' which means that I can now # cope with more complicated key lists, i.e., key=[[path, to, image]] # This solution is valid because within this iterator the key must point to a single # image only. Thus, yield_an_item() returns the one and only leaf that is present in the # return dictionary of subset() lblim = lib.getlabel(self.subset(*key).yield_an_item(), lbl) yield [lbl, lblim]
def label_image_iterator(self, from_id, to_id, labellist=None, background=None, accumulate=False): if accumulate: self.addtodict(np.zeros(self.shape(from_id)), to_id) for lbl in self.label_iterator(id=from_id, labellist=labellist, background=background): if not accumulate: self.getlabel(lbl, ids=from_id, targetids=to_id) else: newlabel = lib.getlabel(lbl, self.get_image(from_id)) self.get_image(to_id)[newlabel == 1] = lbl yield lbl
def label_image_iterator(self, key=None, labellist=None, background=None, accumulate=False, area=None, relabel=False): if accumulate: lblim = np.zeros(self[key].shape, dtype=self[key].dtype) c = 1 for lbl in self.label_iterator(key=key, labellist=labellist, background=background, area=area): if relabel: lblim[lib.getlabel(self[key], lbl) == 1] = c yield [c, lblim] c += 1 else: lblim[lib.getlabel(self[key], lbl) == 1] = lbl yield [lbl, lblim] else: for lbl in self.label_iterator(key=key, labellist=labellist, background=background, area=area): lblim = lib.getlabel(self[key], lbl) yield [lbl, lblim]