Script training of Trainable Weka Segmentation 3D


I want to integrate Trainable Weka Segmentation into a plugin that I’m developing ( I managed to train and apply a “Trainable Weka Segmentation” classifier for 2d images, with the following Java code:

ImagePlus image = new ImagePlus("/path/to/imageA.tif");
ImagePlus labels = new ImagePlus("/path/to/labels-for-imageA.tif");
WekaSegmentation wekaSegmentation = new WekaSegmentation();
wekaSegmentation.addLabeledData(image, labels);
ImagePlus result = wekaSegmentation.applyClassifier(image);, "Multiply...", "value=255 stack");;

But I’m actually working with 3d images. How can I write Java code that trains a classifier for a 3D image. Like “Trainable Weka Segmentation 3D” does. (And potentially even many 3d images)

Thank you for helping

How about the constructor WekaSegmentation(boolean isProcessing3D) ?

1 Like

Using this constructor, causes an exception during classification. I’m pretty sure about the cause: The method addLabeledData only works for 2d. (It’s written in the javadoc). If I use it for 3d, I still get a 2d classifier. The exceptions are thrown because WekaSegmentation applies this 2d classifier to the 3d stack with proper 3d features.

A minimal example:

So the more precise question is: Which method can I use instead of addLabeledData for 3d images.

1 Like