Trainable Weka Segmentation

Hello ImageJ community

I am trying to call Trainable Weka Segmentation in ImageJ, but the error says that it cannot be called:

run(“Trainable Weka Segmentation”);

Can anyone help me?

Sincerely,

Erika

Welcome to the forum, @Erika_Gedvilaite!

It would help greatly if you could please post the exact error message. Please see Bug reporting best practices for details.

Some quick questions and comments:

Firstly: you are using Fiji, right?

Secondly: right now, TWS dumps some errors to the Console window, of the form:

Refreshing GOE props...
java.lang.NullPointerException
	at weka.core.ClassCache.initFromManifest(ClassCache.java:248)
	at weka.core.ClassCache.initFromJar(ClassCache.java:293)
	at weka.core.ClassCache.initFromClasspathPart(ClassCache.java:351)
...

These are harmless and normal. (Unfortunately, they are generated by the underlying Weka library, so it is difficult to get rid of them on the ImageJ side.) You will know TWS is working if a file chooser dialog box pops up.

Lastly: you saw the TWS macro docs, right?

1 . This is the exact code that I am running:

open(“input_image”);


var image_name = getInfo("image.filename");
var path_name = getDirectory("image")+ getInfo("image.filename");
print(path_name);
var outputtxt = getDirectory("image")+ getInfo("image.filename") + “txt”;
print(outputtxt);
var outputjpeg = getDirectory("image")+ getInfo("image.filename") + “jpeg”;
print(outputjpeg);
var response;
var image_width = getWidth();
var image_height = getHeight();
var num_pixels = 0;
var density = 0;

if (image_width == 512)
{
	selectWindow(image_name);
	run("Close");
	open(path_name);
	image_width = getWidth();
	image_height = getHeight();
	
}
run("8-bit");
run("Size...", "width=512 height=380 constrain average interpolation=Bilinear");

run("Trainable Weka Segmentation");
wait (1000); 
selectWindow("Trainable Weka Segmentation v2.3.0");
call("trainableSegmentation.Weka_Segmentation.loadData", "/Applications/Fijiwings2.2.app/plugins/ActionBar/data.arff");
call("trainableSegmentation.Weka_Segmentation.trainClassifier");
call("trainableSegmentation.Weka_Segmentation.getResult");

selectWindow("Classified image");
if(getTitle() != "Classified image"){
	selectWindow("Trainable Weka Segmentation v2.3.0”);
	run("Close");
	exit();
}
run("8-bit");
setOption("BlackBackground", false);
run("Make Binary");
run("Invert");
run("Open");
run("Fill Holes");

run("Set Measurements...", "area redirect=None decimal=3");
run("Analyze Particles...", "size=600-Infinity pixel circularity=0.05-1.00 show=[Bare Outlines] clear add");

selectWindow("Classified image");
close();
selectWindow("Trainable Weka Segmentation v2.3.0");
close();
selectWindow("Log");
run("Close");
selectWindow(image_name);
run("Close");
selectWindow("Drawing of Classified image");
setLocation(736,96);
run("Size...", "width=image_width height=image_height constrain average interpolation=Bilinear");

open(path_name);

roiManager("measure");
selectWindow("Results");
	saveAs("Text",);
	close();
selectWindow("Drawing of Classified image");
	saveAs(“Jpeg”,);
	close();

close("*");
run("Close");
  1. Error : “Unrecognized command: “Trainable Weka Segmentation””

  2. I am using Fiji and FijiWings, a package that helps to look at Fly wings.

Thank you again for all of the help.

Erika

After replacing the “smart quotes” in your macro with normal quotes, I am able to run this macro on a small sample image, with the Trainable Weka Segmentation plugin launching successfully. (I ultimately receive the error “Cannot train without at least 2 sets of examples!” but clearly my Fiji is making it further than yours is.)

I also downloaded the FijiWings distribution and tried with that as well, and it got similarly far. No error about TWS being an unrecognized command.

I then ran Help :arrow_forward: Update… and updated the FijiWings installation to the latest version. After restarting, I again got similarly far when executing your macro.

So: maybe there is some local modification to your installation that is causing trouble here? Can you please verify that your Fiji is fully up-to-date?

2 Likes

Dear Rueden,

Thanks for all of the help. I will try to figure out the error message. I feel like Weka is causing majority of the programs, not ImageJ or FijiWings. Thanks again for all of the help and ideas in trying to solve this.

Sincerely,

Erika