Login  Register

Re: Apply WEKA segmentation script

Posted by Ignacio Arganda-Carreras-2 on Jan 24, 2020; 3:30pm
URL: http://imagej.273.s1.nabble.com/Apply-WEKA-segmentation-script-tp5022890p5022893.html

Hello Rainer,

What works for me is to put the .bsh files under
Fiji.app/plugins/Scripts/Plugins/

Is that what you do? You can also create a folder inside the above path so
the script shows up in the menu under Plugins > "your folder name".

Cheers!

On Fri, Jan 24, 2020 at 2:01 PM Rainer M. Engel <[hidden email]> wrote:

> Can somebody help me, why the provided BeanShell-Script below does work
> nicely from the editor but not when put into ImageJ's 'scripts'-folder
> to be executed from the menu.
>
> That would be great..
>
> Kind regards,
> Rainer
>
>
>
>
> Am 23.01.2020 um 10:37 schrieb Rainer M. Engel:
> > Hey..
> >
> > I tried WEKA automation via macro and despite of all the available
> > commands this seems to be not that ideal, although this is a clear
> > drawback considering the GUI for a nice way to create robust models,
> > which shall/could also be applied via macro (batch).
> >
> > To wait for the UI to pop up could be enhanced via..
> >
> >>> macro language..........................................START
> > wekaNotReady  = true;
> > c = 0;
> > while (wekaNotReady && c < 60) {
> >       if (isOpen("Trainable Weka Segmentation v3.2.33") == true) {
> > wekaNotReady  = false; }
> >       wait(50);
> >       c++;
> > }
> > << macro language............................................END
> >
> > But I could not work with batch mode and WEKA (macro).
> >
> > So this BeanShell-Script offers the same functionality like the known
> > "Apply SIOX segmentator" for SIOX but in this case for WEKA (only a
> > modification of a script, which was part of the WEKA documentation.
> >
> >>> BeanShell language (Apply-saved-WEKA-segmentator.bsh).........START
> > // @File(label="Weka model", description="Select the Weka model to
> > apply") modelPath
> > // @String(label="Result mode",choices={"Labels","Probabilities"})
> > resultMode
> >
> > import trainableSegmentation.WekaSegmentation;
> > import trainableSegmentation.utils.Utils;
> > import ij.io.FileSaver;
> > import ij.IJ;
> > import ij.ImagePlus;
> >
> > // based on the beanshell script found on:
> > // https://imagej.net/Scripting_the_Trainable_Weka_Segmentation modified
> > by rengel, 2020-01
> >
> > // starting time
> > startTime = System.currentTimeMillis();
> >
> > // caculate probabilities?
> > getProbs = resultMode.equals( "Probabilities" );
> > // create segmentator
> > segmentator = new WekaSegmentation();
> > // load classifier
> > segmentator.loadClassifier( modelPath.getCanonicalPath() );
> >
> > // get details from already opened image
> > image = IJ.getImage();
> > //IJ.log(""+image);
> >
> > // apply classifier and get results (0 indicates number of threads is
> > auto-detected)
> > result = segmentator.applyClassifier( image, 0, getProbs );
> >
> > if( !getProbs )
> >       // assign same LUT as in GUI
> >       result.setLut( Utils.getGoldenAngleLUT() );
> >
> > // show result
> > result.show();
> >
> > // force garbage collection (important for large images)
> > result = null;
> > image = null;
> > System.gc();
> >
> > // print elapsed time
> > estimatedTime = System.currentTimeMillis() - startTime;
> > IJ.log( "** Finished processing image in " + estimatedTime + " ms **" );
> > << BeanShell language............................................END
> >
> >
> > I put the "Apply-saved-WEKA-segmentator.bsh" into a sub-folder of
> > 'scripts' to see this script in the menu of ImageJ, but it is not shown,
> > although my Python scripts are. Any help on this is much appreciated.
> >
> > Kind regards,
> > Rainer
> >
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>


--
Ignacio Arganda-Carreras, Ph.D.
Ikerbasque Research Fellow
Departamento de Ciencia de la Computacion e Inteligencia Artificial
Facultad de Informatica, Universidad del Pais Vasco
Paseo de Manuel Lardizabal, 1
20018 Donostia-San Sebastian
Guipuzcoa, Spain

Phone : +34 943 01 73 25
Website: http://sites.google.com/site/iargandacarreras/

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