Skip to content, Skip to search

Changes

Scripting the Trainable Weka Segmentation

23 bytes removed, 23 January
Update parameter syntax (the comment-based syntax is outdated)
Very frequently we might end up having to process a large number of images using a classifier that we interactively trained with the GUI of the [[Trainable Weka Segmentation]] plugin. The following [[Beanshell]] script shows how to load a classifier from file, apply it to all images contained in a folder and save the results in another folder defined by the user:
<source lang="java">
// #@File(label="Input directory", description="Select the directory with input images", style="directory") inputDir// #@File(label="Output directory", description="Select the output directory", style="directory") outputDir// #@File(label="Weka model", description="Select the Weka model to apply") modelPath// #@String(label="Result mode",choices={"Labels","Probabilities"}) resultMode
import trainableSegmentation.WekaSegmentation;
<source lang="java">
// #@File(label="Input directory", description="Select the directory with input images", style="directory") inputDir// #@File(label="Output directory", description="Select the output directory", style="directory") outputDir// #@File(label="Weka model", description="Select the Weka model to apply") modelPath// #@String(label="Result mode",choices={"Labels","Probabilities"}) resultMode// #@Integer(label="Number of tiles in X:", description="Number of image subdivisions in the X direction", value=3) xTiles// #@Integer(label="Number of tiles in Y:", description="Number of image subdivisions in the Y direction", value=3) yTiles// #@Integer(label="Number of tiles in Z (set to 0 for 2D processing):", description="Number of image subdivisions in the Z direction (ignored when using 2D images)", value=3) zTiles
import trainableSegmentation.WekaSegmentation;
<source lang="java">
// #@ImagePlus(label="Training image", description="Stack or a single 2D image") image// #@ImagePlus(label="Label image", description="Image of same size as training image containing binary class labels") labels// #@ImagePlus(label="Test image", description="Stack or a single 2D image") testImage// #@Integer(label="Num. of samples", description="Number of training samples per class and slice",value=2000) nSamplesToUse// #@OUTPUT ImagePlus prob
import ij.IJ;
import trainableSegmentation.WekaSegmentation;
<source lang=java>
// #@ImagePlus image// #@int(label="Num. of clusters", description="Number of expected clusters", value=5) numClusters// #@int(label="Num. of samples", description="Number of training samples per cluster", value=1000) numSamples// #@String(label="Clustering method",choices={"SimpleKMeans","EM"}) clusteringChoice// #@OUTPUT ImagePlus output
import ij.IJ;
import ij.ImageStack;
Bureaucrat, emailconfirmed, incoming, administrator, uploaders
718
edits