def do_export(self, settings, selected_features, progress_slot): """ Implements ExportOperator.do_export(settings, selected_features, progress_slot Most likely called from ExportOperator.export_object_data :param settings: the settings for the exporter, see :param selected_features: :param progress_slot: :return: """ from ilastik.utility.exportFile import objects_per_frame, ExportFile, ilastik_ids, Mode, Default, \ flatten_dict, division_flatten_dict selected_features = list(selected_features) with_divisions = self.Parameters.value["withDivisions"] if self.Parameters.ready() else False obj_count = list(objects_per_frame(self.LabelImage)) track_ids, extra_track_ids, divisions = self.export_track_ids() self._setLabel2Color() lineage = flatten_dict(self.label2color, obj_count) multi_move_max = self.Parameters.value["maxObj"] if self.Parameters.ready() else 2 t_range = self.Parameters.value["time_range"] if self.Parameters.ready() else (0, 0) ids = ilastik_ids(obj_count) export_file = ExportFile(settings["file path"]) export_file.ExportProgress.subscribe(progress_slot) export_file.InsertionProgress.subscribe(progress_slot) export_file.add_columns("table", range(sum(obj_count)), Mode.List, Default.KnimeId) export_file.add_columns("table", list(ids), Mode.List, Default.IlastikId) export_file.add_columns("table", lineage, Mode.List, Default.Lineage) export_file.add_columns("table", track_ids, Mode.IlastikTrackingTable, {"max": multi_move_max, "counts": obj_count, "extra ids": extra_track_ids, "range": t_range}) if with_divisions: object_feature_slot = self.ObjectFeaturesWithDivFeatures else: object_feature_slot = self.ObjectFeatures export_file.add_columns("table", object_feature_slot, Mode.IlastikFeatureTable, {"selection": selected_features}) if with_divisions: if divisions: div_lineage = division_flatten_dict(divisions, self.label2color) zips = zip(*divisions) divisions = zip(zips[0], div_lineage, *zips[1:]) export_file.add_columns("divisions", divisions, Mode.List, Default.DivisionNames) else: logger.debug("No divisions occurred. Division Table will not be exported!") if settings["file type"] == "h5": export_file.add_rois(Default.LabelRoiPath, self.LabelImage, "table", settings["margin"], "labeling") if settings["include raw"]: export_file.add_image(Default.RawPath, self.RawImage) else: export_file.add_rois(Default.RawRoiPath, self.RawImage, "table", settings["margin"]) export_file.write_all(settings["file type"], settings["compression"]) export_file.ExportProgress.unsubscribe(progress_slot) export_file.InsertionProgress.unsubscribe(progress_slot)
def do_export(self, settings, selected_features, progress_slot): """ Implements ExportOperator.do_export(settings, selected_features, progress_slot Most likely called from ExportOperator.export_object_data :param settings: the settings for the exporter, see :param selected_features: :param progress_slot: :return: """ from ilastik.utility.exportFile import objects_per_frame, ExportFile, ilastik_ids, Mode, Default, \ flatten_dict, division_flatten_dict obj_count = list(objects_per_frame(self.LabelImage)) track_ids, extra_track_ids, divisions = self.export_track_ids() self._setLabel2Color() lineage = flatten_dict(self.label2color, obj_count) multi_move_max = self.Parameters.value["maxObj"] if self.Parameters.ready() else 2 multi_move_max = max(2, multi_move_max) t_range = self.Parameters.value["time_range"] if self.Parameters.ready() else (0, 0) ids = ilastik_ids(obj_count) export_file = ExportFile(settings["file path"]) export_file.ExportProgress.subscribe(progress_slot) export_file.InsertionProgress.subscribe(progress_slot) export_file.add_columns("table", range(sum(obj_count)), Mode.List, Default.KnimeId) export_file.add_columns("table", list(ids), Mode.List, Default.IlastikId) export_file.add_columns("table", lineage, Mode.List, Default.Lineage) export_file.add_columns("table", track_ids, Mode.IlastikTrackingTable, {"max": multi_move_max, "counts": obj_count, "extra ids": extra_track_ids, "range": t_range}) export_file.add_columns("table", self.ObjectFeatures, Mode.IlastikFeatureTable, {"selection": selected_features}) if self.Parameters.value["withDivisions"] if self.Parameters.ready() else False: try: div_lineage = division_flatten_dict(divisions, self.label2color) zips = zip(*divisions) divisions = zip(zips[0], div_lineage, *zips[1:]) export_file.add_columns("divisions", divisions, Mode.List, Default.DivisionNames) except Exception as e: if hasattr(progress_slot, "safe_popup"): progress_slot.safe_popup_noclose("warning", "Warning", "Cannot export divisions.\nContinuing ...", e) else: print "\nWarning, Cannot export divisions" if settings["file type"] == "h5": export_file.add_rois(Default.LabelRoiPath, self.LabelImage, "table", settings["margin"], "labeling") if settings["include raw"]: export_file.add_image(Default.RawPath, self.RawImage) else: export_file.add_rois(Default.RawRoiPath, self.RawImage, "table", settings["margin"]) export_file.write_all(settings["file type"], settings["compression"]) export_file.ExportProgress.unsubscribe(progress_slot) export_file.InsertionProgress.unsubscribe(progress_slot)
def _do_export_impl(self, settings, selected_features, progress_slot, object_feature_slot, label_image_slot, lane_index, filename_suffix=""): from ilastik.utility.exportFile import objects_per_frame, ExportFile, ilastik_ids, Mode, Default, \ flatten_dict, division_flatten_dict selected_features = list(selected_features) with_divisions = self.Parameters.value["withDivisions"] if self.Parameters.ready() else False obj_count = list(objects_per_frame(label_image_slot)) track_ids, extra_track_ids, divisions = self.export_track_ids() self._setLabel2Color() lineage = flatten_dict(self.label2color, obj_count) multi_move_max = self.Parameters.value["maxObj"] if self.Parameters.ready() else 2 t_range = self.Parameters.value["time_range"] if self.Parameters.ready() else (0, 0) ids = ilastik_ids(obj_count) file_path = settings["file path"] if filename_suffix: path, ext = os.path.splitext(file_path) file_path = path + "-" + filename_suffix + ext export_file = ExportFile(file_path) export_file.ExportProgress.subscribe(progress_slot) export_file.InsertionProgress.subscribe(progress_slot) export_file.add_columns("table", range(sum(obj_count)), Mode.List, Default.KnimeId) export_file.add_columns("table", list(ids), Mode.List, Default.IlastikId) export_file.add_columns("table", lineage, Mode.List, Default.Lineage) export_file.add_columns("table", track_ids, Mode.IlastikTrackingTable, {"max": multi_move_max, "counts": obj_count, "extra ids": extra_track_ids, "range": t_range}) export_file.add_columns("table", object_feature_slot, Mode.IlastikFeatureTable, {"selection": selected_features}) if with_divisions: if divisions: div_lineage = division_flatten_dict(divisions, self.label2color) zips = zip(*divisions) divisions = zip(zips[0], div_lineage, *zips[1:]) export_file.add_columns("divisions", divisions, Mode.List, Default.DivisionNames) else: logger.debug("No divisions occurred. Division Table will not be exported!") if settings["file type"] == "h5": export_file.add_rois(Default.LabelRoiPath, label_image_slot, "table", settings["margin"], "labeling") if settings["include raw"]: export_file.add_image(Default.RawPath, self.RawImage) else: export_file.add_rois(Default.RawRoiPath, self.RawImage, "table", settings["margin"]) export_file.write_all(settings["file type"], settings["compression"]) export_file.ExportProgress.unsubscribe(progress_slot) export_file.InsertionProgress.unsubscribe(progress_slot)
def do_export(self, settings, selected_features, progress_slot): """ Implements ExportOperator.do_export(settings, selected_features, progress_slot Most likely called from ExportOperator.export_object_data :param settings: the settings for the exporter, see :param selected_features: :param progress_slot: :return: """ from ilastik.utility.exportFile import objects_per_frame, ExportFile, ilastik_ids, Mode, Default, \ flatten_dict, division_flatten_dict selected_features = list(selected_features) with_divisions = self.Parameters.value[ "withDivisions"] if self.Parameters.ready() else False obj_count = list(objects_per_frame(self.LabelImage)) track_ids, extra_track_ids, divisions = self.export_track_ids() self._setLabel2Color() lineage = flatten_dict(self.label2color, obj_count) multi_move_max = self.Parameters.value[ "maxObj"] if self.Parameters.ready() else 2 t_range = self.Parameters.value["time_range"] if self.Parameters.ready( ) else (0, 0) ids = ilastik_ids(obj_count) export_file = ExportFile(settings["file path"]) export_file.ExportProgress.subscribe(progress_slot) export_file.InsertionProgress.subscribe(progress_slot) export_file.add_columns("table", range(sum(obj_count)), Mode.List, Default.KnimeId) export_file.add_columns("table", list(ids), Mode.List, Default.IlastikId) export_file.add_columns("table", lineage, Mode.List, Default.Lineage) export_file.add_columns( "table", track_ids, Mode.IlastikTrackingTable, { "max": multi_move_max, "counts": obj_count, "extra ids": extra_track_ids, "range": t_range }) if with_divisions: object_feature_slot = self.ObjectFeaturesWithDivFeatures else: object_feature_slot = self.ObjectFeatures export_file.add_columns("table", object_feature_slot, Mode.IlastikFeatureTable, {"selection": selected_features}) if with_divisions: if divisions: div_lineage = division_flatten_dict(divisions, self.label2color) zips = zip(*divisions) divisions = zip(zips[0], div_lineage, *zips[1:]) export_file.add_columns("divisions", divisions, Mode.List, Default.DivisionNames) else: logger.debug( "No divisions occurred. Division Table will not be exported!" ) if settings["file type"] == "h5": export_file.add_rois(Default.LabelRoiPath, self.LabelImage, "table", settings["margin"], "labeling") if settings["include raw"]: export_file.add_image(Default.RawPath, self.RawImage) else: export_file.add_rois(Default.RawRoiPath, self.RawImage, "table", settings["margin"]) export_file.write_all(settings["file type"], settings["compression"]) export_file.ExportProgress.unsubscribe(progress_slot) export_file.InsertionProgress.unsubscribe(progress_slot)
def do_export(self, settings, selected_features, progress_slot, lane_index, filename_suffix=""): """ Implements ExportOperator.do_export(settings, selected_features, progress_slot Most likely called from ExportOperator.export_object_data :param settings: the settings for the exporter, see :param selected_features: :param progress_slot: :param lane_index: Ignored. (This is a single-lane operator. It is the caller's responsibility to make sure he's calling the right lane.) :param filename_suffix: If provided, appended to the filename (before the extension). :return: """ assert lane_index == 0, "This has only been tested in tracking workflows with a single image." from ilastik.utility.exportFile import objects_per_frame, ExportFile, ilastik_ids, Mode, Default, \ flatten_dict, division_flatten_dict selected_features = list(selected_features) with_divisions = self.Parameters.value["withDivisions"] if self.Parameters.ready() else False obj_count = list(objects_per_frame(self.LabelImage)) track_ids, extra_track_ids, divisions = self.export_track_ids() self._setLabel2Color() lineage = flatten_dict(self.label2color, obj_count) multi_move_max = self.Parameters.value["maxObj"] if self.Parameters.ready() else 2 t_range = self.Parameters.value["time_range"] if self.Parameters.ready() else (0, 0) ids = ilastik_ids(obj_count) file_path = settings["file path"] if filename_suffix: path, ext = os.path.splitext(file_path) file_path = path + "-" + filename_suffix + ext export_file = ExportFile(file_path) export_file.ExportProgress.subscribe(progress_slot) export_file.InsertionProgress.subscribe(progress_slot) export_file.add_columns("table", range(sum(obj_count)), Mode.List, Default.KnimeId) export_file.add_columns("table", list(ids), Mode.List, Default.IlastikId) export_file.add_columns("table", lineage, Mode.List, Default.Lineage) export_file.add_columns("table", track_ids, Mode.IlastikTrackingTable, {"max": multi_move_max, "counts": obj_count, "extra ids": extra_track_ids, "range": t_range}) if with_divisions: object_feature_slot = self.ObjectFeaturesWithDivFeatures else: object_feature_slot = self.ObjectFeatures export_file.add_columns("table", object_feature_slot, Mode.IlastikFeatureTable, {"selection": selected_features}) if with_divisions: if divisions: div_lineage = division_flatten_dict(divisions, self.label2color) zips = zip(*divisions) divisions = zip(zips[0], div_lineage, *zips[1:]) export_file.add_columns("divisions", divisions, Mode.List, Default.DivisionNames) else: logger.debug("No divisions occurred. Division Table will not be exported!") if settings["file type"] == "h5": export_file.add_rois(Default.LabelRoiPath, self.LabelImage, "table", settings["margin"], "labeling") if settings["include raw"]: export_file.add_image(Default.RawPath, self.RawImage) else: export_file.add_rois(Default.RawRoiPath, self.RawImage, "table", settings["margin"]) export_file.write_all(settings["file type"], settings["compression"]) export_file.ExportProgress.unsubscribe(progress_slot) export_file.InsertionProgress.unsubscribe(progress_slot)