def setupOutputs(self):

        self._opReorder2.AxisOrder.setValue(self.InputImage.meta.getAxisKeys())

        # propagate drange
        self.opThreshold1.InputImage.meta.drange = self.InputImage.meta.drange
        if haveGraphCut():
            self.opThreshold1GC.InputImage.meta.drange = self.InputImage.meta.drange
        self.opThreshold2.InputImage.meta.drange = self.InputImage.meta.drange

        self._disconnectAll()

        curIndex = self.CurOperator.value

        if curIndex == 0:
            outputSlot = self._connectForSingleThreshold(self.opThreshold1)
        elif curIndex == 1:
            outputSlot = self._connectForTwoLevelThreshold()
        elif curIndex == 2:
            outputSlot = self._connectForGraphCut()
        else:
            raise ValueError(
                "Unknown index {} for current tab.".format(curIndex))

        self._opReorder2.Input.connect(outputSlot)
        # force the cache to emit a dirty signal
        self._cache.Input.setDirty(slice(None))
 def _connectForGraphCut(self):
     assert haveGraphCut(), "Module for graph cut is not available"
     if self.UsePreThreshold.value:
         self._connectForSingleThreshold(self.opThreshold1GC)
         return self.opObjectsGraphCut.Output
     else:
         return self.opGraphCut.Output
Example #3
0
 def _connectForGraphCut(self):
     assert haveGraphCut(), "Module for graph cut is not available"
     if self.UsePreThreshold.value:
         self._connectForSingleThreshold(self.opThreshold1GC)
         return self.opObjectsGraphCut.Output
     else:
         return self.opGraphCut.Output
Example #4
0
    def setupOutputs(self):

        self._opReorder2.AxisOrder.setValue(self.InputImage.meta.getAxisKeys())

        # propagate drange
        self.opThreshold1.InputImage.meta.drange = self.InputImage.meta.drange
        if haveGraphCut():
            self.opThreshold1GC.InputImage.meta.drange = self.InputImage.meta.drange
        self.opThreshold2.InputImage.meta.drange = self.InputImage.meta.drange

        self._disconnectAll()

        curIndex = self.CurOperator.value

        if curIndex == 0:
            outputSlot = self._connectForSingleThreshold(self.opThreshold1)
        elif curIndex == 1:
            outputSlot = self._connectForTwoLevelThreshold()
        elif curIndex == 2:
            outputSlot = self._connectForGraphCut()
        elif curIndex == 3:
            outputSlot = self.opIpht.Output
        else:
            raise ValueError(
                "Unknown index {} for current tab.".format(curIndex))

        self._opReorder2.Input.connect(outputSlot)
        # force the cache to emit a dirty signal
        self._cache.Input.connect(outputSlot)
        self._cache.Input.setDirty(slice(None))
Example #5
0
 def _disconnectAll(self):
     # start from back
     for slot in [self.BigRegions, self.SmallRegions, self.FilteredSmallLabels, self.BeforeSizeFilter]:
         slot.disconnect()
         slot.meta.NOTREADY = True
     self._opReorder2.Input.disconnect()
     if haveGraphCut():
         self.opThreshold1GC.InputImage.disconnect()
     self.opThreshold1.InputImage.disconnect()
     self.opThreshold2.InputImage.disconnect()
Example #6
0
 def _disconnectAll(self):
     # start from back
     for slot in [
             self.BigRegions, self.SmallRegions, self.FilteredSmallLabels,
             self.BeforeSizeFilter
     ]:
         slot.disconnect()
         slot.meta.NOTREADY = True
     self._opReorder2.Input.disconnect()
     if haveGraphCut():
         self.opThreshold1GC.InputImage.disconnect()
     self.opThreshold1.InputImage.disconnect()
     self.opThreshold2.InputImage.disconnect()
