def createWidget(self, parent):
     t = FeatureTableWidget(parent)
     t.createTableForFeatureDlg( \
         {"Color": [FeatureEntry("Banana")],
          "Edge": [FeatureEntry("Mango"),
                   FeatureEntry("Cherry")] \
         }, \
         [0.3, 0.7, 1, 1.6, 3.5, 5.0, 10.0] \
     )
     return t
Example #2
0
    def initFeatureDlg(self):
        """
        Initialize the feature selection widget.
        """
        self.initFeatureOrder()

        self.featureDlg = FeatureDlg()
        self.featureDlg.setWindowTitle("Features")

        # Map from groups of feature IDs to groups of feature NAMEs
        groupedNames = []
        for group, featureIds in self.FeatureGroups:
            featureEntries = []
            for featureId in featureIds:
                featureName = self.FeatureNames[featureId]
                featureEntries.append(FeatureEntry(featureName))
            groupedNames.append((group, featureEntries))
        self.featureDlg.createFeatureTable(groupedNames, self.ScalesList)
        self.featureDlg.setImageToPreView(None)

        # Init with no features
        rows = len(self.mainOperator.FeatureIds.value)
        cols = len(self.mainOperator.Scales.value)
        defaultFeatures = numpy.zeros((rows, cols), dtype=bool)
        self.featureDlg.selectedFeatureBoolMatrix = defaultFeatures

        self.featureDlg.accepted.connect(self.onNewFeaturesFromFeatureDlg)
Example #3
0
    def onFeatureButtonClicked(self):
        # Remove all pre-computed feature files
        for slot in self.parentApplet.topLevelOperator.FeatureListFilename:
            slot.disconnect()

        # Slots need to be ready (they also should, as they have default values)
        assert self.topLevelOperatorView.FeatureIds.ready()
        assert self.topLevelOperatorView.Scales.ready()
        assert self.topLevelOperatorView.ComputeIn2d.ready(
        ), self.topLevelOperatorView.ComputeIn2d.value
        assert self.topLevelOperatorView.SelectionMatrix.ready()

        # Refresh the dialog data in case it has changed since the last time we were opened
        # (e.g. if the user loaded a project from disk)
        # This also ensures to restore the selection after previously canceling the feature dialog
        opFeatureSelection = self.topLevelOperatorView

        # Map from groups of feature IDs to groups of feature NAMEs
        groupedNames = []
        for group, featureIds in opFeatureSelection.FeatureGroups:
            featureEntries = []
            for featureId in featureIds:
                featureName = opFeatureSelection.FeatureNames[featureId]
                availableFilterOps = {
                    key[2:]: value
                    for key, value in filterOps.__dict__.items()
                    if key.startswith('Op')
                }
                minimum_scale = availableFilterOps[featureId].minimum_scale
                featureEntries.append(FeatureEntry(featureName, minimum_scale))
            groupedNames.append((group, featureEntries))
        self.featureDlg.createFeatureTable(
            groupedNames, opFeatureSelection.Scales.value,
            opFeatureSelection.ComputeIn2d.value,
            opFeatureSelection.WINDOW_SIZE)
        # update feature dialog to show/hide z dimension specific 'compute in 2d' flags
        if self.topLevelOperatorView.InputImage.ready(
        ) and self.topLevelOperatorView.ComputeIn2d.value:
            ts = self.topLevelOperatorView.InputImage.meta.getTaggedShape()
            hide = ('z' not in ts or ts['z'] == 1) and all(
                self.topLevelOperatorView.ComputeIn2d.value)
            self.featureDlg.setComputeIn2dHidden(hide)

        matrix = opFeatureSelection.SelectionMatrix.value
        featureOrdering = opFeatureSelection.FeatureIds.value

        # Re-order the feature matrix using the loaded feature ids
        reorderedMatrix = numpy.zeros(matrix.shape, dtype=bool)
        newrow = 0
        for group, featureIds in OpFeatureSelection.FeatureGroups:
            for featureId in featureIds:
                oldrow = featureOrdering.index(featureId)
                reorderedMatrix[newrow] = matrix[oldrow]
                newrow += 1

        self.featureDlg.selectionMatrix = reorderedMatrix

        # Now open the feature selection dialog
        self.featureDlg.exec_()
