fiji / Trainable_Segmentation

Fiji library to perform image segmentation based on the Weka learning schemes
https://imagej.net/Trainable_Weka_Segmentation
GNU General Public License v3.0
106 stars 60 forks source link

Applying a saved classifier returns a black image when running script #56

Open J-na opened 4 years ago

J-na commented 4 years ago

Hello, i want to use Trainable Weka Segmentation to analyse images of fluorescent cell clusters. When manually running the plugin i can load a saved classifier and apply it just fine. However, when automating the segmentation using a beanshell script it returns a black image instead as the result. This is the script used:

import ij.IJ; import ij.ImageStack; import ij.ImagePlus; import ij.process.ColorSpaceConverter; import ij.process.ByteProcessor; import trainableSegmentation.*; import weka.clusterers.EM; import weka.clusterers.SimpleKMeans; import weka.core.WekaPackageManager; import weka.core.WekaPackageClassLoaderManager; // input train image input = IJ.getImage(); // create Weka Segmentation object segmentator = new WekaSegmentation( input ); // load classifier from file segmentator.loadClassifier("D:/fiji-win64/greenClass.model"); // apply classifier to current training image and get label result // (set parameter to true to get probabilities) segmentator.applyClassifier(false); // get result (float image) result = segmentator.getClassifiedImage(); result.show();

The script does return the probability maps as expected , but not the classified image . The used image and expected results are shown here:

The original image Cell_cluster The result from manual segmentation Manual_result The result from running the script with segmentator.applyClassifier(false); , this happens for every image processed using the script Result_from_script The probability from running the script with segmentator.applyClassifier(true); Probablility_from_script

I am not sure if this is an issue with the script i am using or with the trainable segmentation itself, but i am hoping it is an easy fix. Thanks in advance :)

Edit: I also tried to immediately convert the generated probability using this script posted earlier https://gist.github.com/iarganda/c7fc0a88b8d2737c9d3d , which generated the same black image as generated by segmentator.applyClassifier(false);. Perhaps it is something related to this?

iarganda commented 4 years ago

Hello @J-na,

Are you sure the image is completely "black"? It might be just 0s and 1s so you need to adjust the contrast or simply apply a LUT to see both classes. If you want to have the same LUT as in the plugin, after getting the result image, do the following:

import trainableSegmentation.utils.Utils;

result.setLut( Utils.getGoldenAngleLUT() ); 

You have more information here.

J-na commented 4 years ago

Hello @iarganda,

Thank you for getting back to me so quick. Intensity analysis confirms that the image contains only pixels with 0 intensity. Applying the golden angle LUT results in this image. Threshholded_probabilities_LUT

A quick test of the 'color-based segmentation using clustering' seems to produce promising results so i will look into using that instead.