Example #7
0
    def initAppletDrawerUi(self):
        """
        Reimplemented from LayerViewerGui base class.
        """
        # Load the ui file (find it in our own directory)
        localDir = os.path.split(__file__)[0]
        self._drawer = uic.loadUi(localDir + "/drawer.ui")

        # disable graph cut applet if not available
        if not haveGraphCut():
            self._drawer.tabWidget.setTabEnabled(2, False)

        self._sigmaSpinBoxes = {
            'x': self._drawer.sigmaSpinBox_X,
            'y': self._drawer.sigmaSpinBox_Y,
            'z': self._drawer.sigmaSpinBox_Z
        }

        self._allWatchedWidgets = self._sigmaSpinBoxes.values() + \
        [
            self._drawer.inputChannelComboBox,
            self._drawer.lowThresholdSpinBox,
            self._drawer.highThresholdSpinBox,
            self._drawer.thresholdSpinBox,
            self._drawer.minSizeSpinBox,
            self._drawer.maxSizeSpinBox,
            self._drawer.thresholdSpinBoxGC,
            self._drawer.lambdaSpinBoxGC
        ]

        for widget in self._allWatchedWidgets:
            # If the user pressed enter inside a spinbox, auto-click "Apply"
            widget.installEventFilter(self)

        self._drawer.showDebugCheckbox.stateChanged.connect(
            self._onShowDebugChanged)
        self._showDebug = False

        self._updateGuiFromOperator()
        self.topLevelOperatorView.InputImage.notifyReady(
            bind(self._updateGuiFromOperator))
        self.__cleanup_fns.append(
            partial(self.topLevelOperatorView.InputImage.unregisterUnready,
                    bind(self._updateGuiFromOperator)))

        self.topLevelOperatorView.InputImage.notifyMetaChanged(
            bind(self._updateGuiFromOperator))
        self.__cleanup_fns.append(
            partial(self.topLevelOperatorView.InputImage.unregisterMetaChanged,
                    bind(self._updateGuiFromOperator)))
    def initAppletDrawerUi(self):
        """
        Reimplemented from LayerViewerGui base class.
        """
        # Load the ui file (find it in our own directory)
        localDir = os.path.split(__file__)[0]
        self._drawer = uic.loadUi(localDir + "/drawer.ui")

        # disable graph cut applet if not available
        if not haveGraphCut():
            self._drawer.tabWidget.setTabEnabled(2, False)

        self._sigmaSpinBoxes = {
            "x": self._drawer.sigmaSpinBox_X,
            "y": self._drawer.sigmaSpinBox_Y,
            "z": self._drawer.sigmaSpinBox_Z,
        }

        self._allWatchedWidgets = self._sigmaSpinBoxes.values() + [
            self._drawer.inputChannelSpinBox,
            self._drawer.lowThresholdSpinBox,
            self._drawer.highThresholdSpinBox,
            self._drawer.thresholdSpinBox,
            self._drawer.minSizeSpinBox,
            self._drawer.maxSizeSpinBox,
            self._drawer.thresholdSpinBoxGC,
            self._drawer.lambdaSpinBoxGC,
        ]

        for widget in self._allWatchedWidgets:
            # If the user pressed enter inside a spinbox, auto-click "Apply"
            widget.installEventFilter(self)

        self._drawer.showDebugCheckbox.stateChanged.connect(self._onShowDebugChanged)
        self._showDebug = False

        self._updateGuiFromOperator()
        self.topLevelOperatorView.InputImage.notifyReady(bind(self._updateGuiFromOperator))
        self.__cleanup_fns.append(
            partial(self.topLevelOperatorView.InputImage.unregisterUnready, bind(self._updateGuiFromOperator))
        )

        self.topLevelOperatorView.InputImage.notifyMetaChanged(bind(self._updateGuiFromOperator))
        self.__cleanup_fns.append(
            partial(self.topLevelOperatorView.InputImage.unregisterMetaChanged, bind(self._updateGuiFromOperator))
        )
    def __init__(self, *args, **kwargs):
        super(OpThresholdTwoLevels, self).__init__(*args, **kwargs)

        self.InputImage.notifyReady( self.checkConstraints )

        self._opReorder1 = OpReorderAxes(parent=self)
        self._opReorder1.AxisOrder.setValue('txyzc')
        self._opReorder1.Input.connect(self.InputImage)

        self._opChannelSelector = OpSingleChannelSelector(parent=self)
        self._opChannelSelector.Input.connect(self._opReorder1.Output)
        self._opChannelSelector.Index.connect(self.Channel)

        # anisotropic gauss
        self._opSmoother = OpAnisotropicGaussianSmoothing5d(parent=self)
        self._opSmoother.Sigmas.connect(self.SmootherSigma)
        self._opSmoother.Input.connect(self._opChannelSelector.Output)

        # debug output
        self.Smoothed.connect(self._opSmoother.Output)

        # single threshold operator
        self.opThreshold1 = _OpThresholdOneLevel(parent=self)
        self.opThreshold1.Threshold.connect(self.SingleThreshold)
        self.opThreshold1.MinSize.connect(self.MinSize)
        self.opThreshold1.MaxSize.connect(self.MaxSize)

        # double threshold operator
        self.opThreshold2 = _OpThresholdTwoLevels(parent=self)
        self.opThreshold2.MinSize.connect(self.MinSize)
        self.opThreshold2.MaxSize.connect(self.MaxSize)
        self.opThreshold2.LowThreshold.connect(self.LowThreshold)
        self.opThreshold2.HighThreshold.connect(self.HighThreshold)

        if haveGraphCut():
            self.opThreshold1GC = _OpThresholdOneLevel(parent=self)
            self.opThreshold1GC.Threshold.connect(self.SingleThresholdGC)
            self.opThreshold1GC.MinSize.connect(self.MinSize)
            self.opThreshold1GC.MaxSize.connect(self.MaxSize)

            self.opObjectsGraphCut = OpObjectsSegment(parent=self)
            self.opObjectsGraphCut.Prediction.connect(self.Smoothed)
            self.opObjectsGraphCut.LabelImage.connect(self.opThreshold1GC.Output)
            self.opObjectsGraphCut.Beta.connect(self.Beta)
            self.opObjectsGraphCut.Margin.connect(self.Margin)

            self.opGraphCut = OpGraphCut(parent=self)
            self.opGraphCut.Prediction.connect(self.Smoothed)
            self.opGraphCut.Beta.connect(self.Beta)

        self._op5CacheOutput = OpReorderAxes(parent=self)

        self._opReorder2 = OpReorderAxes(parent=self)
        self.Output.connect(self._opReorder2.Output)

        #cache our own output, don't propagate from internal operator
        self._cache = _OpCacheWrapper(parent=self)
        self._cache.name = "OpThresholdTwoLevels.OpCacheWrapper"
        self._cache.Input.connect(self.Output)
        self.CachedOutput.connect(self._cache.Output)

        # Serialization slots
        self._cache.InputHdf5.connect(self.InputHdf5)
        self.CleanBlocks.connect(self._cache.CleanBlocks)
        self.OutputHdf5.connect(self._cache.OutputHdf5)

        #Debug outputs
        self.InputChannel.connect(self._opChannelSelector.Output)
