Login  Register

Re: Using TrainableWeka objects in scripts

Posted by Ignacio Arganda-Carreras on Nov 07, 2013; 9:32am
URL: http://imagej.273.s1.nabble.com/Using-TrainableWeka-objects-in-scripts-tp5005479p5005484.html

Hello Marcello,

Thanks for your interest in the Trainable Weka Segmentation. Let me try to
address your questions between your lines:


 I am trying to write a python script using the trainable weka plugin for
> Fiji.  I am using the two libraries, imported like so:
>
> from trainableSegmentation import WekaSegmentation
> from trainableSegmentation import Weka_Segmentation
>
>
What do you exactly want to do? WekaSegmentation is the back-end class,
where all the methods are stored in a library fashion. Weka_Segmentation is
the plugin class, which contains the GUI and calls the library methods to
perform learning and segmentation.


>
> My question is, how do I get the object for the learner (class
> WekaSegmentation) I create and populate with my script to be "loaded
> into"/used by the GUI I create with an object of class Weka_Segmentation


If you already trained a classifier, you can get it from your
WekaSegmentation object using the method:

AbstractClassifier<http://weka.sourceforge.net/doc.dev/weka/classifiers/AbstractClassifier.html?is-external=true>
*getClassifier
<http://fiji.sc/javadoc/trainableSegmentation/WekaSegmentation.html#getClassifier()>*
()
Returns the current classifier.

Equivalently you can set a new classifier to your WekaSegmentation object
using the method:

void *setClassifier
<http://fiji.sc/javadoc/trainableSegmentation/WekaSegmentation.html#setClassifier(weka.classifiers.AbstractClassifier)>*
(AbstractClassifier<http://weka.sourceforge.net/doc.dev/weka/classifiers/AbstractClassifier.html?is-external=true>
 cls)
Set current classifier

If what you want is to load a new classifier into the GUI
(Weka_Segmentation object) then you have to do it from file using the
following method:

static void *loadClassifier
<http://fiji.sc/javadoc/trainableSegmentation/Weka_Segmentation.html#loadClassifier(java.lang.String)>*
(String<http://docs.oracle.com/javase/6/docs/api/java/lang/String.html?is-external=true>
 newClassifierPathName)
Load a new classifier

For encapsulation reasons there's no easy way to access the
WekaSegmentation object from the GUI. There's a workaround if you need it
by getting the object from the CustomWindow:

final ImageWindow iw = WindowManager.getCurrentImage().getWindow();
if( iw instanceof CustomWindow )
{
final CustomWindow win = (CustomWindow) iw;
 final WekaSegmentation wekaSegmentation = win.getWekaSegmentation();
}


> .
>
> Or, alternatively, is there a way to get a handle for the WekaSegmentation
> object (I am guessing might be) a member of the Weka_Segmentation class?
>  This way I could just populate the images+ROIs in that.
>
>
Just the way I just explained.



> The goal here is to get my Images and ROIs to appear in the Plugin GUI.
>  For now.  But with the possibility of doing all the processing headless
> if/when the time comes...
>

I see. That's a bit tricky. The idea behind the library + plugin (GUI)
structure is that you can call all the library methods from any script or
plugin without the need of the GUI. If you then need to go back to the GUI,
you're supposed to load the classifier and/or data using the corresponding
buttons or macro commands. Why is that strategy not working for you?

Best,

ignacio


--
Ignacio Arganda-Carreras, Ph.D.
Seung's lab, 46-5065
Department of Brain and Cognitive Sciences
Massachusetts Institute of Technology
43 Vassar St.
Cambridge, MA 02139
USA

Phone: (001) 617-324-3747
Website: http://bioweb.cnb.csic.es/~iarganda/index_EN.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html