Advertisement
Guest User

Bubblesizer

a guest
Apr 21st, 2017
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. from ij import IJ, WindowManager
  2. from trainableSegmentation import WekaSegmentation
  3. import Watershed_Irregular_Features
  4. from ij.process import ImageConverter
  5. def bubblesizer():
  6.  
  7.     # Please define the path to your classifier.
  8.     classifer_path = "D:\\Bubbles.model"
  9.    
  10.     # Gets the image you want to segment.
  11.     your_image = IJ.getFilePath("Select image for WEKA segmentation")
  12.     target = IJ.openImage(your_image)
  13.    
  14.     #launches weka segmentation.
  15.     weka = WekaSegmentation()
  16.     weka.setTrainingImage(target)
  17.  
  18.     # Loads the classifier you have trained manually.
  19.     weka.loadClassifier(classifer_path)
  20.     weka.applyClassifier(False)
  21.  
  22.     # Shows you the segmented image.
  23.     segmentation = weka.getClassifiedImage()
  24.     segmentation.show()
  25.  
  26.     # Converts to binary, runs watershed segmentation and analyze particles. Outputs area measurements.
  27.     ImageConverter(segmentation).convertToGray8()
  28.  
  29.     WindowManager.getCurrentImage()
  30.     IJ.run("Make Binary")
  31.     IJ.run("Invert")
  32.     IJ.run(segmentation, "Watershed Irregular Features", "erosion=1 convexity_treshold=0 separator_size=0-200")
  33.     IJ.run("Analyze Particles...", "size=50-Infinity circularity=0.1-1.00 show=Outlines display summarize")
  34.  
  35. bubblesizer()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement