class SectionClassification(SectionCore): SECTION_NAME = SECTION_NAME_CLASSIFICATION OPTIONS = [('%s_classification' % x, [ ('%s_classification_envpath' % x, \ StringTrait('', 1000, label='Classifier folder', widget_info=StringTrait.STRING_PATH)), ('%s_classification_regionname' % x, SelectionTrait2(None, [], label='Region name')), ('%s_classification_annotationfileext' % x, StringTrait('xml', 50, label='Annotation ext.')) ]) \ for x in (CH_PRIMARY+CH_OTHER)] + \ [('collectsamples', [ ('collectsamples', BooleanTrait(False)), ('collectsamples_prefix', StringTrait('',100))]), ('merged_channel', [ ('merge_primary', BooleanTrait(True, label='primary')), ('merge_secondary', BooleanTrait(True, label='secondary')), ('merge_tertiary', BooleanTrait(True, label='tertiary')) ]) ] + \ [('%s_classification' %CH_VIRTUAL[0], [ ('%s_classification_envpath' %CH_VIRTUAL[0], \ StringTrait('', 1000, label='Classifier folder', widget_info=StringTrait.STRING_PATH)), ('%s_primary_region' %CH_VIRTUAL[0], SelectionTrait2(None, [], label='')), ('%s_secondary_region' %CH_VIRTUAL[0], SelectionTrait2(None, [], label='')), ('%s_tertiary_region' %CH_VIRTUAL[0], SelectionTrait2(None, [], label='')), ('%s_classification_annotationfileext' %CH_VIRTUAL[0], StringTrait('xml', 50, label='Annotation ext.')), ('%s_classification_regionname' %CH_VIRTUAL[0], SelectionTrait2(None, [], label="Region name")) ])]
class SectionGeneral(SectionCore): SECTION_NAME = SECTION_NAME_GENERAL OPTIONS = [('general', [ ('pathin', StringTrait('', label='Image Directory', widget_info=StringTrait.STRING_PATH)), ('has_multiple_plates', BooleanTrait(False, label='Multiple Plates')), ('pathout', StringTrait('', label='Output Directory', widget_info=StringTrait.STRING_PATH)), ('plate_layout', StringTrait('', label='Plate Layout', widget_info=StringTrait.STRING_PATH)), ('namingscheme', SelectionTrait(CecogEnvironment.naming_schema.sections()[0], CecogEnvironment.naming_schema.sections(), label='Image Naming Scheme')), ('framerange', BooleanTrait(False, label='Timelapse')), ('framerange_begin', IntTrait(1, 0, 10000, label='first')), ('framerange_end', IntTrait(1, 0, 1000, label='last')), ('frameincrement', IntTrait(1, 1, 100, label='increment')), ('skip_finished', BooleanTrait(False, label='Skip finished positions')), ('constrain_positions', BooleanTrait(False, label='Positions')), ('positions', StringTrait('', 1000, label="", mask='(\w+,)*\w+')), ('process_primary', BooleanTrait(True, label='primary')), ('process_secondary', BooleanTrait(False, label='secondary')), ('process_tertiary', BooleanTrait(False, label='tertiary')), ('process_merged', BooleanTrait(False, label='merged')), ('crop_image', BooleanTrait(False, label='Image cropping')), ('crop_image_x0', IntTrait(-1, -1, 4000, label='upper left x:')), ('crop_image_y0', IntTrait(-1, -1, 4000, label='upper left y')), ('crop_image_x1', IntTrait(-1, -1, 4000, label='lower right x')), ('crop_image_y1', IntTrait(-1, -1, 4000, label='lower right y')), ('crop_image', BooleanTrait(False, label='Image cropping')), ('rendering', DictTrait({}, label='Rendering')), ('version', StringTrait('', 6, label='Cecog %s, file version:' % version, widget_info=StringTrait.STRING_GRAYED)), ('rendering_class', DictTrait({}, label='Rendering class')), ('primary_featureextraction_exportfeaturenames', ListTrait(['n2_avg', 'n2_stddev', 'roisize'], label='Primary channel')), ('secondary_featureextraction_exportfeaturenames', ListTrait(['n2_avg', 'n2_stddev', 'roisize'], label='Secondary channel')), ('tertiary_featureextraction_exportfeaturenames', ListTrait(['n2_avg', 'n2_stddev', 'roisize'], label='Tertiary channel')), ])]
class SectionEventSelection(SectionCore): SECTION_NAME = SECTION_NAME_EVENT_SELECTION OPTIONS = [ ('event_selection', [('eventchannel', SelectionTrait2(None, [], label='Channel')), ('event_selection', BooleanTrait(True, label='Event Selection')), ('backwardrange', FloatTrait(0, -1, 4000, label='Duration [pre]')), ('forwardrange', FloatTrait(0, -1, 4000, label='Duration [post]')), ('duration_unit', SelectionTrait2(TimeConverter.FRAMES, TimeConverter.units, label='Duration unit')), ('backwardrange_min', BooleanTrait(False, label='Min.')), ('forwardrange_min', BooleanTrait(False, label='Min.')), ('maxindegree', IntTrait(1, 0, 4000, label='Max in-degree')), ('maxoutdegree', IntTrait(2, 0, 4000, label='Max out-degree')), ]), ('supervised_event_selection', [('supervised_event_selection', BooleanTrait(True, label='Supervised', widget_info=BooleanTrait.RADIOBUTTON)), ('labeltransitions', StringTrait('', 200, label='Class transition motif(s)')), ('backwardlabels', StringTrait('', 200, label='Class filter [pre]', mask='(\d+,)*\d+')), ('forwardlabels', StringTrait('', 200, label='Class filter [post]', mask='(\d+,)*\d+')), ('backwardcheck', FloatTrait(2, 0, 4000, label='Filter duration [pre]')), ('forwardcheck', FloatTrait(2, 0, 4000, label='Filter duration [post]')), ]), ('unsupervised_event_selection', [('unsupervised_event_selection', BooleanTrait(False, label='Unsupervised', widget_info=BooleanTrait.RADIOBUTTON)), ('min_event_duration', IntTrait(3, 1, 100, label='Min. event duration')), ('num_clusters', IntTrait(6, 2, 15, label='Number of clusters',)), ('min_cluster_size', IntTrait(2, 1, 10, label='Min. cluster size',)), ]) ]
class SectionFeatureExtraction(SectionCore): SECTION_NAME = SECTION_NAME_FEATURE_EXTRACTION OPTIONS = [ ('primary_features', [('primary_featurecategory_%s' % name, BooleanTrait(True, label=desc)) for name, desc in zip(FEATURE_CATEGORIES, FEATURE_CATEGORY_DESC)] + [ ('primary_dist_haralick', StringTrait('1,2,4,8', 200, label='Haralick: Distances for cooccurence')), ('primary_se_granugrey', StringTrait('1,2,3,5,7', 200, label='Granulometry Sizes (Structuring Element)')), ('primary_diameter_spotfeatures', IntTrait(5, 1, 30, label="Diameter")), ('primary_thresh_spotfeatures', IntTrait(8, 1, 255, label="Threshold")), ]), ('secondary_features', [('secondary_featurecategory_%s' % name, BooleanTrait(True, label=desc)) for name, desc in zip(FEATURE_CATEGORIES, FEATURE_CATEGORY_DESC)] + [ ('secondary_dist_haralick', StringTrait('1,2,4,8', 200, label='Haralick: Distances for cooccurence')), ('secondary_se_granugrey', StringTrait('1,2,3,5,7', 200, label='Granulometry Sizes (Structuring Element)')), ('secondary_diameter_spotfeatures', IntTrait(5, 1, 30, label="Diameter")), ('secondary_thresh_spotfeatures', IntTrait(8, 1, 255, label="Threshold")), ]), ('tertiary_features', [('tertiary_featurecategory_%s' % name, BooleanTrait(True, label=desc)) for name, desc in zip(FEATURE_CATEGORIES, FEATURE_CATEGORY_DESC)] + [ ('tertiary_dist_haralick', StringTrait('1,2,4,8', 200, label='Haralick: Distances for cooccurence')), ('tertiary_se_granugrey', StringTrait('1,2,3,5,7', 200, label='Granulometry Sizes (Structuring Element)')), ('tertiary_diameter_spotfeatures', IntTrait(5, 1, 30, label="Diameter")), ('tertiary_thresh_spotfeatures', IntTrait(8, 1, 255, label="Threshold")), ]), ]
class SectionFeatureExtraction(SectionCore): SECTION_NAME = SECTION_NAME_FEATURE_EXTRACTION OPTIONS = [ ('primary_features', [ ('primary_%s' % name, BooleanTrait(val, label=desc)) for name, (desc, val) in GUI_LABELS.iteritems() ] + [ ('primary_dist_haralick', StringTrait( '1,2,4,8', 200, label='Haralick: Distances for cooccurence')), ('primary_se_granulometry', StringTrait('1,2,3,5,7', 200, label='Granulometry Sizes (Structuring Element)')), ('primary_diameter_spotfeatures', IntTrait(5, 1, 30, label="Diameter")), ('primary_thresh_spotfeatures', IntTrait(8, 1, 255, label="Threshold")), ]), ('secondary_features', [ ('secondary_%s' % name, BooleanTrait(val, label=desc)) for name, (desc, val) in GUI_LABELS.iteritems() ] + [ ('secondary_dist_haralick', StringTrait( '1,2,4,8', 200, label='Haralick: Distances for cooccurence')), ('secondary_se_granulometry', StringTrait('1,2,3,5,7', 200, label='Granulometry Sizes (Structuring Element)')), ('secondary_diameter_spotfeatures', IntTrait(5, 1, 30, label="Diameter")), ('secondary_thresh_spotfeatures', IntTrait(8, 1, 255, label="Threshold")), ]), ('tertiary_features', [ ('tertiary_%s' % name, BooleanTrait(val, label=desc)) for name, (desc, val) in GUI_LABELS.iteritems() ] + [ ('tertiary_dist_haralick', StringTrait( '1,2,4,8', 200, label='Haralick: Distances for cooccurence')), ('tertiary_se_granulometry', StringTrait('1,2,3,5,7', 200, label='Granulometry Sizes (Structuring Element)')), ('tertiary_diameter_spotfeatures', IntTrait(5, 1, 30, label="Diameter")), ('tertiary_thresh_spotfeatures', IntTrait(8, 1, 255, label="Threshold")), ]), ]
class SectionErrorcorrection(SectionCore): SECTION_NAME = SECTION_NAME_ERRORCORRECTION OPTIONS = [ ('error_correction', [('primary', BooleanTrait(True, label='primary')), ('secondary', BooleanTrait(False, label='secondary')), ('tertiary', BooleanTrait(False, label='tertiary')), ('merged', BooleanTrait(False, label='merged')), ('constrain_graph', BooleanTrait(True, label='Constrain graph')), ('primary_graph', StringTrait('', 1000, label='Primary file', widget_info=StringTrait.STRING_FILE)), ('secondary_graph', StringTrait('', 1000, label='Secondary file', widget_info=StringTrait.STRING_FILE)), ('tertiary_graph', StringTrait('', 1000, label='Tertiary file', widget_info=StringTrait.STRING_FILE)), ('merged_graph', StringTrait('', 1000, label='Merged ch. file', widget_info=StringTrait.STRING_FILE)), ('groupby_position', BooleanTrait(True, label='Position', widget_info=BooleanTrait.RADIOBUTTON)), ('groupby_sirna', BooleanTrait(False, label='siRNA', widget_info=BooleanTrait.RADIOBUTTON)), ('hmm_smoothing', BooleanTrait(True, label='Smoothing Model', widget_info=BooleanTrait.RADIOBUTTON)), ('hmm_baumwelch', BooleanTrait(False, label='Baum-Welch', widget_info=BooleanTrait.RADIOBUTTON)), ('groupby_genesymbol', BooleanTrait(False, label='Gene Symbol', widget_info=BooleanTrait.RADIOBUTTON)), ('overwrite_time_lapse', BooleanTrait(False, label='Overwrite time-lapse')), ('timelapse', FloatTrait(1, 0, 2000, digits=2, label='Time-lapse [min]')), ('max_time', FloatTrait(-1, -1, 2000, digits=2, label='Max. time in plot [min]')), ('ignore_tracking_branches', BooleanTrait(False, label='Ignore tracking branches')), ('enable_sorting', BooleanTrait(False, label='Sort by phase duration')), ('sorting_sequence', StringTrait('', 1000, label='Label sequence', mask='(\w+,)*\w+')), ('primary_sort', StringTrait('', 100)), ('secondary_sort', StringTrait('', 100)), ('compose_galleries', BooleanTrait(False, label='Compose gallery images')), ('compose_galleries_sample', IntTrait(-1, -1, 10000, label='Max. number of random samples')), ('resampling_factor', FloatTrait(0.4, 0.01, 1.0, label="Resampling factor")), ('size_gallery_image', IntTrait(60, 1, 1000, label='Size of gallery images (px)')) ]) ]
class SectionGeneral(SectionCore): SECTION_NAME = SECTION_NAME_GENERAL OPTIONS = [('general', [ ('pathin', StringTrait('', 1000, label='Image folder', widget_info=StringTrait.STRING_PATH)), ('has_multiple_plates', BooleanTrait(False, label='Multiple plates')), ('pathout', StringTrait('', 1000, label='Analysis folder', widget_info=StringTrait.STRING_PATH)), ('image_import_namingschema', BooleanTrait(True, label='Import via naming schema', widget_info=BooleanTrait.RADIOBUTTON)), ('image_import_structurefile', BooleanTrait(False, label='Import via coordinate file', widget_info=BooleanTrait.RADIOBUTTON)), ('namingscheme', SelectionTrait(CecogEnvironment.naming_schema.sections()[0], CecogEnvironment.naming_schema.sections(), label='Naming scheme')), ('structure_filename', StringTrait('', 1000, label='Coordinate filename', widget_info=StringTrait.STRING_FILE)), ('structure_file_pathin', BooleanTrait(True, label='Image folder', widget_info=BooleanTrait.RADIOBUTTON)), ('structure_file_pathout', BooleanTrait(False, label='Analysis folder', widget_info=BooleanTrait.RADIOBUTTON)), ('structure_file_extra_path', BooleanTrait(False, label='Different location', widget_info=BooleanTrait.RADIOBUTTON)), ('structure_file_extra_path_name', StringTrait('', 1000, label='Path', widget_info=StringTrait.STRING_PATH)), ('constrain_positions', BooleanTrait(False, label='Constrain positions')), ('positions', StringTrait('', 1000, label='Positions', mask='(\w+,)*\w+')), ('crop_image', BooleanTrait(False, label='Crop image')), ('crop_image_x0', IntTrait(-1, -1, 4000, label='Upper left X')), ('crop_image_y0', IntTrait(-1, -1, 4000, label='Upper left Y')), ('crop_image_x1', IntTrait(-1, -1, 4000, label='Lower right X')), ('crop_image_y1', IntTrait(-1, -1, 4000, label='Lower right Y')), ('crop_image', BooleanTrait(False, label='Crop image')), ('redofailedonly', BooleanTrait(True, label='Skip processed positions')), ('framerange', BooleanTrait(False, label='Constrain timepoints')), ('framerange_begin', IntTrait(1, 0, 10000, label='Begin')), ('framerange_end', IntTrait(1, 0, 1000, label='End')), ('frameincrement', IntTrait(1, 1, 100, label='Timepoint increment')), ('rendering', DictTrait({}, label='Rendering')), ('version', StringTrait('', 6, label='Cecog %s, file version:' % VERSION, widget_info=StringTrait.STRING_GRAYED)), ('rendering_class', DictTrait({}, label='Rendering class')), ('primary_featureextraction_exportfeaturenames', ListTrait(['n2_avg', 'n2_stddev', 'roisize'], label='Primary channel')), ('secondary_featureextraction_exportfeaturenames', ListTrait(['n2_avg', 'n2_stddev', 'roisize'], label='Secondary channel')), ('tertiary_featureextraction_exportfeaturenames', ListTrait(['n2_avg', 'n2_stddev', 'roisize'], label='Tertiary channel')), ])]
class SectionObjectdetection(SectionCore): SECTION_NAME = SECTION_NAME_OBJECTDETECTION OPTIONS = [ ('primary_image', [('primary_channelid', SelectionTrait2(None, [], label='Primary channel ID')), ('primary_normalizemin', IntTrait(0, -2**16, 2**16, label='Min.')), ('primary_normalizemax', IntTrait(255, -2**16, 2**16, label='Max.')), ('primary_zslice_selection', BooleanTrait(True, label='Z-slice selection', widget_info=BooleanTrait.RADIOBUTTON)), ('primary_flat_field_correction', BooleanTrait(False, label='Z-slice flat field correction', widget_info=BooleanTrait.CHECKBOX)), ('primary_flat_field_correction_image_dir', StringTrait('', 1000, label='Correction image directory', widget_info=StringTrait.STRING_PATH)), ('primary_zslice_selection_slice', IntTrait(1, 0, 1000, label='Slice')), ('primary_zslice_projection', BooleanTrait(False, label='Z-slice projection', widget_info=BooleanTrait.RADIOBUTTON)), ('primary_zslice_projection_method', SelectionTrait(ZSLICE_PROJECTION_METHODS[0], ZSLICE_PROJECTION_METHODS, label='Method')), ('primary_zslice_projection_begin', IntTrait(1, 0, 1000, label='Begin')), ('primary_zslice_projection_end', IntTrait(1, 0, 1000, label='End')), ('primary_zslice_projection_step', IntTrait(1, 1, 1000, label='Step')), # these two options are nopes, just to have no # special casing in channel classes ('primary_channelregistration_x', IntTrait(0, -99999, 99999, label='Shift X')), ('primary_channelregistration_y', IntTrait(0, -99999, 99999, label='Shift Y')), ]), ] + \ unlist( [[('%s_image' % prefix, [('%s_channelid' % prefix, SelectionTrait2(None, [], label='%s channel ID' % name)), ('%s_normalizemin' % prefix, IntTrait(0, -2**16, 2**16, label='Min.')), ('%s_normalizemax' % prefix, IntTrait(255, -2**16, 2**16, label='Max.')), ('%s_zslice_selection' % prefix, BooleanTrait(True, label='Z-slice selection', widget_info=BooleanTrait.RADIOBUTTON)), ('%s_flat_field_correction' % prefix, BooleanTrait(False, label='Z-slice flat field correction', widget_info=BooleanTrait.CHECKBOX)), ('%s_flat_field_correction_image_dir' % prefix, StringTrait('', 1000, label='Correction image directory', widget_info=StringTrait.STRING_PATH)), ('%s_zslice_selection_slice' % prefix, IntTrait(1, 0, 1000, label='Slice')), ('%s_zslice_projection' % prefix, BooleanTrait(False, label='Z-slice projection', widget_info=BooleanTrait.RADIOBUTTON)), ('%s_zslice_projection_method' % prefix, SelectionTrait(ZSLICE_PROJECTION_METHODS[0], ZSLICE_PROJECTION_METHODS, label='Method')), ('%s_zslice_projection_begin' % prefix, IntTrait(1, 0, 1000, label='Begin')), ('%s_zslice_projection_end' % prefix, IntTrait(1, 0, 1000, label='End')), ('%s_zslice_projection_step' % prefix, IntTrait(1, 1, 1000, label='Step')), ]), ('%s_registration' % prefix, [('%s_channelregistration_x' % prefix, IntTrait(0, -99999, 99999, label='Shift X')), ('%s_channelregistration_y' % prefix, IntTrait(0, -99999, 99999, label='Shift Y')), ]), ] for name, prefix in [('Secondary', 'secondary'), ('Tertiary', 'tertiary'), # moste merged channel options are nopes # to avoid special casing ('Merged', 'merged') ]] )
class SegmentationPluginIlastik(SegmentationPluginPrimary): LABEL = 'Local adaptive threshold w/ split&merge using trained ilastik classifier' NAME = 'primary_ilastik' COLOR = '#FF0000' REQUIRES = None PARAMS = [('ilastik_classifier', StringTrait('', 1000, label='ilastik Classifier File', widget_info=StringTrait.STRING_FILE)), ('ilastik_class_selector', IntTrait(1, 0, 1000, label='Output class')), ('medianradius', IntTrait(2, 0, 1000, label='Median radius')), ('latwindowsize', IntTrait(20, 1, 1000, label='Window size')), ('latlimit', IntTrait(1, 0, 255, label='Min. contrast')), ('lat2', BooleanTrait(False, label='Local adaptive threshold 2')), ('latwindowsize2', IntTrait(20, 1, 1000, label='Window size')), ('latlimit2', IntTrait(1, 0, 255, label='Min. contrast')), ('shapewatershed', BooleanTrait(False, label='Split & merge by shape')), ('shapewatershed_gausssize', IntTrait(1, 0, 10000, label='Gauss radius')), ('shapewatershed_maximasize', IntTrait(1, 0, 10000, label='Min. seed distance')), ('shapewatershed_minmergesize', IntTrait(1, 0, 10000, label='Object size threshold')), ('intensitywatershed', BooleanTrait(False, label='Split & merge by intensity')), ('intensitywatershed_gausssize', IntTrait(1, 0, 10000, label='Gauss radius')), ('intensitywatershed_maximasize', IntTrait(1, 0, 10000, label='Min. seed distance')), ('intensitywatershed_minmergesize', IntTrait(1, 0, 10000, label='Object size threshold')), ('postprocessing', BooleanTrait(False, label='Object filter')), ('postprocessing_roisize_min', IntTrait(-1, -1, 10000, label='Min. object size')), ('postprocessing_roisize_max', IntTrait(-1, -1, 10000, label='Max. object size')), ('postprocessing_intensity_min', IntTrait(-1, -1, 10000, label='Min. average intensity')), ('postprocessing_intensity_max', IntTrait(-1, -1, 10000, label='Max. average intensity')), ('removeborderobjects', BooleanTrait(True, label='Remove border objects')), ('holefilling', BooleanTrait(True, label='Fill holes')), ] # the : at the beginning indicates a QRC link with alias 'plugins/segmentation/local_adaptive_threshold' DOC = ':local_adaptive_threshold' @stopwatch() def prefilter(self, img_in): img = SegmentationPluginPrimary.prefilter(self, img_in) np_img = img.toArray(True) return self._predict_image_with_ilastik(np_img) def threshold(self, img_in, *args): np_img = img_in.toArray(True) return ccore.numpy_to_image((np_img > 128).astype(numpy.uint8), True) def render_to_gui(self, panel): panel.add_group(None, [('ilastik_classifier', (0, 0, 1, 1)), ('ilastik_class_selector', (1, 0, 1, 1)), ], label='ilastik') SegmentationPluginPrimary.render_to_gui(self, panel) def _predict_image_with_ilastik(self, image_): import ilastik from ilastik.core.dataMgr import DataMgr, DataItemImage from ilastik.modules.classification.core.featureMgr import FeatureMgr from ilastik.modules.classification.core.classificationMgr import ClassificationMgr from ilastik.modules.classification.core.features.featureBase import FeatureBase from ilastik.modules.classification.core.classifiers.classifierRandomForest import ClassifierRandomForest from ilastik.modules.classification.core.classificationMgr import ClassifierPredictThread from ilastik.core.volume import DataAccessor import numpy, h5py dataMgr = DataMgr() # Transform input image to ilastik convention s # 3D = (time,x,y,z,channel) # 2D = (time,1,x,y,channel) # Note, this work for 2D images right now. Is there a need for 3D image_.shape = (1,1) + image_.shape # Check if image_ has channels, if not add singelton dimension if len(image_.shape) == 4: image_.shape = image_.shape + (1,) # Add data item di to dataMgr di = DataItemImage('') di.setDataVol(DataAccessor(image_)) dataMgr.append(di, alreadyLoaded=True) fileName = self.params["ilastik_classifier"] ilastik_class = self.params["ilastik_class_selector"] hf = h5py.File(fileName,'r') temp = hf['classifiers'].keys() # If hf is not closed this leads to an error in win64 and mac os x hf.close() del hf classifiers = [] for cid in temp: cidpath = 'classifiers/' + cid classifiers.append(ClassifierRandomForest.loadRFfromFile(fileName, str(cidpath))) dataMgr.module["Classification"]["classificationMgr"].classifiers = classifiers # Restore user selection of feature items from hdf5 featureItems = [] f = h5py.File(fileName,'r') for fgrp in f['features'].values(): featureItems.append(FeatureBase.deserialize(fgrp)) f.close() del f fm = FeatureMgr(dataMgr, featureItems) # Create FeatureMgr # Compute features fm.prepareCompute(dataMgr) fm.triggerCompute() fm.joinCompute(dataMgr) # Predict with loaded classifier classificationPredict = ClassifierPredictThread(dataMgr) classificationPredict.start() classificationPredict.wait() if ilastik_class >= classificationPredict._prediction[0].shape[-1]: raise RuntimeError('ilastik output class not valid...') # Produce output image and select the probability map probMap = (classificationPredict._prediction[0][0,0,:,:, ilastik_class] * 255).astype(numpy.uint8) img_out = ccore.numpy_to_image(probMap, True) return img_out
class SegmentationPluginPrimaryLoadFromFile(SegmentationPluginPrimary): LABEL = 'Load from file' NAME = 'primary_from_file' COLOR = '#FF00FF' REQUIRES = None PARAMS = [('segmentation_folder', StringTrait('', 1000, label='Segmentation folder', widget_info=StringTrait.STRING_FILE)), ('loader_regex', StringTrait('^%(plate)s$/^%(pos)s$/.*P%(pos)s_T%(time)05d_C%(channel)s_Z%(zslice)d_S1.tif', 1000, label='Regex for loading')), ] # the : at the beginning indicates a QRC link with alias 'plugins/segmentation/local_adaptive_threshold' DOC = ':local_adaptive_threshold' def render_to_gui(self, panel): panel.add_group(None, [('segmentation_folder', (0, 0, 1, 1))]) panel.add_group(None, [('loader_regex', (0, 0, 1, 1))]) @stopwatch() def _run(self, meta_image): image = meta_image.image coords = dict( plate = meta_image.image_container.current_plate, pos = meta_image.coordinate.position, time = meta_image.coordinate.time, zslice = meta_image.coordinate.zslice, channel = meta_image.coordinate.channel, ) main_folder = self.params['segmentation_folder'] #FIXME: This is useful enought to put into an reusable function, maybe in utils? locator = self.params["loader_regex"] % coords locator_split = locator.split('/') locator_match = '/' for loc in locator_split[:-1]: try: match_candidates = os.listdir(main_folder + locator_match) if len(match_candidates) == 0: raise RuntimeError except: raise RuntimeError('No files found in ' + main_folder + locator_match) match_results = [m.group() for l in match_candidates for m in [re.search(loc, l)] if m] if len(match_results) != 1: raise RuntimeError('Could not match ' + match_candidates[0] + ' with ' + loc) locator_match += match_results[0] + '/' match_candidates = os.listdir(main_folder + locator_match) match_results = [m.group() for l in match_candidates for m in [re.search(locator_split[-1], l)] if m] if len(match_results) == 0: raise RuntimeError('Could not match ', match_candidates[0], 'with', locator_split[-1]) match_result = match_results[0] img = ccore.readImage(main_folder + locator_match + match_result) # img_pre = SegmentationPluginPrimary.prefilter(self, img, 2) # img_bin = SegmentationPluginPrimary.threshold(self, img_pre, 20, 3) container = ccore.ImageMaskContainer(image, img, False) return container
class SectionErrorcorrection(SectionCore): SECTION_NAME = SECTION_NAME_ERRORCORRECTION OPTIONS = [('error_correction', [ ('filename_to_r', StringTrait('', 1000, label='R-project executable', widget_info=StringTrait.STRING_FILE)), ('constrain_graph', BooleanTrait(True, label='Constrain graph')), ('primary_graph', StringTrait('', 1000, label='Primary file', widget_info=StringTrait.STRING_FILE)), ('secondary_graph', StringTrait('', 1000, label='Secondary file', widget_info=StringTrait.STRING_FILE)), ('skip_processed_plates', BooleanTrait(False, label='Skip processed plates')), ('position_labels', BooleanTrait(False, label='Position labels')), ('mappingfile_path', StringTrait('', 1000, label='Path', widget_info=StringTrait.STRING_PATH)), ('groupby_position', BooleanTrait(True, label='Position', widget_info=BooleanTrait.RADIOBUTTON)), ('groupby_oligoid', BooleanTrait(False, label='Oligo ID', widget_info=BooleanTrait.RADIOBUTTON)), ('groupby_genesymbol', BooleanTrait(False, label='Gene symbol', widget_info=BooleanTrait.RADIOBUTTON)), ('overwrite_time_lapse', BooleanTrait(False, label='Overwrite time-lapse')), ('timelapse', FloatTrait(1, 0, 2000, digits=2, label='Time-lapse [min]')), ('max_time', FloatTrait(100, 1, 2000, digits=2, label='Max. time in plot [min]')), ('ignore_tracking_branches', BooleanTrait(False, label='Ignore tracking branches')), ('show_html', BooleanTrait(True, label='Open in browser')), ('enable_sorting', BooleanTrait(False, label='Sort by phase duration')), ('sorting_sequence', StringTrait('', 1000, label='Label sequence', mask='(\w+,)*\w+')), ('primary_sort', StringTrait('', 100)), ('secondary_sort', StringTrait('', 100)), ('compose_galleries', BooleanTrait(False, label='Compose gallery images')), ('compose_galleries_sample', IntTrait(-1, -1, 10000, label='Max. number of random samples')), ])]
class SectionTracking(SectionCore): SECTION_NAME = SECTION_NAME_TRACKING OPTIONS = [ ('tracking', [ ('tracking_regionname', SelectionTrait2(None, [], label='Region name')), ('tracking_maxobjectdistance', IntTrait(0, 0, 4000, label='Max object x-y distance')), ('tracking_maxtrackinggap', IntTrait(0, 0, 4000, label='Max time-point gap')), ('tracking_maxsplitobjects', IntTrait(0, 0, 4000, label='Max split events')), ('tracking_maxindegree', IntTrait(1, 0, 4000, label='Max in-degree')), ('tracking_maxoutdegree', IntTrait(2, 0, 4000, label='Max out-degree')), ('tracking_exporttrackfeatures', BooleanTrait(True, label='Export tracks')), ('tracking_compressiontrackfeatures', SelectionTrait(COMPRESSION_FORMATS[0], COMPRESSION_FORMATS, label='Compression')), ]), ('event_selection', [ ('tracking_labeltransitions', StringTrait('', 200, label='Class transition motif(s)', mask='(\(\d+,\d+\),)*\(\d+,\d+\)')), ('tracking_backwardrange', FloatTrait(0, -1, 4000, label='Duration [pre]')), ('tracking_forwardrange', FloatTrait(0, -1, 4000, label='Duration [post]')), ('tracking_backwardlabels', StringTrait('', 200, label='Class filter [pre]', mask='(\d+,)*\d+')), ('tracking_forwardlabels', StringTrait('', 200, label='Class filter [post]', mask='(\d+,)*\d+')), ('tracking_backwardcheck', FloatTrait(2, 0, 4000, label='Filter duration [pre]')), ('tracking_forwardcheck', FloatTrait(2, 0, 4000, label='Filter duration [post]')), ('tracking_duration_unit', SelectionTrait2(TRACKING_DURATION_UNITS_DEFAULT[0], TRACKING_DURATION_UNITS_DEFAULT, label='Duration unit')), ('tracking_backwardrange_min', BooleanTrait(False, label='Min.')), ('tracking_forwardrange_min', BooleanTrait(False, label='Min.')), ]), ('visualization', [ ('tracking_visualization', BooleanTrait(False, label='Visualization')), ('tracking_visualize_track_length', IntTrait(5, -1, 10000, label='Max. time-points')), ('tracking_centroid_radius', IntTrait(3, -1, 50, label='Centroid radius')), ]), ]
class SectionPostProcessing(SectionCore): SECTION_NAME = SECTION_NAME_POST_PROCESSING OPTIONS = [('post_processing', [ ('ibb_analysis', BooleanTrait(True, label='IBB analysis')), ('mappingfile_path', StringTrait('', 1000, label='Mapping file path', widget_info=StringTrait.STRING_PATH)), ('single_plot', BooleanTrait( True, label='Export single event', )), ('single_plot_max_plots', IntTrait( 1, 1, 2000, label='Max. number', )), ('ibb_ratio_signal_threshold', FloatTrait( 1.2, 0.5, 5, label='IBB minimum ratio signal threshold', )), ('ibb_range_signal_threshold', FloatTrait( 3, 0.5, 5, label='IBB minimum range threshold', )), ('ibb_onset_factor_threshold', FloatTrait( 1.2, 1, 5, label='IBB onset slope threshold', )), ('nebd_onset_factor_threshold', FloatTrait( 1.2, 1, 5, label='NEBD onset slope threshold', )), ('plot_ylim1_low', IntTrait( 0, 0, 2000, label='Y-axis limit (low)', )), ('plot_ylim1_high', IntTrait( 100, 1, 4000, label='Y-axis limit (high)', )), ('single_plot_ylim_low', FloatTrait( 1, 0, 10, label='Y-axis ratio range (low)', )), ('single_plot_ylim_high', IntTrait( 5, 1, 30, label='Y-axis ratio range (high)', )), ('group_by_position', BooleanTrait(True, label='Position', widget_info=BooleanTrait.RADIOBUTTON)), ('group_by_oligoid', BooleanTrait(False, label='Oligo ID', widget_info=BooleanTrait.RADIOBUTTON)), ('group_by_genesymbol', BooleanTrait(False, label='Gene symbol', widget_info=BooleanTrait.RADIOBUTTON)), ('group_by_group', BooleanTrait(False, label='Group', widget_info=BooleanTrait.RADIOBUTTON)), ('color_sort_by_position', BooleanTrait(False, label='Position', widget_info=BooleanTrait.RADIOBUTTON)), ('color_sort_by_oligoid', BooleanTrait(True, label='Oligo ID', widget_info=BooleanTrait.RADIOBUTTON)), ('color_sort_by_genesymbol', BooleanTrait(False, label='Gene symbol', widget_info=BooleanTrait.RADIOBUTTON)), ('color_sort_by_group', BooleanTrait(False, label='Group', widget_info=BooleanTrait.RADIOBUTTON)), ('securin_analysis', BooleanTrait(True, label='Securin analysis')), ])]