Example #4
0
def widget(qtbot):
    w = FeatureTableWidget(
        None,
        (
            ("Color", [FeatureEntry("Banana", minimum_scale=0.3)]),
            ("Edge", [FeatureEntry("Mango"),
                      FeatureEntry("Cherry")]),
        ),
        [0.3, 0.7, 1, 1.6, 3.5, 5.0, 10.0],
        computeIn2d=[True, False, True, True, True, False, False],
    )
    qtbot.addWidget(w)
    w.show()

    qtbot.waitForWindowShown(w)

    return w
Example #5
0
    def initFeatureDlg(self):
        """
        Initialize the feature selection widget.
        """
        self.initFeatureOrder()

        self.featureDlg = FeatureDlg(parent=self)
        self.featureDlg.setWindowTitle("Features")
        try:
            size = PreferencesManager().get("featureSelection", "dialog size")
            self.featureDlg.resize(*size)
        except TypeError:
            pass

        def saveSize():
            size = self.featureDlg.size()
            s = (size.width(), size.height())
            PreferencesManager().set("featureSelection", "dialog size", s)

        self.featureDlg.accepted.connect(saveSize)

        # Map from groups of feature IDs to groups of feature NAMEs
        groupedNames = []
        for group, featureIds in self.FeatureGroups:
            featureEntries = []
            for featureId in featureIds:
                featureName = self.FeatureNames[featureId]
                featureEntries.append(FeatureEntry(featureName))
            groupedNames.append((group, featureEntries))
        self.featureDlg.createFeatureTable(
            groupedNames, self.ScalesList,
            self.topLevelOperatorView.WINDOW_SIZE)
        self.featureDlg.setImageToPreView(None)

        # Init with no features
        rows = len(self.topLevelOperatorView.FeatureIds.value)
        cols = len(self.topLevelOperatorView.Scales.value)
        defaultFeatures = numpy.zeros((rows, cols), dtype=bool)
        self.featureDlg.selectedFeatureBoolMatrix = defaultFeatures

        self.featureDlg.accepted.connect(self.onNewFeaturesFromFeatureDlg)

        # Disable the first column, except for the first item.
        # This is a slightly hacky way of fixing ilastik issue #610.
        # Besides color, the features at a sigma of 0.3 are not valid because the
        #  results are overwhelmed by the inherent sampling noise of the filter.
        # (This is a bit hacky because we ASSUME the first feature is Gaussian
        # Smoothing.  It works for now.)
        enabled_item_mask = numpy.ones(defaultFeatures.shape, dtype=bool)
        enabled_item_mask[1:, 0] = False  # hacky
        self.featureDlg.setEnableItemMask(enabled_item_mask)
Example #6
0
    def initFeatureDlg(self):
        """
        Initialize the feature selection widget.
        """
        self.initFeatureOrder()

        self.featureDlg = FeatureDlg(parent=self)
        self.featureDlg.setWindowTitle("Features")
        try:
            size = PreferencesManager().get("featureSelection", "dialog size")
            self.featureDlg.resize(*size)
        except TypeError:
            pass

        def saveSize():
            size = self.featureDlg.size()
            s = (size.width(), size.height())
            PreferencesManager().set("featureSelection", "dialog size", s)

        self.featureDlg.accepted.connect(saveSize)

        # Map from groups of feature IDs to groups of feature NAMEs
        groupedNames = []
        for group, featureIds in self.FeatureGroups:
            featureEntries = []
            for featureId in featureIds:
                featureName = self.FeatureNames[featureId]
                featureEntries.append(FeatureEntry(featureName))
            groupedNames.append((group, featureEntries))
        self.featureDlg.createFeatureTable(groupedNames, self.ScalesList)
        self.featureDlg.setImageToPreView(None)

        # Init with no features
        rows = len(self.topLevelOperatorView.FeatureIds.value)
        cols = len(self.topLevelOperatorView.Scales.value)
        defaultFeatures = numpy.zeros((rows, cols), dtype=bool)
        self.featureDlg.selectedFeatureBoolMatrix = defaultFeatures

        self.featureDlg.accepted.connect(self.onNewFeaturesFromFeatureDlg)