def named_save_action(self): if self.profile_name.text() in self.settings.measurement_profiles: ret = QMessageBox.warning( self, "Profile exist", "Profile exist\nWould you like to overwrite it?", QMessageBox.No | QMessageBox.Yes, ) if ret == QMessageBox.No: return selected_values = [] for i in range(self.profile_options_chosen.count()): txt = str(self.profile_options_chosen.item(i).text()) selected_values.append((txt, str, txt)) val_dialog = MultipleInput("Set fields name", list(selected_values), parent=self) if val_dialog.exec_(): selected_values = [] for i in range(self.profile_options_chosen.count()): element: MeasurementListWidgetItem = self.profile_options_chosen.item( i) selected_values.append( MeasurementEntry(val_dialog.result[element.text()], element.stat)) stat_prof = MeasurementProfile(self.profile_name.text(), selected_values) self.settings.measurement_profiles[stat_prof.name] = stat_prof self.export_profiles_butt.setEnabled(True)
def measurement_profiles(): statistics = [ MeasurementEntry( "Segmentation Volume", Volume.get_starting_leaf().replace_(area=AreaType.ROI, per_component=PerComponent.No), ), MeasurementEntry( "ROI Components Number", ComponentsNumber.get_starting_leaf().replace_(area=AreaType.ROI, per_component=PerComponent.No), ), ] statistics2 = [ MeasurementEntry( "Mask Volume", Volume.get_starting_leaf().replace_(area=AreaType.Mask, per_component=PerComponent.No) ), ] return MeasurementProfile("statistic1", statistics), MeasurementProfile("statistic2", statistics + statistics2)
def create_simple_plan(root_type: RootType, save: Save): parameters = { "channel": 0, "minimum_size": 200, "threshold": { "name": "Manual", "values": { "threshold": 13000 } }, "noise_filtering": { "name": "Gauss", "values": { "dimension_type": DimensionType.Layer, "radius": 1.0 } }, "side_connection": False, } segmentation = ROIExtractionProfile(name="test", algorithm="Lower threshold", values=parameters) chosen_fields = [ MeasurementEntry( name="Segmentation Volume", calculation_tree=Leaf(name="Volume", area=AreaType.ROI, per_component=PerComponent.No), ), ] statistic = MeasurementProfile(name="base_measure", chosen_fields=chosen_fields, name_prefix="") statistic_calculate = MeasurementCalculate( channel=-1, units=Units.µm, measurement_profile=statistic, name_prefix="") tree = CalculationTree( root_type, [ CalculationTree(segmentation, [ CalculationTree(statistic_calculate, []), CalculationTree(save, []) ]) ], ) return CalculationPlan(tree=tree, name="test")
def calculate(self): if self.settings.roi is None: QMessageBox.warning(self, "No segmentation", "need segmentation to work") return to_calculate = [] for i in range(self._shift, self.measurement_layout.count()): # noinspection PyTypeChecker chk: QCheckBox = self.measurement_layout.itemAt(i).widget() if chk.isChecked(): leaf: Leaf = MEASUREMENT_DICT[chk.text()].get_starting_leaf() to_calculate.append( leaf.replace_(per_component=PerComponent.Yes, area=AreaType.ROI)) if not to_calculate: QMessageBox.warning(self, "No measurement", "Select at least one measurement") return profile = MeasurementProfile( "", [MeasurementEntry(x.name, x) for x in to_calculate]) dial = ExecuteFunctionDialog( profile.calculate, kwargs={ "image": self.settings.image, "channel_num": self.channel_select.get_value(), "roi": self.settings.roi_info, "result_units": self.units_select.currentEnum(), }, ) dial.exec_() result: MeasurementResult = dial.get_result() values = result.get_separated() labels = result.get_labels() self.result_view.clear() self.result_view.setColumnCount(len(values) + 1) self.result_view.setRowCount(len(labels)) for i, val in enumerate(labels): self.result_view.setItem(i, 0, QTableWidgetItem(val)) for j, values_list in enumerate(values): for i, val in enumerate(values_list): self.result_view.setItem(i, j + 1, QTableWidgetItem(str(val)))
def save_action(self): if self.profile_name.text() in self.settings.measurement_profiles: ret = QMessageBox.warning( self, "Profile exist", "Profile exist\nWould you like to overwrite it?", QMessageBox.No | QMessageBox.Yes, ) if ret == QMessageBox.No: return selected_values = [] for i in range(self.profile_options_chosen.count()): element: MeasurementListWidgetItem = self.profile_options_chosen.item( i) selected_values.append( MeasurementEntry(element.text(), element.stat)) stat_prof = MeasurementProfile(self.profile_name.text(), selected_values) self.settings.measurement_profiles[stat_prof.name] = stat_prof self.settings.dump() self.export_profiles_butt.setEnabled(True)
def create_calculation_plan(): parameters = { "channel": 1, "minimum_size": 200, "threshold": { "name": "Base/Core", "values": { "core_threshold": { "name": "Manual", "values": { "threshold": 30000 } }, "base_threshold": { "name": "Manual", "values": { "threshold": 13000 } }, }, }, "noise_filtering": { "name": "Gauss", "values": { "dimension_type": DimensionType.Layer, "radius": 1.0 } }, "side_connection": False, "sprawl_type": { "name": "Euclidean", "values": {} }, } segmentation = ROIExtractionProfile( name="test", algorithm="Lower threshold with watershed", values=parameters) mask_suffix = MaskSuffix(name="", suffix="_mask") chosen_fields = [ MeasurementEntry( name="Segmentation Volume", calculation_tree=Leaf(name="Volume", area=AreaType.ROI, per_component=PerComponent.No), ), MeasurementEntry( name="Segmentation Volume/Mask Volume", calculation_tree=Node( left=Leaf(name="Volume", area=AreaType.ROI, per_component=PerComponent.No), op="/", right=Leaf(name="Volume", area=AreaType.Mask, per_component=PerComponent.No), ), ), MeasurementEntry( "Segmentation Components Number", calculation_tree=Leaf("Components number", area=AreaType.ROI, per_component=PerComponent.No), ), ] statistic = MeasurementProfile(name="base_measure", chosen_fields=chosen_fields, name_prefix="") statistic_calculate = MeasurementCalculate( channel=0, units=Units.µm, measurement_profile=statistic, name_prefix="") tree = CalculationTree( RootType.Image, [ CalculationTree(mask_suffix, [ CalculationTree(segmentation, [CalculationTree(statistic_calculate, [])]) ]) ], ) return CalculationPlan(tree=tree, name="test")