Login  Register

Re: weka segmentation in batch mode

Posted by Ignacio Arganda-Carreras on Mar 21, 2014; 8:56am
URL: http://imagej.273.s1.nabble.com/weka-segmentation-in-batch-mode-tp5007024p5007027.html

Hello Aryeh and Will,

For the classification task I think it's a bit risky to use a delay anyway
because you don't know how long the classification will take. Have you
tried using a script instead of a macro? That allows you to have much more
control over the images and the commands are executed as in a regular
program, so you won't need any wait call.

Have a look at:

http://fiji.sc/Scripting_the_Trainable_Segmentation

A simple Beanshell script equivalent to your macro code would be:

import trainableSegmentation.*;

 // input train image
 input  = IJ.openImage( "input-grayscale-or-color-image.tif" );
 // create Weka Segmentation object
 segmentator = new WekaSegmentation( input );
 // load classifier from file
 segmentator.loadClassifier( "my-cool-trained-classifier.model" );

 // apply classifier to current training image and get label result
 // (set parameter to true to get probabilities)
 segmentator.applyClassifier( false );
 // get result (float image)
 result = segmentator.getClassifiedImage();
Let me know if you have questions about it!

ignacio



On Fri, Mar 21, 2014 at 7:11 AM, Aryeh Weiss <[hidden email]> wrote:

> On 3/21/14, 7:52 AM, William Menegas wrote:
>
>> Hello,
>>
>> I was wondering if anyone could give me some advice on using "Weka
>> Segmentation" in headless mode or in a normal session of fiji in batch
>> mode. I am using:
>>
>> ...
>> run("Trainable Weka Segmentation");
>> call("trainableSegmentation.Weka_Segmentation.loadClassifier",
>> "/path/classifier.model");
>> call("trainableSegmentation.Weka_Segmentation.getProbability");
>> selectWindow("Probability maps");
>> ...
>>
>> The problem is that fiji doesn't seem to want to wait for the
>> classification. I tried inserting "wait(100000)" before
>> "selectWindow("Probability maps"), but it didn't help and I don't think
>> there was even a wait.
>>
>> Any help would be much appreciated!
>> Will
>>
>> --
>> ImageJ mailing list:http://imagej.nih.gov/ij/list.html
>>
>>  I had a similar problem with the EDF plugin. Here is a quote form that
> post:
>
>> The problem I have is that the macro does not wait for EDF to finish, and
>> EDF can take a while.
>> My solution to this is based on the fact that EDF creates a window called
>> "Output". so I did the following:
>>
>> initTime = getTime();
>> while ( !isOpen("Output") ) {
>>     elapsedTime = getTime() - initTime;
>>     if (elapsedTime%10000 == 0) {
>>         print(elapsedTime/1000, " seconds elapsed");
>>         wait(10);
>>     }
>>
>> which works (as  long as there is no other window called "Output"). I
>> print an occasional reminder that the macro is still alive within this wait
>> loop.
>>
>
> I posted this as a question, wondering if there is a better way to do it.
> I did not receive any reply, so perhaps in a macro this is the way to go.
> You should replace "Output" with "Probability maps".
>
> --aryeh
>
> --
> Aryeh Weiss
> Faculty of Engineering
> Bar Ilan University
> Ramat Gan 52900 Israel
>
> Ph:  972-3-5317638
> FAX: 972-3-7384051
>
>
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
> --
> 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://imagej.nih.gov/ij/list.html>
> http://bioweb.cnb.csic.es/~iarganda/index_EN.html
>

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