def setup(self):
        graph = Graph()
        op = OpSparseLabelArray(graph=graph)
        arrayshape = numpy.array([1,10,10,10,1])
        op.inputs["shape"].setValue( tuple(arrayshape) )
        op.eraser.setValue(100)

        slicing = sl[0:1, 1:5, 2:6, 3:7, 0:1]
        inDataShape = slicing2shape(slicing)
        inputData = ( 3*numpy.random.random(inDataShape) ).astype(numpy.uint8)
        op.Input[slicing] = inputData
        data = numpy.zeros(arrayshape, dtype=numpy.uint8)
        data[slicing] = inputData
        
        self.op = op
        self.slicing = slicing
        self.inData = inputData
        self.data = data
Beispiel #2
0
    def setup(self):
        graph = Graph()
        op = OpSparseLabelArray(graph=graph)
        arrayshape = numpy.array([1, 10, 10, 10, 1])
        op.inputs["shape"].setValue(tuple(arrayshape))
        op.eraser.setValue(100)

        slicing = sl[0:1, 1:5, 2:6, 3:7, 0:1]
        inDataShape = slicing2shape(slicing)
        inputData = (3 * numpy.random.random(inDataShape)).astype(numpy.uint8)
        op.Input[slicing] = inputData
        data = numpy.zeros(arrayshape, dtype=numpy.uint8)
        data[slicing] = inputData

        self.op = op
        self.slicing = slicing
        self.inData = inputData
        self.data = data
    def setup(self):
        try:
            import blist
        except ImportError:
            raise unittest.SkipTest

        from lazyflow.operators.opSparseLabelArray import OpSparseLabelArray
        graph = Graph()
        op = OpSparseLabelArray(graph=graph)
        arrayshape = numpy.array([1, 10, 10, 10, 1])
        op.inputs["shape"].setValue(tuple(arrayshape))
        op.eraser.setValue(100)

        slicing = sl[0:1, 1:5, 2:6, 3:7, 0:1]
        inDataShape = slicing2shape(slicing)
        inputData = (3 * numpy.random.random(inDataShape)).astype(numpy.uint8)
        op.Input[slicing] = inputData
        data = numpy.zeros(arrayshape, dtype=numpy.uint8)
        data[slicing] = inputData

        self.op = op
        self.slicing = slicing
        self.inData = inputData
        self.data = data
    def setup(self):
        try:
            import blist
        except ImportError:
            raise unittest.SkipTest 
        
        from lazyflow.operators.opSparseLabelArray import OpSparseLabelArray
        graph = Graph()
        op = OpSparseLabelArray(graph=graph)
        arrayshape = numpy.array([1,10,10,10,1])
        op.inputs["shape"].setValue( tuple(arrayshape) )
        op.eraser.setValue(100)

        slicing = sl[0:1, 1:5, 2:6, 3:7, 0:1]
        inDataShape = slicing2shape(slicing)
        inputData = ( 3*numpy.random.random(inDataShape) ).astype(numpy.uint8)
        op.Input[slicing] = inputData
        data = numpy.zeros(arrayshape, dtype=numpy.uint8)
        data[slicing] = inputData
        
        self.op = op
        self.slicing = slicing
        self.inData = inputData
        self.data = data
Beispiel #5
0
    def setInSlot(self, slot, subindex, roi, value):
        key = roi.toSlice()
        time1 = time.time()
        start, stop = sliceToRoi(key, self._cacheShape)

        blockStart = (1.0 * start / self._blockShape).floor()
        blockStop = (1.0 * stop / self._blockShape).ceil()
        blockStop = numpy.where(stop == self._cacheShape, self._dirtyShape,
                                blockStop)
        blockKey = roiToSlice(blockStart, blockStop)
        innerBlocks = self._blockNumbers[blockKey]
        for b_ind in innerBlocks.ravel():

            offset = self._blockShape * self._flatBlockIndices[b_ind]
            bigstart = numpy.maximum(offset, start)
            bigstop = numpy.minimum(offset + self._blockShape, stop)
            smallstart = bigstart - offset
            smallstop = bigstop - offset
            bigkey = roiToSlice(bigstart - start, bigstop - start)
            smallkey = roiToSlice(smallstart, smallstop)
            smallvalues = value[tuple(bigkey)]
            if (smallvalues != 0).any():
                if not b_ind in self._labelers:
                    self._labelers[b_ind] = OpSparseLabelArray(self)
                    # Don't connect deletelabel; it is set manually (here and also above)
                    self._labelers[b_ind].inputs["deleteLabel"].setValue(
                        self.inputs["deleteLabel"].value)
                    self._labelers[b_ind].inputs["shape"].setValue(
                        tuple(self._blockShape))
                    self._labelers[b_ind].inputs["eraser"].setValue(
                        self.inputs["eraser"].value)

                    # remember old max labele, i.e. 0 since we just created
                    self._oldMaxLabels[b_ind] = 0
                    # add the 0 to the histogram
                    self._maxLabelHistogram[0] += 1

                    def max_label_changed(b_ind, slot, *args):
                        self.lock.acquire()

                        newmax = slot.value

                        # make sure histogram is large enough
                        if newmax > self._maxLabelHistogram.shape[0] - 1:
                            self._maxLabelHistogram.resize((newmax + 1, ))

                        # update histogram
                        oldmax = self._oldMaxLabels[b_ind]
                        self._maxLabelHistogram[oldmax] -= 1
                        self._maxLabelHistogram[newmax] += 1
                        self._oldMaxLabels[b_ind] = newmax

                        # check wether self._maxlabel needs to be updated (up and down)
                        maxdirty = False
                        if newmax > self._maxLabel:
                            assert self._maxLabelHistogram[newmax] == 1
                            self._maxLabel = newmax
                        elif self._maxLabelHistogram[oldmax] == 0:
                            self._maxLabel = numpy.max(
                                numpy.nonzero(self._maxLabelHistogram)[0])

                        self.lock.release()

                        self.maxLabel.setValue(self._maxLabel)

                    self._labelers[b_ind].inputs["maxLabel"].notifyDirty(
                        partial(max_label_changed, b_ind))

                self._labelers[b_ind].inputs["Input"][smallkey] = smallvalues

        time2 = time.time()
        logger.debug("OpBlockedSparseLabelArray: setInSlot writing took %fs" %
                     (time2 - time1, ))

        # Trade-off here:
        # Instead of sending a separate dirty notification for each block we touched,
        #  we just send a single dirty notification for the entire encompassing roi.
        # This results in fewer notifications, but more "dirty" pixels.
        # Downstream operators will probably ask for updated values for all of the
        #  blocks we said were "dirty" even though some of them were not really touched.
        self.Output.setDirty(key)

        time3 = time.time()
        logger.debug("OpBlockedSparseLabelArray: setInSlot setDirty took %fs" %
                     (time3 - time2, ))
        logger.debug("OpBlockedSparseLabelArray: setInSlot total took %fs" %
                     (time3 - time1, ))