from lazyflow.operators import OpPixelOperator, OpLabelVolume,\
    OpCompressedCache, OpColorizeLabels,\
    OpSingleChannelSelector, OperatorWrapper,\
    OpMultiArrayStacker, OpMultiArraySlicer,\
    OpReorderAxes, OpFilterLabels
from lazyflow.rtype import SubRegion
from lazyflow.request import Request, RequestPool

# local
from thresholdingTools import OpAnisotropicGaussianSmoothing5d

from thresholdingTools import OpSelectLabels

from opGraphcutSegment import haveGraphCut

if haveGraphCut():
    from opGraphcutSegment import OpObjectsSegment, OpGraphCut


logger = logging.getLogger(__name__)

# determine labeling implementation
try:
    _labeling_impl = ilastik.config.cfg.get("ilastik", "labeling")
except NoOptionError:
    _labeling_impl = "vigra"
#FIXME check validity of implementation
logger.info("Using '{}' labeling implemetation".format(_labeling_impl))


## High level operator for one/two level threshold
Example #11
0
    def __init__(self, *args, **kwargs):
        super(OpThresholdTwoLevels, self).__init__(*args, **kwargs)

        self.InputImage.notifyReady(self.checkConstraints)

        self._opReorder1 = OpReorderAxes(parent=self)
        self._opReorder1.AxisOrder.setValue('txyzc')
        self._opReorder1.Input.connect(self.InputImage)

        self._opChannelSelector = OpSingleChannelSelector(parent=self)
        self._opChannelSelector.Input.connect(self._opReorder1.Output)
        self._opChannelSelector.Index.connect(self.Channel)

        # anisotropic gauss
        self._opSmoother = OpAnisotropicGaussianSmoothing5d(parent=self)
        self._opSmoother.Sigmas.connect(self.SmootherSigma)
        self._opSmoother.Input.connect(self._opChannelSelector.Output)

        # debug output
        self.Smoothed.connect(self._opSmoother.Output)

        # single threshold operator
        self.opThreshold1 = _OpThresholdOneLevel(parent=self)
        self.opThreshold1.Threshold.connect(self.SingleThreshold)
        self.opThreshold1.MinSize.connect(self.MinSize)
        self.opThreshold1.MaxSize.connect(self.MaxSize)

        # double threshold operator
        self.opThreshold2 = _OpThresholdTwoLevels(parent=self)
        self.opThreshold2.MinSize.connect(self.MinSize)
        self.opThreshold2.MaxSize.connect(self.MaxSize)
        self.opThreshold2.LowThreshold.connect(self.LowThreshold)
        self.opThreshold2.HighThreshold.connect(self.HighThreshold)

        # Identity-preserving hysteresis thresholding
        self.opIpht = OpIpht(parent=self)
        self.opIpht.MinSize.connect(self.MinSize)
        self.opIpht.MaxSize.connect(self.MaxSize)
        self.opIpht.LowThreshold.connect(self.LowThreshold)
        self.opIpht.HighThreshold.connect(self.HighThreshold)
        self.opIpht.InputImage.connect(self._opSmoother.Output)

        if haveGraphCut():
            self.opThreshold1GC = _OpThresholdOneLevel(parent=self)
            self.opThreshold1GC.Threshold.connect(self.SingleThresholdGC)
            self.opThreshold1GC.MinSize.connect(self.MinSize)
            self.opThreshold1GC.MaxSize.connect(self.MaxSize)

            self.opObjectsGraphCut = OpObjectsSegment(parent=self)
            self.opObjectsGraphCut.Prediction.connect(self.Smoothed)
            self.opObjectsGraphCut.LabelImage.connect(
                self.opThreshold1GC.Output)
            self.opObjectsGraphCut.Beta.connect(self.Beta)
            self.opObjectsGraphCut.Margin.connect(self.Margin)

            self.opGraphCut = OpGraphCut(parent=self)
            self.opGraphCut.Prediction.connect(self.Smoothed)
            self.opGraphCut.Beta.connect(self.Beta)

        self._op5CacheOutput = OpReorderAxes(parent=self)

        self._opReorder2 = OpReorderAxes(parent=self)
        self.Output.connect(self._opReorder2.Output)

        #cache our own output, don't propagate from internal operator
        self._cache = _OpCacheWrapper(parent=self)
        self._cache.name = "OpThresholdTwoLevels.OpCacheWrapper"
        self.CachedOutput.connect(self._cache.Output)

        # Serialization slots
        self._cache.InputHdf5.connect(self.InputHdf5)
        self.CleanBlocks.connect(self._cache.CleanBlocks)
        self.OutputHdf5.connect(self._cache.OutputHdf5)

        #Debug outputs
        self.InputChannel.connect(self._opChannelSelector.Output)
