def _populate_feature_dict(self, mainOperator):
        featureDict = {}
        plugins = pluginManager.getPluginsOfCategory('ObjectFeatures')
        taggedShape = mainOperator.RawImage.meta.getTaggedShape()
        fakeimgshp = [taggedShape['x'], taggedShape['y']]
        fakelabelsshp = [taggedShape['x'], taggedShape['y']]
        ndim = 3
        if 'z' in taggedShape and taggedShape['z'] > 1:
            fakeimgshp.append(taggedShape['z'])
            fakelabelsshp.append(taggedShape['z'])
            ndim = 3
        else:
            ndim = 2
        if 'c' in taggedShape and taggedShape['c'] > 1:
            fakeimgshp.append(taggedShape['c'])

        fakeimg = numpy.empty(fakeimgshp, dtype=numpy.float32)
        fakelabels = numpy.empty(fakelabelsshp, dtype=numpy.uint32)

        if ndim == 3:
            fakelabels = vigra.taggedView(fakelabels, 'xyz')
            if len(fakeimgshp) == 4:
                fakeimg = vigra.taggedView(fakeimg, 'xyzc')
            else:
                fakeimg = vigra.taggedView(fakeimg, 'xyz')
        if ndim == 2:
            fakelabels = vigra.taggedView(fakelabels, 'xy')
            if len(fakeimgshp) == 3:
                fakeimg = vigra.taggedView(fakeimg, 'xyc')
            else:
                fakeimg = vigra.taggedView(fakeimg, 'xy')

        for pluginInfo in plugins:
            availableFeatures = pluginInfo.plugin_object.availableFeatures(
                fakeimg, fakelabels)
            if len(availableFeatures) > 0:
                featureDict[pluginInfo.name] = availableFeatures

        # Make sure no plugins use the same feature names.
        # (Currently, our feature export implementation doesn't support repeated column names.)
        all_feature_names = chain(*[
            list(plugin_dict.keys())
            for plugin_dict in list(featureDict.values())
        ])
        feature_set = Counter(all_feature_names)
        # remove all elements with a count of 1
        feature_set = feature_set - Counter(feature_set.keys())
        if feature_set:
            offending_feature_names = feature_set.keys()
            raise ValueError(
                'Feature names used in multiple plugins. '
                f'Offending feature names: {list(offending_feature_names)}')
        return featureDict, ndim
    def getAvailablePlugins(cls):
        '''
        Checks whether any plugins are found and whether we use the hytra backend.
        Returns the list of available plugins
        '''
        try:
            import hytra
            # export plugins only available with hytra backend
            exportPlugins = pluginManager.getPluginsOfCategory('TrackingExportFormats')
            availableExportPlugins = [pluginInfo.name for pluginInfo in exportPlugins]

            return availableExportPlugins
        except ImportError:
            return []
    def _getAvailablePlugins(self):
        '''
        Checks whether any plugins are found and whether we use the hytra backend.
        Returns the list of available plugins
        '''
        try:
            import hytra
            # export plugins only available with hytra backend
            exportPlugins = pluginManager.getPluginsOfCategory('TrackingExportFormats')
            availableExportPlugins = [pluginInfo.name for pluginInfo in exportPlugins]

            return availableExportPlugins
        except ImportError:
            return []
    def _populate_feature_dict(self, mainOperator):
        featureDict = {}
        plugins = pluginManager.getPluginsOfCategory('ObjectFeatures')
        taggedShape = mainOperator.RawImage.meta.getTaggedShape()
        fakeimgshp = [taggedShape['x'], taggedShape['y']]
        fakelabelsshp = [taggedShape['x'], taggedShape['y']]
        ndim = 3
        if 'z' in taggedShape and taggedShape['z'] > 1:
            fakeimgshp.append(taggedShape['z'])
            fakelabelsshp.append(taggedShape['z'])
            ndim = 3
        else:
            ndim = 2
        if 'c' in taggedShape and taggedShape['c'] > 1:
            fakeimgshp.append(taggedShape['c'])

        fakeimg = numpy.empty(fakeimgshp, dtype=numpy.float32)
        fakelabels = numpy.empty(fakelabelsshp, dtype=numpy.uint32)

        if ndim == 3:
            fakelabels = vigra.taggedView(fakelabels, 'xyz')
            if len(fakeimgshp) == 4:
                fakeimg = vigra.taggedView(fakeimg, 'xyzc')
            else:
                fakeimg = vigra.taggedView(fakeimg, 'xyz')
        if ndim == 2:
            fakelabels = vigra.taggedView(fakelabels, 'xy')
            if len(fakeimgshp) == 3:
                fakeimg = vigra.taggedView(fakeimg, 'xyc')
            else:
                fakeimg = vigra.taggedView(fakeimg, 'xy')

        for pluginInfo in plugins:
            availableFeatures = pluginInfo.plugin_object.availableFeatures(fakeimg, fakelabels)
            if len(availableFeatures) > 0:
                featureDict[pluginInfo.name] = availableFeatures

        # Make sure no plugins use the same feature names.
        # (Currently, our feature export implementation doesn't support repeated column names.)
        all_feature_names = chain(
            *[list(plugin_dict.keys()) for plugin_dict in list(featureDict.values())])
        feature_set = Counter(all_feature_names)
        # remove all elements with a count of 1
        feature_set = feature_set - Counter(feature_set.keys())
        if feature_set:
            offending_feature_names = feature_set.keys()
            raise ValueError(
                'Feature names used in multiple plugins. '
                f'Offending feature names: {list(offending_feature_names)}')
        return featureDict, ndim
    def _selectFeaturesButtonPressed(self):
        featureDict = {}
        slot = self.mainOperator.Features
        if slot.ready():
            selectedFeatures = self.mainOperator.Features([]).wait()
        else:
            selectedFeatures = None

        try:
            plugins = pluginManager.getPluginsOfCategory('ObjectFeatures')
        except:
            QMessageBox.warning(self,
                                'object features unavailable',
                                'Object features plugins failed. Perhaps Yapsy is not installed?',
                                QMessageBox.Ok)
            return

        imgshape = list(self.mainOperator.RawImage.meta.shape)
        axistags = self.mainOperator.RawImage.meta.axistags
        imgshape.pop(axistags.index('t'))
        fakeimg = np.empty(imgshape, dtype=np.float32)

        labelshape = list(self.mainOperator.BinaryImage.meta.shape)
        axistags = self.mainOperator.BinaryImage.meta.axistags
        labelshape.pop(axistags.index('t'))
        labelshape.pop(axistags.index('c') - 1)
        fakelabels = np.empty(labelshape, dtype=np.uint32)

        for pluginInfo in plugins:
            featureDict[pluginInfo.name] = pluginInfo.plugin_object.availableFeatures(fakeimg, fakelabels)
        dlg = FeatureSelectionDialog(featureDict=featureDict,
                                     selectedFeatures=selectedFeatures)
        dlg.exec_()

        if dlg.result() == QDialog.Accepted:
            self.mainOperator.Features.setValue(dlg.selectedFeatures)
            self._calculateFeatures()
    def _selectFeaturesButtonPressed(self):
        featureDict = {}
        mainOperator = self.topLevelOperatorView
        slot = mainOperator.Features
        if slot.ready():
            selectedFeatures = mainOperator.Features([]).wait()
        else:
            selectedFeatures = None

        plugins = pluginManager.getPluginsOfCategory('ObjectFeatures')

        imgshape = list(mainOperator.RawImage.meta.shape)
        axistags = mainOperator.RawImage.meta.axistags
        imgshape.pop(axistags.index('t'))
        fakeimg = np.empty(imgshape, dtype=np.float32)

        labelshape = list(mainOperator.BinaryImage.meta.shape)
        axistags = mainOperator.BinaryImage.meta.axistags
        labelshape.pop(axistags.index('t'))
        labelshape.pop(axistags.index('c') - 1)
        fakelabels = np.empty(labelshape, dtype=np.uint32)
        
        ndim = 3
        zIndex = axistags.index('z')
        if len(labelshape)==2 or (zIndex<len(mainOperator.RawImage.meta.shape) and mainOperator.RawImage.meta.shape[zIndex]==1):
            ndim=2
        
        for pluginInfo in plugins:
            featureDict[pluginInfo.name] = pluginInfo.plugin_object.availableFeatures(fakeimg, fakelabels)
        dlg = FeatureSelectionDialog(featureDict=featureDict,
                                     selectedFeatures=selectedFeatures, ndim=ndim)
        dlg.exec_()

        if dlg.result() == QDialog.Accepted:
            mainOperator.Features.setValue(dlg.selectedFeatures)
            self._calculateFeatures()
    def _selectFeaturesButtonPressed(self):
        featureDict = {}
        mainOperator = self.topLevelOperatorView
        if not mainOperator.RawImage.ready():
            mexBox=QMessageBox()
            mexBox.setText("Please add the raw data before selecting features")
            mexBox.exec_()
            return
        
        if not mainOperator.BinaryImage.ready():
            mexBox=QMessageBox()
            mexBox.setText("Please add binary (segmentation) data before selecting features ")
            mexBox.exec_()
            return
        
        slot = mainOperator.Features
        if slot.ready():
            selectedFeatures = mainOperator.Features([]).wait()
        else:
            selectedFeatures = None

        plugins = pluginManager.getPluginsOfCategory('ObjectFeatures')

        taggedShape = mainOperator.RawImage.meta.getTaggedShape()
        fakeimg = None
        fakeimgshp = [taggedShape['x'], taggedShape['y']]
        fakelabelsshp = [taggedShape['x'], taggedShape['y']]
        ndim = 3
        if 'z' in taggedShape and taggedShape['z']>1:
            fakeimgshp.append(taggedShape['z'])
            fakelabelsshp.append(taggedShape['z'])
            ndim = 3
        else:
            ndim = 2
        if 'c' in taggedShape and taggedShape['c']>1:
            fakeimgshp.append(taggedShape['c'])
        
        fakeimg = np.empty(fakeimgshp, dtype=np.float32)
        fakelabels = np.empty(fakelabelsshp, dtype=np.uint32)
        
        if ndim==3:
            fakelabels = vigra.taggedView(fakelabels, 'xyz')
            if len(fakeimgshp)==4:
                fakeimg = vigra.taggedView(fakeimg, 'xyzc')
            else:
                fakeimg = vigra.taggedView(fakeimg, 'xyz')
        if ndim==2:
            fakelabels = vigra.taggedView(fakelabels, 'xy')
            if len(fakeimgshp)==3:
                fakeimg = vigra.taggedView(fakeimg, 'xyc')
            else:
                fakeimg = vigra.taggedView(fakeimg, 'xy')
        
        for pluginInfo in plugins:
            featureDict[pluginInfo.name] = pluginInfo.plugin_object.availableFeatures(fakeimg, fakelabels)
        dlg = FeatureSelectionDialog(featureDict=featureDict,
                                     selectedFeatures=selectedFeatures, ndim=ndim)
        dlg.exec_()

        if dlg.result() == QDialog.Accepted:
            mainOperator.Features.setValue(dlg.selectedFeatures)
            self._calculateFeatures()
    def handleSubsetFeaturesClicked(self):
        mainOperator = self.topLevelOperatorView
        computedFeatures = copy.deepcopy(
            mainOperator.ComputedFeatureNames([]).wait())
        # do NOT show default features, the user did not want them for classification
        # the key for the fake plugin of default features is taken from the top of opObjectExtraction file
        if mainOperator.SelectedFeatures.ready():
            selectedFeatures = copy.deepcopy(
                mainOperator.SelectedFeatures([]).wait())
        else:
            selectedFeatures = computedFeatures

        plugins = pluginManager.getPluginsOfCategory('ObjectFeatures')
        taggedShape = mainOperator.RawImages.meta.getTaggedShape()
        fakeimgshp = [taggedShape['x'], taggedShape['y']]
        fakelabelsshp = [taggedShape['x'], taggedShape['y']]

        if 'z' in taggedShape and taggedShape['z'] > 1:
            fakeimgshp.append(taggedShape['z'])
            fakelabelsshp.append(taggedShape['z'])
            ndim = 3
        else:
            ndim = 2
        if 'c' in taggedShape and taggedShape['c'] > 1:
            fakeimgshp.append(taggedShape['c'])

        fakeimg = numpy.empty(fakeimgshp, dtype=numpy.float32)
        fakelabels = numpy.empty(fakelabelsshp, dtype=numpy.uint32)

        if ndim == 3:
            fakelabels = vigra.taggedView(fakelabels, 'xyz')
            if len(fakeimgshp) == 4:
                fakeimg = vigra.taggedView(fakeimg, 'xyzc')
            else:
                fakeimg = vigra.taggedView(fakeimg, 'xyz')
        if ndim == 2:
            fakelabels = vigra.taggedView(fakelabels, 'xy')
            if len(fakeimgshp) == 3:
                fakeimg = vigra.taggedView(fakeimg, 'xyc')
            else:
                fakeimg = vigra.taggedView(fakeimg, 'xy')

        for pluginInfo in plugins:
            availableFeatures = pluginInfo.plugin_object.availableFeatures(
                fakeimg, fakelabels)
            if len(availableFeatures) > 0:
                if pluginInfo.name in list(
                        self.applet._selectedFeatures.keys()):
                    assert pluginInfo.name in list(
                        computedFeatures.keys()
                    ), 'Object Classification: {} not found in available (computed) object features'.format(
                        pluginInfo.name)

                if not pluginInfo.name in selectedFeatures and pluginInfo.name in self.applet._selectedFeatures:
                    selectedFeatures[pluginInfo.name] = dict()

                    for feature in list(self.applet._selectedFeatures[
                            pluginInfo.name].keys()):
                        if feature in list(availableFeatures.keys()):
                            selectedFeatures[pluginInfo.name][
                                feature] = availableFeatures[feature]

        dlg = FeatureSubSelectionDialog(computedFeatures,
                                        selectedFeatures=selectedFeatures,
                                        ndim=ndim)
        dlg.exec_()
        if dlg.result() == QDialog.Accepted:
            if len(dlg.selectedFeatures) == 0:
                self.interactiveMode = False

            mainOperator.SelectedFeatures.setValue(dlg.selectedFeatures)
            nfeatures = 0
            for plugin_features in dlg.selectedFeatures.values():
                nfeatures += len(plugin_features)
            self.labelingDrawerUi.featuresSubset.setText(
                "{} features selected,\nsome may have multiple channels".
                format(nfeatures))
        mainOperator.ComputedFeatureNames.setDirty(())
    def handleSubsetFeaturesClicked(self):
        mainOperator = self.topLevelOperatorView
        computedFeatures = copy.deepcopy(mainOperator.ComputedFeatureNames([]).wait())
        # do NOT show default features, the user did not want them for classification
        # the key for the fake plugin of default features is taken from the top of opObjectExtraction file
        if mainOperator.SelectedFeatures.ready():
            selectedFeatures = copy.deepcopy(mainOperator.SelectedFeatures([]).wait())
        else:
            selectedFeatures = computedFeatures

        plugins = pluginManager.getPluginsOfCategory('ObjectFeatures')
        taggedShape = mainOperator.RawImages.meta.getTaggedShape()
        fakeimgshp = [taggedShape['x'], taggedShape['y']]
        fakelabelsshp = [taggedShape['x'], taggedShape['y']]

        if 'z' in taggedShape and taggedShape['z']>1:
            fakeimgshp.append(taggedShape['z'])
            fakelabelsshp.append(taggedShape['z'])
            ndim = 3
        else:
            ndim = 2
        if 'c' in taggedShape and taggedShape['c']>1:
            fakeimgshp.append(taggedShape['c'])

        fakeimg = numpy.empty(fakeimgshp, dtype=numpy.float32)
        fakelabels = numpy.empty(fakelabelsshp, dtype=numpy.uint32)

        if ndim==3:
            fakelabels = vigra.taggedView(fakelabels, 'xyz')
            if len(fakeimgshp)==4:
                fakeimg = vigra.taggedView(fakeimg, 'xyzc')
            else:
                fakeimg = vigra.taggedView(fakeimg, 'xyz')
        if ndim==2:
            fakelabels = vigra.taggedView(fakelabels, 'xy')
            if len(fakeimgshp)==3:
                fakeimg = vigra.taggedView(fakeimg, 'xyc')
            else:
                fakeimg = vigra.taggedView(fakeimg, 'xy')

        for pluginInfo in plugins:
            availableFeatures = pluginInfo.plugin_object.availableFeatures(fakeimg, fakelabels)
            if len(availableFeatures) > 0:
                if pluginInfo.name in list(self.applet._selectedFeatures.keys()): 
                    assert pluginInfo.name in list(computedFeatures.keys()), 'Object Classification: {} not found in available (computed) object features'.format(pluginInfo.name)

                if not pluginInfo.name in selectedFeatures and pluginInfo.name in self.applet._selectedFeatures:
                        selectedFeatures[pluginInfo.name]=dict()

                        for feature in list(self.applet._selectedFeatures[pluginInfo.name].keys()):
                            if feature in list(availableFeatures.keys()):
                                selectedFeatures[pluginInfo.name][feature] = availableFeatures[feature]

        dlg = FeatureSubSelectionDialog(computedFeatures,
                                        selectedFeatures=selectedFeatures, ndim=ndim)
        dlg.exec_()
        if dlg.result() == QDialog.Accepted:
            if len(dlg.selectedFeatures) == 0:
                self.interactiveMode = False

            mainOperator.SelectedFeatures.setValue(dlg.selectedFeatures)
            nfeatures = 0
            for plugin_features in dlg.selectedFeatures.values():
                nfeatures += len(plugin_features)
            self.labelingDrawerUi.featuresSubset.setText("{} features selected,\nsome may have multiple channels".format(nfeatures))
        mainOperator.ComputedFeatureNames.setDirty(())
    def _selectFeaturesButtonPressed(self):
        featureDict = {}
        mainOperator = self.topLevelOperatorView
        if not mainOperator.RawImage.ready():
            mexBox=QMessageBox()
            mexBox.setText("Please add the raw data before selecting features")
            mexBox.exec_()
            return
        
        if not mainOperator.BinaryImage.ready():
            mexBox=QMessageBox()
            mexBox.setText("Please add binary (segmentation) data before selecting features ")
            mexBox.exec_()
            return
        
        slot = mainOperator.Features
        if slot.ready():
            selectedFeatures = mainOperator.Features([]).wait()
        else:
            selectedFeatures = None

        plugins = pluginManager.getPluginsOfCategory('ObjectFeatures')
        taggedShape = mainOperator.RawImage.meta.getTaggedShape()
        fakeimg = None
        fakeimgshp = [taggedShape['x'], taggedShape['y']]
        fakelabelsshp = [taggedShape['x'], taggedShape['y']]
        ndim = 3
        if 'z' in taggedShape and taggedShape['z']>1:
            fakeimgshp.append(taggedShape['z'])
            fakelabelsshp.append(taggedShape['z'])
            ndim = 3
        else:
            ndim = 2
        if 'c' in taggedShape and taggedShape['c']>1:
            fakeimgshp.append(taggedShape['c'])
        
        fakeimg = np.empty(fakeimgshp, dtype=np.float32)
        fakelabels = np.empty(fakelabelsshp, dtype=np.uint32)
        
        if ndim==3:
            fakelabels = vigra.taggedView(fakelabels, 'xyz')
            if len(fakeimgshp)==4:
                fakeimg = vigra.taggedView(fakeimg, 'xyzc')
            else:
                fakeimg = vigra.taggedView(fakeimg, 'xyz')
        if ndim==2:
            fakelabels = vigra.taggedView(fakelabels, 'xy')
            if len(fakeimgshp)==3:
                fakeimg = vigra.taggedView(fakeimg, 'xyc')
            else:
                fakeimg = vigra.taggedView(fakeimg, 'xy')
        for pluginInfo in plugins:
            availableFeatures = pluginInfo.plugin_object.availableFeatures(fakeimg, fakelabels)
            if len(availableFeatures) > 0:
                featureDict[pluginInfo.name] = availableFeatures
        dlg = FeatureSelectionDialog(featureDict=featureDict,
                                     selectedFeatures=selectedFeatures, ndim=ndim)
        dlg.exec_()

        if dlg.result() == QDialog.Accepted:
            mainOperator.Features.setValue(dlg.selectedFeatures)
            self._calculateFeatures()
    def handleSubsetFeaturesClicked(self):
        mainOperator = self.topLevelOperatorView
        computedFeatures = mainOperator.ComputedFeatureNames([]).wait()
        if mainOperator.SelectedFeatures.ready():
            selectedFeatures = mainOperator.SelectedFeatures([]).wait()
        else:
            selectedFeatures = computedFeatures

        plugins = pluginManager.getPluginsOfCategory('ObjectFeatures')
        taggedShape = mainOperator.RawImages.meta.getTaggedShape()
        fakeimgshp = [taggedShape['x'], taggedShape['y']]
        fakelabelsshp = [taggedShape['x'], taggedShape['y']]

        if 'z' in taggedShape and taggedShape['z']>1:
            fakeimgshp.append(taggedShape['z'])
            fakelabelsshp.append(taggedShape['z'])
            ndim = 3
        else:
            ndim = 2
        if 'c' in taggedShape and taggedShape['c']>1:
            fakeimgshp.append(taggedShape['c'])

        fakeimg = numpy.empty(fakeimgshp, dtype=numpy.float32)
        fakelabels = numpy.empty(fakelabelsshp, dtype=numpy.uint32)

        if ndim==3:
            fakelabels = vigra.taggedView(fakelabels, 'xyz')
            if len(fakeimgshp)==4:
                fakeimg = vigra.taggedView(fakeimg, 'xyzc')
            else:
                fakeimg = vigra.taggedView(fakeimg, 'xyz')
        if ndim==2:
            fakelabels = vigra.taggedView(fakelabels, 'xy')
            if len(fakeimgshp)==3:
                fakeimg = vigra.taggedView(fakeimg, 'xyc')
            else:
                fakeimg = vigra.taggedView(fakeimg, 'xy')

        for pluginInfo in plugins:
            availableFeatures = pluginInfo.plugin_object.availableFeatures(fakeimg, fakelabels)
            if len(availableFeatures) > 0:
                if pluginInfo.name in self.applet._selectedFeatures.keys() and not pluginInfo.name in computedFeatures.keys():
                    computedFeatures[pluginInfo.name] = availableFeatures

                if not pluginInfo.name in selectedFeatures and \
                    pluginInfo.name in self.applet._selectedFeatures and \
                    len(self.applet._selectedFeatures[pluginInfo.name].keys()) > 0:
                        selectedFeatures[pluginInfo.name]=dict()
                        if pluginInfo.name in self.applet._selectedFeatures.keys():
                            for feature in self.applet._selectedFeatures[pluginInfo.name].keys():
                                if feature in availableFeatures.keys():
                                    selectedFeatures[pluginInfo.name][feature] = availableFeatures[feature]

        dlg = FeatureSubSelectionDialog(computedFeatures,
                                        selectedFeatures=selectedFeatures, ndim=ndim)
        dlg.exec_()
        if dlg.result() == QDialog.Accepted:
            if len(dlg.selectedFeatures) == 0:
                self.interactiveMode = False

            mainOperator.SelectedFeatures.setValue(dlg.selectedFeatures)
            nfeatures = 0
            for plugin_features in dlg.selectedFeatures.itervalues():
                nfeatures += len(plugin_features)
            self.labelingDrawerUi.featuresSubset.setText("{} features selected,\nsome may have multiple channels".format(nfeatures))
        mainOperator.ComputedFeatureNames.setDirty(())
