def Weka_Segm(dirs): """ Loads trained classifier and segments cells """ """ in aligned images according to training. """ # Define reference image for segmentation (default is timepoint000). w_train = os.path.join(dirs["Composites_Aligned"], "Timepoint000.tif") trainer = IJ.openImage(w_train) weka = WekaSegmentation() weka.setTrainingImage(trainer) # Select classifier model. weka.loadClassifier(str(classifier)) weka.applyClassifier(False) segmentation = weka.getClassifiedImage() segmentation.show() # Convert image to 8bit ImageConverter(segmentation).convertToRGB() ImageConverter(segmentation).convertToGray8() # Threshold segmentation to soma only. hist = segmentation.getProcessor().getHistogram() lowth = Auto_Threshold.IJDefault(hist) segmentation.getProcessor().threshold(lowth) segmentation.getProcessor().setThreshold(0, 0, ImageProcessor.NO_LUT_UPDATE) segmentation.getProcessor().invert() segmentation.show() # Run Watershed Irregular Features plugin, with parameters. IJ.run(segmentation, "Watershed Irregular Features", "erosion=20 convexity_treshold=0 separator_size=0-Infinity") # Make selection and add to RoiManager. RoiManager() rm = RoiManager.getInstance() rm.runCommand("reset") roi = ThresholdToSelection.run(segmentation) segmentation.setRoi(roi) rm.addRoi(roi) rm.runCommand("Split")
def apply_autothreshold(hist, method='Otsu'): if method == 'Otsu': lowthresh = Auto_Threshold.Otsu(hist) if method == 'Triangle': lowthresh = Auto_Threshold.Triangle(hist) if method == 'IJDefault': lowthresh = Auto_Threshold.IJDefault(hist) if method == 'Huang': lowthresh = Auto_Threshold.Huang(hist) if method == 'MaxEntropy': lowthresh = Auto_Threshold.MaxEntropy(hist) if method == 'Mean': lowthresh = Auto_Threshold.Mean(hist) if method == 'Shanbhag': lowthresh = Auto_Threshold.Shanbhag(hist) if method == 'Yen': lowthresh = Auto_Threshold.Yen(hist) if method == 'Li': lowthresh = Auto_Threshold.Li(hist) return lowthresh