Interactive image segmentation using trainable classifiers and superpixel-level features.
Trainable Superpixel Segmentation (TSS) is an ImageJ 1.x / Fiji plugin for interactively segmenting images by annotating superpixels, training a classifier, and applying it to the image.
Trainable Superpixel Segmentation (TSS) combines superpixel generation, feature extraction, and machine-learning classification to provide an interactive workflow for image segmentation. Features describing each superpixel include colour, texture and morphological measurements provided by MorphoLibJ, while classification is performed using standard classifiers from Weka.
Users can select representative regions directly on the image, assign them to classes, train a classifier, and apply the resulting model to obtain a segmentation.
| Figure 1: Overview of the Trainable Superpixel Segmentation pipeline: superpixel generation, feature extraction, classifier training and segmentation. |
- Download the latest plugin jar from the GitHub releases page for this project (look for
Trainable_Superpixel_Segmentation-<version>.jar), for example: Trainable_Superpixel_Segmentation-1.0.0.jar - Copy the jar into your ImageJ/Fiji
plugins/directory. - Make sure MorphoLibJ is installed in your ImageJ/Fiji instance (you can install it from the ImageJ update site or by copying the MorphoLibJ jar into
plugins/). - Restart ImageJ. The plugin appears under the Plugins menu ("Segmentation > Trainable Superpixel Segmentation").
Requirements
- Java JDK (8 or later)
- Maven
Build steps
- From the project root run:
mvn package- The build produces a jar under
target/(for exampletarget/Trainable_Superpixel_Segmentation-0.0.1-SNAPSHOT.jar). - To test locally, copy that jar into ImageJ's
plugins/folder and restart ImageJ.
This short tutorial helps you use the plugin once it is installed.
The TSS plugin expects two images as input:
- A grayscale or RGB input image (original image to be segmented).
- To test the plugin, you can use this sample input image.
- Its corresponding superpixel image (label image resulting from applying a superpixel method to the original image).
- To test the plugin, you can use this sample superpixel image.
| Figure 2: Example of input image (left), with corresponding superpixel overlay from SLIC (center), and superpixel image with segmentation labels (right). | ||
Note: Any superpixel segmentation method can be used to produce the label image. In our experiments, we mostly use SLIC.
When clicking on Plugins > Segmentation > Trainable Superpixel Segmentation, the following dialog will pop up:
Select your grayscale or RGB image as "Input image" and your indexed (label) image as "Superpixel image", and click "OK".Tip: For better visualization of the superpixels, you can select a colorful lookup table. Before, calling the plugin, select the label image, click on Image > Lookup Tables > Glasbey (or any other lookup table).
After selecting the input and superpixel images, the main GUI of the plugin will pop up:
|
|
| Figure 4: Main GUI of Trainable Superpixel Segmentation, showing the controls (left), image (center) and labels (right) panels. |
- Controls panel — contains the buttons for training and applying classifiers, creating results and probability maps, managing classes, and opening the settings.
- Image panel — displays the input image and, when enabled, an overlay showing the superpixels or the segmentation result. You can also click on the image here to select regions for training.
- Labels panel — contains the available classes and the regions assigned to each class.
The workflow is simple: select representative regions in the image, assign them to classes, train a classifier, and apply it to the image.
The controls panel provides the main operations:
- Train classifier — trains the selected classifier using the regions assigned to the different classes. The features used for training are those selected in Settings.
- Toggle overlay — cycles through the available image views:
- the original image,
- the original image with the superpixel boundaries/labels overlaid, and
- the image with the segmentation result overlaid.
- Create result — creates and displays the segmentation result. If a classifier has not yet been trained, the plugin will train one from the selected regions before generating the result.
- Get probability — generates a probability map for each class using the trained classifier. The maps are returned as an image stack, with one slice per class.
- Plot result — opens the statistics window provided by WEKA for the trained classifier.
- Apply classifier — applies the current classifier to the image. If no classifier has been trained or loaded, one is trained from the currently selected regions first.
- Load classifier — loads a previously saved WEKA classifier from a
.modelfile. The plugin reads the classes stored in the model and updates the GUI accordingly. - Save classifier — saves the current classifier as a
.modelfile so that it can be reused later. - Create new class — creates an additional class. The new class is added to the Classes panel alongside the default classes.
- Settings — opens the settings dialog, where you can select the image features used for training, adjust the overlay opacity, and choose/configure the WEKA classifier.
The image panel is where you interact with the image and select training examples.
Click on the image to select one or more superpixels. The selected regions can then be assigned to one of the classes using the corresponding Add to class button in the Classes panel.
The Toggle overlay button is particularly useful here: displaying the superpixel overlay makes it easier to see which region will be selected when you click on the image.
The Labels panel contains the classes used for training. Two classes are created by default, and additional classes can be added with Create new class.
For each class:
- Click Add to class to assign the currently selected regions to that class.
- The list below the button shows the regions already assigned to the class.
- Click an entry in the list to display the corresponding selected point in the image.
- Double-click an entry to remove that region from the class.
Try to select representative regions for each class. Once enough examples have been assigned, click Train classifier to train the model.
The Settings dialog controls the main parameters used by the plugin:
- Features — select which region features are used to represent the superpixels during training and classification.
- Overlay opacity — controls the transparency of the superpixel or result overlay. The value can be set from
0to1. - Classifier — select the WEKA classifier and configure its available options.
|
|
| Figure 9: Settings dialog for selecting training features, overlay opacity and the WEKA classifier, and modifying the class names. |
- Label representative superpixels that cover intra-class variability and different images.
- Choose a superpixel size that respects the structures of interest.
- Combine color and texture features for complex textures.
- Try different classifiers and tune hyperparameters if results are unsatisfactory.
This plugin is part of a final degree project by Josu Salinas. The full report (methodology, experiments and results) is available here.