Exemple #12
0
    def _selectFeaturesButtonPressed(self):
        featureDict = {}
        mainOperator = self.topLevelOperatorView
        if not mainOperator.RawImage.ready():
            mexBox = QMessageBox()
            mexBox.setText("Please add the raw data before selecting features")
            mexBox.exec_()
            return

        if not mainOperator.BinaryImage.ready():
            mexBox = QMessageBox()
            mexBox.setText(
                "Please add binary (segmentation) data before selecting features "
            )
            mexBox.exec_()
            return

        slot = mainOperator.Features
        if slot.ready():
            selectedFeatures = mainOperator.Features([]).wait()
        else:
            selectedFeatures = None

        plugins = pluginManager.getPluginsOfCategory('ObjectFeatures')
        taggedShape = mainOperator.RawImage.meta.getTaggedShape()
        fakeimgshp = [taggedShape['x'], taggedShape['y']]
        fakelabelsshp = [taggedShape['x'], taggedShape['y']]
        ndim = 3
        if 'z' in taggedShape and taggedShape['z'] > 1:
            fakeimgshp.append(taggedShape['z'])
            fakelabelsshp.append(taggedShape['z'])
            ndim = 3
        else:
            ndim = 2
        if 'c' in taggedShape and taggedShape['c'] > 1:
            fakeimgshp.append(taggedShape['c'])

        fakeimg = numpy.empty(fakeimgshp, dtype=numpy.float32)
        fakelabels = numpy.empty(fakelabelsshp, dtype=numpy.uint32)

        if ndim == 3:
            fakelabels = vigra.taggedView(fakelabels, 'xyz')
            if len(fakeimgshp) == 4:
                fakeimg = vigra.taggedView(fakeimg, 'xyzc')
            else:
                fakeimg = vigra.taggedView(fakeimg, 'xyz')
        if ndim == 2:
            fakelabels = vigra.taggedView(fakelabels, 'xy')
            if len(fakeimgshp) == 3:
                fakeimg = vigra.taggedView(fakeimg, 'xyc')
            else:
                fakeimg = vigra.taggedView(fakeimg, 'xy')

        for pluginInfo in plugins:
            availableFeatures = pluginInfo.plugin_object.availableFeatures(
                fakeimg, fakelabels)
            if len(availableFeatures) > 0:
                featureDict[pluginInfo.name] = availableFeatures

        # Make sure no plugins use the same feature names.
        # (Currently, our feature export implementation doesn't support repeated column names.)
        all_feature_names = chain(*[
            list(plugin_dict.keys())
            for plugin_dict in list(featureDict.values())
        ])
        feature_set = set()
        for name in all_feature_names:
            assert name not in feature_set, \
                "Feature name '{}' is used by more than one feature plugin.\n"\
                "All plugins must produce uniquely named features.\n"\
                "The plugins and feature names we found are:\n{}"\
                .format(name, featureDict)
            feature_set.add(name)

        dlg = FeatureSelectionDialog(featureDict=featureDict,
                                     selectedFeatures=selectedFeatures,
                                     ndim=ndim)
        dlg.exec_()

        if dlg.result() == QDialog.Accepted:
            mainOperator.Features.setValue(dlg.selectedFeatures)
            self._calculateFeatures()
    def _selectFeaturesButtonPressed(self):
        featureDict = {}
        mainOperator = self.topLevelOperatorView
        if not mainOperator.RawImage.ready():
            mexBox=QMessageBox()
            mexBox.setText("Please add the raw data before selecting features")
            mexBox.exec_()
            return
        
        if not mainOperator.BinaryImage.ready():
            mexBox=QMessageBox()
            mexBox.setText("Please add binary (segmentation) data before selecting features ")
            mexBox.exec_()
            return
        
        slot = mainOperator.Features
        if slot.ready():
            selectedFeatures = mainOperator.Features([]).wait()
        else:
            selectedFeatures = None

        plugins = pluginManager.getPluginsOfCategory('ObjectFeatures')
        taggedShape = mainOperator.RawImage.meta.getTaggedShape()
        fakeimgshp = [taggedShape['x'], taggedShape['y']]
        fakelabelsshp = [taggedShape['x'], taggedShape['y']]
        ndim = 3
        if 'z' in taggedShape and taggedShape['z']>1:
            fakeimgshp.append(taggedShape['z'])
            fakelabelsshp.append(taggedShape['z'])
            ndim = 3
        else:
            ndim = 2
        if 'c' in taggedShape and taggedShape['c']>1:
            fakeimgshp.append(taggedShape['c'])
        
        fakeimg = numpy.empty(fakeimgshp, dtype=numpy.float32)
        fakelabels = numpy.empty(fakelabelsshp, dtype=numpy.uint32)
        
        if ndim==3:
            fakelabels = vigra.taggedView(fakelabels, 'xyz')
            if len(fakeimgshp)==4:
                fakeimg = vigra.taggedView(fakeimg, 'xyzc')
            else:
                fakeimg = vigra.taggedView(fakeimg, 'xyz')
        if ndim==2:
            fakelabels = vigra.taggedView(fakelabels, 'xy')
            if len(fakeimgshp)==3:
                fakeimg = vigra.taggedView(fakeimg, 'xyc')
            else:
                fakeimg = vigra.taggedView(fakeimg, 'xy')

        for pluginInfo in plugins:
            availableFeatures = pluginInfo.plugin_object.availableFeatures(fakeimg, fakelabels)
            if len(availableFeatures) > 0:
                featureDict[pluginInfo.name] = availableFeatures

        # Make sure no plugins use the same feature names.
        # (Currently, our feature export implementation doesn't support repeated column names.)
        all_feature_names = chain(*[list(plugin_dict.keys()) for plugin_dict in list(featureDict.values())])
        feature_set = set()
        for name in all_feature_names:
            assert name not in feature_set, \
                "Feature name '{}' is used by more than one feature plugin.\n"\
                "All plugins must produce uniquely named features.\n"\
                "The plugins and feature names we found are:\n{}"\
                .format(name, featureDict)
            feature_set.add(name)

        dlg = FeatureSelectionDialog(featureDict=featureDict,
                                     selectedFeatures=selectedFeatures, ndim=ndim)
        dlg.exec_()

        if dlg.result() == QDialog.Accepted:
            mainOperator.Features.setValue(dlg.selectedFeatures)
            self._calculateFeatures()