http://imagej.273.s1.nabble.com/Apply-WEKA-segmentation-script-tp5022890p5022893.html
the script shows up in the menu under Plugins > "your folder name".
On Fri, Jan 24, 2020 at 2:01 PM Rainer M. Engel <
> 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.