Trainable Weka Segmenatition

Hi
I’m trying to develop a macro (in ijm format ) equivalent to https://imagej.net/Scripting_the_Trainable_Weka_Segmentation#Example:_apply_classifier_to_all_images_in_folder
that does exactly what I intended, but is coded as a Beanshell script (I need to edit some parts of the code and I’m not fluent in Beanshell, that’s why I would want to go for ijm language).

I was able to do that, but the replacement for the next two code lines sounds odd to me

// create segmentator
segmentator = new WekaSegmentation();
// load classifier
segmentator.loadClassifier( modelPath.getCanonicalPath() );

I can’t just load the classifier without previously open the main weka window, and to do that I need an image previously loaded into memory. The way I found to overcome the problem was to create / open a dummy image.

newImage("Untitled", "8-bit black", 512, 512, 1);
run("Advanced Weka Segmentation");
wait(3000);
call("trainableSegmentation.Weka_Segmentation.loadClassifier", modelPath);

and then call

call("trainableSegmentation.Weka_Segmentation.applyClassifier", inDir, list[it], "showResults=true", "storeResults=true", "probabilityMaps=true", outDir);

This approach, in addition to forcing me to create an extra image, makes it unable to run everything in batch mode, since the main weka window (and therefore the first image) must be visible. Is there any other alternative using ijm language?

Thanks
Eduardo

@econdesousa

Why not use the BeanShell script? I use that one all the time - works really well. As far as not knowing BeanShell - there is always Google… and you can also use the Macro Recorder… to record commands in BeanShell. If you have specific questions regarding ‘how to’ code something… just post here. There are enough folks who could help.

What about the current script template do you need to modify? I suppose it all depends on how much you need to modify - eh?

You’re right about that one working well.

Regarding BeanShell, it is in my to do list, but now I’m in a hurry so I need to use ijm.

The solution I found works fairly well. I just became curious why with BeanShell you can load the classifier in the background while in ijm you need an image and the main weka window open previously and whether there is an alternative that I missed somehow.
Best
Eduardo

1 Like