Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
J-na opened this issue Jun 5, 2020 · 2 comments
Open
Assignees

Comments

@J-na
Copy link

J-na commented Jun 5, 2020

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 iarganda self-assigned this Jun 5, 2020
@iarganda
Copy link
Collaborator

iarganda commented Jun 5, 2020

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
Copy link
Author

J-na commented Jun 5, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants