Skip to content

Membrane Detector

Automatic image segmentation using a train-and-predict scheme based on random forest classification.


Overview

The Membrane Detector is a pixel classifier for automatic image segmentation, based on Random Forest for Membrane Detection by Verena Kaynig, using the randomforest-matlab library by Abhishek Jaiantilal.

It excels at segmenting complex datasets where global thresholding fails due to varying background intensities or subtle intensity gradients.

Launch via Ribbon → Tools → Classifiers → Membrane detector.


Interface

Membrane detector interface

The tool is divided into:

  • Top fields — paths for the temp directory and classifier file
  • Workflow panel — step-by-step guide to training and predicting
  • Train classifier panel — training and prediction settings
  • Log list — progress messages from the last operation

File paths

  • Temp dir — directory for temporary feature files (.fm) generated during training and prediction. Defaults to RF_Temp/ next to the open dataset. Use the browse button to change it.
  • Classifier filename — full path to the .forest classifier file. Use the browse button to pick a location.

Workflow panel

Guides the four-step process.

Step 1 — Train classifier... (toggle): activates Train mode. Training controls in the Train classifier panel are enabled. The main action button reads Train classifier.

Step 2 — Save classifier: saves the trained classifier to the file specified in Classifier filename.

Step 3 — Predict dataset... (toggle): activates Predict mode. Training-specific controls are disabled; Predict shown slice appears. The main action button reads Predict dataset.

Step 4 (optional) — Wipe Temp dir: deletes all files in Temp dir to free disk space.

Warning

Wiping the temp directory is irreversible. Make sure the temporary files are no longer needed before proceeding.


Train classifier panel

Settings used for both training and prediction.

  • Object — model material that marks the object (e.g., membrane).
  • Background — model material that marks the background.
  • Context size — context window radius in pixels for feature extraction. Smaller values suit short or highly curved structures; larger values capture more context.
  • Membrane thickness — expected thickness of the target structure in pixels.
  • Votes thresholding — threshold applied to the classifier vote probability (0–1) to produce a binary result. Values closer to 1 require stronger classifier confidence.
  • — exports the raw per-pixel vote probability map to the MATLAB workspace as mibVotes after each training or prediction step.
  • — applies skeletonise + dilate morphological closing to the prediction, useful for enforcing closed membrane outlines.
  • Predict shown slice (predict mode only) — runs prediction on the currently displayed slice as a quick preview. Results appear in the Selection layer.
  • Train classifier / Predict dataset — the main action button. Its label changes with the active mode:
    • Train mode: trains the classifier on the current slice using the labeled materials.
    • Predict mode: runs prediction across the entire dataset (or the subrange shown in the log).

Step-by-step example

This example segments endoplasmic reticulum from a time-lapse widefield dataset where global thresholding is ineffective due to background intensity gradients.

Example dataset of endoplasmic reticulum

1 — Label training areas

  • Start a new model in the Segmentation panel with New
  • Add two materials with + and rename them Object and Background
Snapshot

Model setup with Object and Background materials

  • Use the Brush tool to mark regions:
    • Select endoplasmic reticulum profiles → press A to add to Object
    • Mark background areas → press A to add to Background
Snapshot

Manual segmentation of Object and Background

2 — Train the classifier

  • Launch via Ribbon → Tools → Classifiers → Membrane detector
  • Set Object to Object and Background to Background
  • Adjust Context size and Membrane thickness as needed
  • In Step 1, click Train classifier... to activate train mode
  • Click Train classifier to train on the current slice
Snapshot

Training result on a single slice

  • If the result is unsatisfactory, add more labels (across multiple slices if needed) and retrain
  • Once satisfied, click Save classifier (Step 2)

3 — Predict the whole dataset

  • In Step 3, click Predict dataset... to activate predict mode
  • Use Predict shown slice to preview the result on the current slice
Snapshot

Prediction dialog

  • If acceptable, click Predict dataset to process the full dataset

Prediction results are written to the Selection layer. Transfer them to the Mask or Model layer for further refinement or saving.

4 — Clean up

  • Click Wipe Temp dir (Step 4, optional) to remove the large feature files generated during prediction.

Batch scripting

This tool supports batch scripting for automation.

Example
% Train on the current slice
BatchOpt.Mode                 = {'trainClassifier', {'trainClassifier','predictDataset'}};
BatchOpt.ObjectMaterial       = {'Object'};
BatchOpt.BackgroundMaterial   = {'Background'};
BatchOpt.ContextSize          = {29, [1 Inf], true};
BatchOpt.MembraneThickness    = {3, [1 Inf], true};
BatchOpt.VotesThreshold       = {0.5, [0 1], false};
BatchOpt.ExportVotes          = false;
BatchOpt.SkelClosed           = false;

obj.mibController.startController('controllers.MembranePixClassifier', [], BatchOpt);

% Predict the full dataset
BatchOpt.Mode{1} = 'predictDataset';
obj.mibController.startController('controllers.MembranePixClassifier', [], BatchOpt);

References


Back to MIB | User interface | Ribbon | Tools