Exemple #1
0
    def setupOutputs(self):
        taggedShape = self.LabelVolume.meta.getTaggedShape()

        if set(taggedShape.keys()) != set('txyzc'):
            raise Exception("Input volumes must have txyzc axes.")

        self.BlockwiseDivisionFeatures.meta.shape = tuple([taggedShape['t']])
        self.BlockwiseDivisionFeatures.meta.axistags = vigra.defaultAxistags(
            "t")
        self.BlockwiseDivisionFeatures.meta.dtype = object

        ndim = 3
        if np.any(list(taggedShape.get(k, 0) == 1 for k in "xyz")):
            ndim = 2

        self.featureManager = FeatureManager(
            scales=config.image_scale,
            n_best=config.n_best_successors,
            com_name_cur=config.com_name_cur,
            com_name_next=config.com_name_next,
            size_name=config.size_name,
            delim=config.delim,
            template_size=config.template_size,
            ndim=ndim,
            size_filter=config.size_filter,
            squared_distance_default=config.squared_distance_default)
    def setupOutputs(self):
        taggedShape = self.LabelVolume.meta.getTaggedShape()        

        if set(taggedShape.keys()) != set('txyzc'):
            raise Exception("Input volumes must have txyzc axes.")

        self.BlockwiseDivisionFeatures.meta.shape = tuple([taggedShape['t']])
        self.BlockwiseDivisionFeatures.meta.axistags = vigra.defaultAxistags("t")
        self.BlockwiseDivisionFeatures.meta.dtype = object        
        
        ndim = 3
        if np.any(list(taggedShape.get(k, 0) == 1 for k in "xyz")):
            ndim = 2
            
        self.featureManager = FeatureManager(scales=config.image_scale, n_best=config.n_best_successors, com_name_cur=config.com_name_cur,
                    com_name_next=config.com_name_next, size_name=config.size_name, delim=config.delim, template_size=config.template_size, 
                    ndim=ndim, size_filter=config.size_filter,squared_distance_default=config.squared_distance_default)
Exemple #3
0
class OpDivisionFeatures(Operator):
    """Computes division features on a 5D volume."""
    LabelVolume = InputSlot()
    DivisionFeatureNames = InputSlot(rtype=List, stype=Opaque)
    RegionFeaturesVigra = InputSlot()

    BlockwiseDivisionFeatures = OutputSlot()

    def __init__(self, *args, **kwargs):
        super(OpDivisionFeatures, self).__init__(*args, **kwargs)

    def setupOutputs(self):
        taggedShape = self.LabelVolume.meta.getTaggedShape()

        if set(taggedShape.keys()) != set('txyzc'):
            raise Exception("Input volumes must have txyzc axes.")

        self.BlockwiseDivisionFeatures.meta.shape = tuple([taggedShape['t']])
        self.BlockwiseDivisionFeatures.meta.axistags = vigra.defaultAxistags(
            "t")
        self.BlockwiseDivisionFeatures.meta.dtype = object

        ndim = 3
        if np.any(list(taggedShape.get(k, 0) == 1 for k in "xyz")):
            ndim = 2

        self.featureManager = FeatureManager(
            scales=config.image_scale,
            n_best=config.n_best_successors,
            com_name_cur=config.com_name_cur,
            com_name_next=config.com_name_next,
            size_name=config.size_name,
            delim=config.delim,
            template_size=config.template_size,
            ndim=ndim,
            size_filter=config.size_filter,
            squared_distance_default=config.squared_distance_default)

    def execute(self, slot, subindex, roi, result):
        assert len(roi.start) == len(roi.stop) == len(
            self.BlockwiseDivisionFeatures.meta.shape)
        assert slot == self.BlockwiseDivisionFeatures
        taggedShape = self.LabelVolume.meta.getTaggedShape()
        timeIndex = taggedShape.keys().index('t')

        import time
        start = time.time()

        vroi_start = len(self.LabelVolume.meta.shape) * [
            0,
        ]
        vroi_stop = list(self.LabelVolume.meta.shape)

        assert len(roi.start) == 1
        froi_start = roi.start[0]
        froi_stop = roi.stop[0]
        vroi_stop[timeIndex] = roi.stop[0]

        assert timeIndex == 0
        vroi_start[timeIndex] = roi.start[0]
        if roi.stop[0] + 1 < self.LabelVolume.meta.shape[timeIndex]:
            vroi_stop[timeIndex] = roi.stop[0] + 1
            froi_stop = roi.stop[0] + 1
        vroi = [
            slice(vroi_start[i], vroi_stop[i]) for i in range(len(vroi_start))
        ]

        feats = self.RegionFeaturesVigra[slice(froi_start, froi_stop)].wait()
        labelVolume = self.LabelVolume[vroi].wait()
        divisionFeatNames = self.DivisionFeatureNames[(
        )].wait()[config.features_division_name]

        for t in range(roi.stop[0] - roi.start[0]):
            result[t] = {}
            feats_cur = feats[t][config.features_vigra_name]
            if t + 1 < froi_stop - froi_start:
                feats_next = feats[t + 1][config.features_vigra_name]

                img_next = labelVolume[t + 1, ...]
            else:
                feats_next = None
                img_next = None
            res = self.featureManager.computeFeatures_at(
                feats_cur, feats_next, img_next, divisionFeatNames)
            result[t][config.features_division_name] = res

        stop = time.time()
        logger.info(
            "TIMING: computing division features took {:.3f}s".format(stop -
                                                                      start))
        return result

    def propagateDirty(self, slot, subindex, roi):
        if slot is self.DivisionFeatureNames:
            self.BlockwiseDivisionFeatures.setDirty(slice(None))
        elif slot is self.RegionFeaturesVigra:
            self.BlockwiseDivisionFeatures.setDirty(roi)
        else:
            axes = self.LabelVolume.meta.getTaggedShape().keys()
            dirtyStart = collections.OrderedDict(zip(axes, roi.start))
            dirtyStop = collections.OrderedDict(zip(axes, roi.stop))

            # Remove the spatial and channel dims (keep t, if present)
            del dirtyStart['x']
            del dirtyStart['y']
            del dirtyStart['z']
            del dirtyStart['c']

            del dirtyStop['x']
            del dirtyStop['y']
            del dirtyStop['z']
            del dirtyStop['c']

            self.BlockwiseDivisionFeatures.setDirty(dirtyStart.values(),
                                                    dirtyStop.values())
