(set parameter to true to get probabilities) apply classifier to current training image and get label result Once the classifier is trained (it will be displayed in the Log window), we can apply it to the entire training image and obtain a result in the form of a labeled image or a probability map for each class: Once we have training samples for both classes, we are ready to train the classifier of our segmentator: Please, have a look at them and decided which one fits better your needs. Segmentator.addRandomBalancedBinaryData( input2, labels2, "class 2", "class 1", numSamples) ĥ) You can use all methods available in the API to add labels from a binary image in many differente ways. 1000 black pixels as labels for class 1
for all slices in input2, add 1000 white pixels as labels for class 2 and Segmentator.addBinaryData( input2, labels2, "class 2", "class 1" ) Ĥ) If you want to balance the number of samples for each class you can do it in a similar way using this other method: for all slices in input2, add white pixels as labels for class 2 and
Labels2 = IJ.openImage( "binary-labels-2.tif" ) Input2 = IJ.openImage( "input-image-2.tif" ) Segmentator.addBinaryData( labels, 0, "class 2", "class 1" ) ģ) You can also add samples from a new input image and its corresponding labels: for the first slice, add white pixels as labels for class 2 and Labels = IJ.openImage( "binary-labels.tif" ) There are a few methods to do this, for example: Segmentator.addExample( 1, new Roi( 400, 400, 30, 30 ), 1 ) Ģ) add the labels from a binary image, where white pixels belong to one class and black pixels belong to the other class. add pixels to second class (1) from ROI in slice # 1 add pixels to first class (0) from ROI in slice # 1 There are different ways of adding labels to our data:ġ) we can add any type of ROI to any of the existing classes using "addExample": If we are fine with that, we can now add some labels for our training data and train the classifier based on them. That means that it will use the same features that are set by default in the Trainable Weka Segmentation plugin, 2 classes (named "class 1" and "class 2") and a random forest classifier with 200 trees and 2 random features per node. Segmentator = new WekaSegmentation( input ) Īs it is now, the segmentator has default parameters and default classifier. Input = IJ.openImage( "input-grayscale-or-color-image.tif" ) We can open our input image and assign it to a WekaSegmentation object or segmentator: In order to include all the library methods, the easiest (but not elegant) way of doing it is importing the whole library: Let's go through the basic commands with examples written in Beanshell: For that, please have a look at the API of the Trainable Weka Segmentation library, which is available here. The first thing you need to start scripting the Trainable Weka Segmentation is to know which methods you can use.
Interface is largely inspired from the open source software "ImageJ". It allows to load images, apply filtering and/or segmentation, and run basic analyses. ImageM integrates into a GUI several algorithms for interactive image processing and analysis.