Example #1
0
 def propagateDirty(self, slot, subindex, roi):
     key = roi.toSlice()
     if slot == self.Input:
         key = key[:-1] + (slice(0,1,None),)
         self.outputs["Output"].setDirty(key)
     else:
         self.Output.setDirty(slice(None))
Example #2
0
 def propagateDirty(self, dirtySlot, subindex, roi):
     if dirtySlot == self.MergingFunction:
         self.Output.setDirty(slice(None))
     elif dirtySlot == self.Inputs:
         # Assumes a pixel-wise merge function.
         key = roi.toSlice()
         self.Output.setDirty(key)
Example #3
0
 def propagateDirty(self, dirtySlot, subindex, roi):
     if dirtySlot == self.MergingFunction:
         self.Output.setDirty( slice(None) )
     elif dirtySlot == self.Inputs:
         # Assumes a pixel-wise merge function.
         key = roi.toSlice()
         self.Output.setDirty( key )
Example #4
0
 def propagateDirty(self, slot, subindex, roi):
     key = roi.toSlice()
     if slot == self.Input:
         self.outputs["Output"].setDirty(key)
     elif slot == self.Function:
         self.Output.setDirty(slice(None))
     else:
         assert False, "Unknown dirty input slot"
Example #5
0
 def propagateDirty(self, slot, subindex, roi):
     key = roi.toSlice()
     if slot == self.Input:
         self.outputs["Output"].setDirty(key)
     elif slot == self.Function:
         self.Output.setDirty( slice(None) )
     else:
         assert False, "Unknown dirty input slot"
Example #6
0
 def propagateDirty(self, slot, subindex, roi):
     key = roi.toSlice()
     if slot == self.Input:
         channelIndex = self.Input.meta.axistags.channelIndex
         newKey = list(key)
         newKey[channelIndex] = slice(0, 1, None)
         # key = key[:-1] + (slice(0,1,None),)
         self.outputs["Output"].setDirty(tuple(newKey))
     else:
         self.Output.setDirty(slice(None))
Example #7
0
 def propagateDirty(self, slot, subindex, roi):
     key = roi.toSlice()
     if slot == self.Input:
         channelIndex = self.Input.meta.axistags.channelIndex
         newKey = list(key)
         newKey[channelIndex] = slice(0, 1, None)
         #key = key[:-1] + (slice(0,1,None),)
         self.outputs["Output"].setDirty(tuple(newKey))
     else:
         self.Output.setDirty(slice(None))
Example #8
0
 def propagateDirty(self, slot, subindex, roi):
     key = roi.toSlice()
     # Check for proper name because subclasses may define extra inputs.
     # (but decline to override notifyDirty)
     if slot is self.Input:
         self.Output.setDirty(key)
     else:
         # If some input we don't know about is dirty (i.e. we are subclassed by an operator with extra inputs),
         # then mark the entire output dirty.  This is the correct behavior for e.g. 'sigma' inputs.
         self.Output.setDirty(slice(None))
Example #9
0
    def execute(self, slot, subindex, roi, result):
        key = roi.toSlice()
        data = self.inputs["Input"][key[:-1]+(slice(None),)].wait()
    
        #FIXME: only works if channels are in last dimension
        dm = numpy.max(data, axis = data.ndim-1)
        res = numpy.zeros(data.shape, numpy.uint8)

        for c in range(data.shape[-1]):
            res[...,c] = numpy.where(data[...,c] == dm, 1, 0)    

        result[:] = res[...,key[-1]]
Example #10
0
    def execute(self, slot, subindex, roi, result):
        key = roi.toSlice()
        data = self.inputs["Input"][key[:-1] + (slice(None), )].wait()

        #FIXME: only works if channels are in last dimension
        dm = numpy.max(data, axis=data.ndim - 1)
        res = numpy.zeros(data.shape, numpy.uint8)

        for c in range(data.shape[-1]):
            numpy.equal(data[..., c], dm, out=res[..., c])

        result[:] = res[..., key[-1]]
Example #11
0
    def execute(self, slot, subindex, roi, result):
        *key, c = roi.toSlice()

        n_channels_requested = c.stop - c.start
        if n_channels_requested != 1:
            raise InvalidRoiException(
                f"This operator only accepts slices of size 1 for c! Got {n_channels_requested}."
            )

        data = self.Input[(*key, slice(None))].wait()

        # special case, when data is all zeros (e.g. directly from frozen cache w/o trained classifier)
        if not numpy.any(data):
            result[:] = 0
            return

        result[:] = numpy.uint8(
            numpy.argmax(data, axis=-1) == c.start)[..., numpy.newaxis]