class OpDivisionFeatures(Operator):
    """Computes division features on a 5D volume."""    
    LabelVolume = InputSlot()
    DivisionFeatureNames = InputSlot(rtype=List, stype=Opaque)
    RegionFeaturesVigra = InputSlot()
    
    BlockwiseDivisionFeatures = OutputSlot()
        
    def __init__(self, *args, **kwargs):
        super(OpDivisionFeatures, self).__init__(*args, **kwargs)
                
    def setupOutputs(self):
        taggedShape = self.LabelVolume.meta.getTaggedShape()        

        if set(taggedShape.keys()) != set('txyzc'):
            raise Exception("Input volumes must have txyzc axes.")

        self.BlockwiseDivisionFeatures.meta.shape = tuple([taggedShape['t']])
        self.BlockwiseDivisionFeatures.meta.axistags = vigra.defaultAxistags("t")
        self.BlockwiseDivisionFeatures.meta.dtype = object        
        
        ndim = 3
        if np.any(list(taggedShape.get(k, 0) == 1 for k in "xyz")):
            ndim = 2
            
        self.featureManager = FeatureManager(scales=config.image_scale, n_best=config.n_best_successors, com_name_cur=config.com_name_cur,
                    com_name_next=config.com_name_next, size_name=config.size_name, delim=config.delim, template_size=config.template_size, 
                    ndim=ndim, size_filter=config.size_filter,squared_distance_default=config.squared_distance_default)


    def execute(self, slot, subindex, roi, result):
        assert len(roi.start) == len(roi.stop) == len(self.BlockwiseDivisionFeatures.meta.shape)
        assert slot == self.BlockwiseDivisionFeatures
        taggedShape = self.LabelVolume.meta.getTaggedShape()
        timeIndex = list(taggedShape.keys()).index('t')
        
        import time
        start = time.time()
        
        vroi_start = len(self.LabelVolume.meta.shape) * [0,]
        vroi_stop = list(self.LabelVolume.meta.shape)
        
        assert len(roi.start) == 1
        froi_start = roi.start[0]
        froi_stop = roi.stop[0]
        vroi_stop[timeIndex] = roi.stop[0]
        
        assert timeIndex == 0
        vroi_start[timeIndex] = roi.start[0]
        if roi.stop[0] + 1 < self.LabelVolume.meta.shape[timeIndex]:
            vroi_stop[timeIndex] = roi.stop[0]+1
            froi_stop = roi.stop[0]+1
        vroi = [slice(vroi_start[i],vroi_stop[i]) for i in range(len(vroi_start))]
        
        feats = self.RegionFeaturesVigra[slice(froi_start, froi_stop)].wait()
        labelVolume = self.LabelVolume[vroi].wait()
        divisionFeatNames = self.DivisionFeatureNames[()].wait()[config.features_division_name] 
        
        for t in range(roi.stop[0]-roi.start[0]):
            result[t] = {}
            feats_cur = feats[t][config.features_vigra_name]
            if t+1 < froi_stop-froi_start:                
                feats_next = feats[t+1][config.features_vigra_name]
                                
                img_next = labelVolume[t+1,...]
            else:
                feats_next = None
                img_next = None
            res = self.featureManager.computeFeatures_at(feats_cur, feats_next, img_next, divisionFeatNames)
            result[t][config.features_division_name] = res 
        
        stop = time.time()
        logger.debug("TIMING: computing division features took {:.3f}s".format(stop-start))
        return result
    
    
    def propagateDirty(self, slot, subindex, roi):
        if slot is self.DivisionFeatureNames:
            self.BlockwiseDivisionFeatures.setDirty(slice(None))
        elif slot is self.RegionFeaturesVigra:
            self.BlockwiseDivisionFeatures.setDirty(roi)
        else:
            axes = list(self.LabelVolume.meta.getTaggedShape().keys())
            dirtyStart = collections.OrderedDict(list(zip(axes, roi.start)))
            dirtyStop = collections.OrderedDict(list(zip(axes, roi.stop)))

            # Remove the spatial and channel dims (keep t, if present)
            del dirtyStart['x']
            del dirtyStart['y']
            del dirtyStart['z']
            del dirtyStart['c']

            del dirtyStop['x']
            del dirtyStop['y']
            del dirtyStop['z']
            del dirtyStop['c']

            self.BlockwiseDivisionFeatures.setDirty(list(dirtyStart.values()), list(dirtyStop.values()))