Example #12
0
from lazyflow.operators import OpPixelOperator, OpLabelVolume,\
    OpCompressedCache, OpColorizeLabels,\
    OpSingleChannelSelector, OperatorWrapper,\
    OpMultiArrayStacker, OpMultiArraySlicer,\
    OpReorderAxes, OpFilterLabels
from lazyflow.rtype import SubRegion
from lazyflow.request import Request, RequestPool

# local
from thresholdingTools import OpAnisotropicGaussianSmoothing5d

from thresholdingTools import OpSelectLabels

from opGraphcutSegment import haveGraphCut

if haveGraphCut():
    from opGraphcutSegment import OpObjectsSegment, OpGraphCut

logger = logging.getLogger(__name__)

# determine labeling implementation
try:
    _labeling_impl = ilastik.config.cfg.get("ilastik", "labeling")
except NoOptionError:
    _labeling_impl = "vigra"
#FIXME check validity of implementation
logger.info("Using '{}' labeling implemetation".format(_labeling_impl))


## High level operator for one/two level threshold
class OpThresholdTwoLevels(Operator):
Example #13
0
    def __init__(self, *args, **kwargs):
        super(OpThresholdTwoLevels, self).__init__(*args, **kwargs)

        self.InputImage.notifyReady( self.checkConstraints )

        self._opReorder1 = OpReorderAxes(parent=self)
        self._opReorder1.AxisOrder.setValue('txyzc')
        self._opReorder1.Input.connect(self.InputImage)

        # slice in time for anisotropic gauss
        self._opTimeSlicer = OpMultiArraySlicer(parent=self)
        self._opTimeSlicer.AxisFlag.setValue('t')
        self._opTimeSlicer.Input.connect(self._opReorder1.Output)
        assert self._opTimeSlicer.Slices.level == 1

        self._opChannelSelector = OperatorWrapper(OpSingleChannelSelector, parent=self)
        self._opChannelSelector.Input.connect(self._opTimeSlicer.Slices)
        self._opChannelSelector.Index.connect(self.Channel)

        # anisotropic gauss
        self._opSmoother = OperatorWrapper(OpAnisotropicGaussianSmoothing,
                                           parent=self,
                                           broadcastingSlotNames=['Sigmas'])
        self._opSmoother.Sigmas.connect(self.SmootherSigma)
        self._opSmoother.Input.connect(self._opChannelSelector.Output)

        # stack output again, everything is now going to work for arbitrary dimensions
        self._smoothStacker = OpMultiArrayStacker(parent=self)
        self._smoothStacker.AxisFlag.setValue('t')
        self._smoothStacker.AxisIndex.setValue(0)
        self._smoothStacker.Images.connect(self._opSmoother.Output)

        # debug output
        self.Smoothed.connect(self._smoothStacker.Output)

        # single threshold operator
        self.opThreshold1 = _OpThresholdOneLevel(parent=self)
        self.opThreshold1.InputImage.connect(self._smoothStacker.Output)
        self.opThreshold1.Threshold.connect(self.SingleThreshold)
        self.opThreshold1.MinSize.connect(self.MinSize)
        self.opThreshold1.MaxSize.connect(self.MaxSize)

        # double threshold operator
        self.opThreshold2 = _OpThresholdTwoLevels(parent=self)
        self.opThreshold2.InputImage.connect(self._smoothStacker.Output)
        self.opThreshold2.MinSize.connect(self.MinSize)
        self.opThreshold2.MaxSize.connect(self.MaxSize)
        self.opThreshold2.LowThreshold.connect(self.LowThreshold)
        self.opThreshold2.HighThreshold.connect(self.HighThreshold)

        if haveGraphCut():
            self.opThreshold1GC = _OpThresholdOneLevel(parent=self)
            self.opThreshold1GC.InputImage.connect(self._smoothStacker.Output)
            self.opThreshold1GC.Threshold.connect(self.SingleThresholdGC)
            self.opThreshold1GC.MinSize.connect(self.MinSize)
            self.opThreshold1GC.MaxSize.connect(self.MaxSize)

            self.opObjectsGraphCut = OpObjectsSegment(parent=self)
            self.opObjectsGraphCut.Prediction.connect(self._smoothStacker.Output)
            self.opObjectsGraphCut.LabelImage.connect(self.opThreshold1GC.Output)
            self.opObjectsGraphCut.Beta.connect(self.Beta)
            self.opObjectsGraphCut.Margin.connect(self.Margin)

            self.opGraphCut = OpGraphCut(parent=self)
            self.opGraphCut.Prediction.connect(self._smoothStacker.Output)
            self.opGraphCut.Beta.connect(self.Beta)

        # HACK: For backwards compatibility with old projects,
        #       the cache must by in xyzct order,
        #       because the cache is loaded directly from the serializer
        self._op5CacheInput = OpReorderAxes(parent=self)
        self._op5CacheInput.AxisOrder.setValue("xyzct")

        #cache our own output, don't propagate from internal operator
        self._opCache = OpCompressedCache(parent=self)
        self._opCache.name = "OpThresholdTwoLevels._opCache"
        self._opCache.InputHdf5.connect(self.InputHdf5)
        self._opCache.Input.connect(self._op5CacheInput.Output)

        self._op5CacheOutput = OpReorderAxes(parent=self)
        self._op5CacheOutput.Input.connect(self._opCache.Output)

        self._opReorder2 = OpReorderAxes(parent=self)
        self.Output.connect(self._opReorder2.Output)

        self.CachedOutput.connect(self._op5CacheOutput.Output)

        # Serialization outputs
        self.CleanBlocks.connect(self._opCache.CleanBlocks)
        self.OutputHdf5.connect(self._opCache.OutputHdf5)

        #Debug outputs
        self._inputStacker = OpMultiArrayStacker(parent=self)
        self._inputStacker.AxisFlag.setValue('t')
        self._inputStacker.AxisIndex.setValue(0)
        self._inputStacker.Images.connect(self._opChannelSelector.Output)
        self.InputChannel.connect(self._inputStacker.Output)