Example #12
0
    def execute(self, slot, subindex, roi, result):
        key = roi.toSlice()
        data = self.inputs["Input"][key[:-1] + (slice(None),)].wait()

        dm = numpy.max(data, axis=data.ndim - 1, keepdims=True)
        res = numpy.zeros(data.shape, numpy.uint8)
        numpy.equal(data, dm, out=res)

        # Special case: If all channels are tied, then none of them win.
        tied_pixels = numpy.logical_and.reduce(res, axis=-1, keepdims=True, dtype=numpy.uint8)

        # We could use numpy.concatenate():
        #  tied_pixels = numpy.concatenate((tied_pixels, tied_pixels), axis=-1)
        # But that's not as fast as duplicating the array with a stride trick.
        # (This only works because channel is the last axis.)
        tied_pixels = numpy.lib.stride_tricks.as_strided(tied_pixels, shape=res.shape, strides=tied_pixels.strides)
        res[tied_pixels] = 0

        result[:] = res[..., key[-1]]
Example #13
0
 def propagateDirty(self, slot, subindex, roi):
     if slot == self.AxisFlag:
         for i,s in enumerate(self.Slices):
             s.setDirty( slice(None) )
     elif slot == self.Input:
         key = roi.toSlice()
         reducedKey = list(key)
         inputTags = self.Input.meta.axistags
         flag = self.AxisFlag.value
         axisSlice = reducedKey.pop( inputTags.index(flag) )
         
         axisStart, axisStop = axisSlice.start, axisSlice.stop
         if axisStart is None:
             axisStart = 0
         if axisStop is None:
             axisStop = len( self.Slices )
 
         for i in range(axisStart, axisStop):
             self.Slices[i].setDirty( reducedKey )
     else:
         assert False, "Unknown dirty input slot"
Example #14
0
    def propagateDirty(self, slot, subindex, roi):
        if slot == self.AxisFlag:
            for i, s in enumerate(self.Slices):
                s.setDirty(slice(None))
        elif slot == self.Input:
            key = roi.toSlice()
            reducedKey = list(key)
            inputTags = self.Input.meta.axistags
            flag = self.AxisFlag.value
            axisSlice = reducedKey.pop(inputTags.index(flag))

            axisStart, axisStop = axisSlice.start, axisSlice.stop
            if axisStart is None:
                axisStart = 0
            if axisStop is None:
                axisStop = len(self.Slices)

            for i in range(axisStart, axisStop):
                self.Slices[i].setDirty(reducedKey)
        else:
            assert False, "Unknown dirty input slot"
Example #15
0
    def execute(self, slot, subindex, roi, result):
        key = roi.toSlice()
        data = self.inputs["Input"][key[:-1] + (slice(None), )].wait()

        dm = numpy.max(data, axis=data.ndim - 1, keepdims=True)
        res = numpy.zeros(data.shape, numpy.uint8)
        numpy.equal(data, dm, out=res)

        # Special case: If all channels are tied, then none of them win.
        tied_pixels = numpy.logical_and.reduce(res,
                                               axis=-1,
                                               keepdims=True,
                                               dtype=numpy.uint8)

        # We could use numpy.concatenate():
        #  tied_pixels = numpy.concatenate((tied_pixels, tied_pixels), axis=-1)
        # But that's not as fast as duplicating the array with a stride trick.
        # (This only works because channel is the last axis.)
        tied_pixels = numpy.lib.stride_tricks.as_strided(
            tied_pixels, shape=res.shape, strides=tied_pixels.strides)
        res[tied_pixels] = 0

        result[:] = res[..., key[-1]]
Example #16
0
 def execute(self, slot, subindex, roi, result):
     key = roi.toSlice()
     result[...] = self._data[key]
Example #17
0
 def execute(self, slot, subindex, roi, result):
     key = roi.toSlice()
     result[...] = self.Input(roi.start, roi.stop).wait()
Example #18
0
 def setInSlot(self, slot, subindex, roi, value):
     self.Output[0][roi.toSlice()] = value
Example #19
0
 def propagateDirty(self, slot, subindex, roi):
     key = roi.toSlice()
     if slot == self.Input:
         self.outputs["Output"].setDirty(key)
Example #20
0
 def setInSlot(self, slot, subindex, roi, value):
     self.Output[0][roi.toSlice()] = value
Example #21
0
 def setInSlot(self, slot, subindex, roi, value):
     # Forward to output
     assert subindex == ()
     assert slot == self.Input
     key = roi.toSlice()
     self.Output[key] = value
Example #22
0
 def propagateDirty(self, slot, subindex, roi):
     key = roi.toSlice()
     if slot == self.Input:
         self.outputs["Output"].setDirty(key)