Re: A couple of more questions about AWS

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: A couple of more questions about AWS

Ignacio Arganda-Carreras
Hello Dionysios,

Let me answer your question cc-ing the whole ImageJ list. I'm sure this
will help other people too.

I have been trying to find my way around beanshell and javascript for

> the last few days. I have been studying your suggestions and the code
> provided in "Scripting the Trainable Segmentation" webpage.
>
> A friendly comment first, as I am not sure that you are the creator of
> this webpage: As a newbie on both languages, I find difficult to follow
> it as the fist is in javascript and the second one in beanshell. I think
> for less seasoned people (like me) coming from the macro language, this
> can be confusing as they are both java-like but with some differences.
> Maybe, you should just stick to one of the two or better provide the
> scripts in both. I know there is a script comparison page, but...
>
>
I'm sure that's just a learning curve problem. Once you're comfortable with
a script language, you'll be able to "read" the other scripts more easily.
I'll try to work on the scripting page to make it more friendly anyway.
Thanks for your suggestions.



> Moving on, is there a way to know which are the available
> methods/classes while you are programming in script editor, like code
> auto-completion or something? For example, in the macro language,
> everything is documented in the "built-in functions" webpage and you can
> always use macro recorder to help you out (i know that works in
> javascript, but no in beanshell).
>
>
For Beanshell you can use the API of Trainable_Segmentation package. From
the script editor, you go directly to the desired class using "Tools > Open
Help for Class..." and then type for example "WekaSegmentation".



> As a start, I have been trying to run the beanshell script in "Define
> binary labels programmatically" loading my own images and it fails. It
> gives me a "java.lang.ArrayIndexOutOf BoundsException: 2" pop up
> message, without anything in the error prompt and then the classifier
> fails. I located that the problem should be that it cannot set the
> enabled features with "seg.setEnabledFeatures( enableFeatures );". Do
> you have any suggestions on this? I only modified the path to my images
> and nothing else.
>
>
The script works for me with the latest Fiji version. Have you changed
something apart from the input images? If you send me the script and the
images I can try to reproduce the error on my machine.



> Apart from the above, my goal is to setup a mixed feature vector (custom
> feature + standard features). So, I guess, I have to enable my selected
> standard features, then compute the custom ones and add them to the
> FeatureStack. I can see how you can enable feature groups along with the
> parameters (sigma, membrane size etc.), which is similar in fashion to
> what AWS does in the GUI. However, I have not figured out how you can
> prepare a feature vector using only specific features (Sobel_filter_2.0,
> Hessian_Eigenvalue_1_4.0, Difference_of_gaussians_16.0_1.0 etc.). Do I
> need to set the parameters needed first, compute a single feature, add
> it to FeatureStack and reset the parameters for the next one and so on?
>
>
Defining your own features is exactly what the other script in the wiki
page does. What you need to do is:

1) Create your own features, i.e. filtered versions of your training image.
If you have a stack, then you need to create the same features for each
slice of the stack. Make sure that each feature has a unique name.
2) Add those features to the FeatureStack of each slice of the training
image, and then add the feature stacks into a FeatureStackArray.
3) Set the feature stack array to the WekaSegmentation object.
 4) Train.

If you just one to specify a smaller set of the already existing features
you can do it with the method "setFeatures( ArrayList )". For example, in
the beanshell script you would remove lines 32 to 62 and add something like
this:

// declare list of features
list = new ArrayList();

// add specific feature names and parameters
list.add("Anisotropic_diffusion_20_1_0.1_0.9");
list.add("Hessian_Trace_1.0");
list.add("Hessian_Eigenvalue_1_1.0");
list.add("Variance_1.0");
list.add("Mean_1.0");
list.add("Minimum_1.0");
list.add("Gaussian_blur_2.0");
list.add("Hessian_Trace_2.0");
list.add("Hessian_Eigenvalue_1_2.0");

// set features to Weka segmentator
seg.setFeatures(list);

Let me know if you have questions about this.


> Sorry for my long email and thanks again for your invaluable help!
>

No problem! I hope this helps!

ignacio


> Dionysios
>
>
>
> -----Original Message-----
> From: Ignacio Arganda-Carreras <[hidden email]>
> To: Dionysios Lefkaditis <[hidden email]>
> Subject: Re: A couple of more questions about AWS
> Date: Fri, 8 Mar 2013 10:16:39 -0500
>
> No problem! Let me know if I can be of further help. I usually make
> small experiments first in BeanShell and then add them to the plugin.
> It's very useful!
>
>
> ignacio
>
> On Fri, Mar 8, 2013 at 7:50 AM, Dionysios Lefkaditis
> <[hidden email]> wrote:
>         Hello Ignacio,
>
>         It works perfectly! Thanks so much for your help. You will
>         probably hear
>         from me soon as I dig into beanshell and the addition of custom
>         features.
>
>         all the best,
>         Dionysios
>
>
>
>         -----Original Message-----
>         From: Ignacio Arganda-Carreras <[hidden email]>
>         To: Dionysios Lefkaditis <[hidden email]>
>         Subject: Re: A couple of more questions about AWS
>
>         Date: Thu, 7 Mar 2013 16:58:00 -0500
>
>         OK, i made some changes. Let me know if this works for you.
>
>
>         Best,
>
>
>         ignacio
>
>
>         On Thu, Mar 7, 2013 at 9:18 AM, Dionysios Lefkaditis
>         <[hidden email]> wrote:
>                 Hello Ignacio,
>
>                 I have been busy with some other projects during the
>         past weeks.
>                 I just
>                 had a look to extend the number of classes that can be
>         defined
>                 in AWS.
>                 You suggested me to just change the MAX_NUM_CLASSES
>         variable in
>                 the
>                 "WekaSegmentation.java" file (I made it 10).
>
>                 Well, it seems it is not that simple. Doing just that,
>         the code
>                 would
>                 not compile, so I modified the available colours for the
>         classes
>                 in line
>                 180 in "Weka_Segmentation.java". So, I added the
>         required number
>                 of
>                 colours and now it compiles fine.
>
>                 I can now add more than 5 classes without getting a GUI
>         warning.
>                 However, the plugin window can only accommodate up to 5
>         classes
>                 for
>                 labelling, so I cannot add labels to more than 5 classes
>                 interactively.
>                 When I try to add labels through a script, it will only
>         train a
>                 5-class
>                 classifier and the rest are ignored. And finally, if I
>         load a
>                 trained
>                 6-class classifier it will not accept it.
>
>                 Could you give me some hints on what needs to be further
>                 modified? I am
>                 attaching the "Weka_Segmentation.java" and
>                 "WekaSegmentation.java" for
>                 you to see what exactly I have modified.
>
>                 Thanks a lot and best regards,
>
>
>                 --
>                 Dionysios Lefkaditis
>
>                 Project Engineer
>
>                 FMTC
>
>                 www.fmtc.be
>
>                 Celestijnenlaan 300D
>
>                 3001 Heverlee
>
>                 Belgium
>
>                 Tel: +32-16-328041
>
>                 GSM: +32-498-919436
>
>                 Fax: +32 16 32 80 64
>
>                 Meet JADA, the first badminton robot in the world!
>          YouTube -
>                 FMTCvzw's Channel
>
>
>
>                 -----Original Message-----
>                 From: Ignacio Arganda-Carreras <[hidden email]>
>                 To: Dionysios Lefkaditis <[hidden email]>
>                 Subject: Re: A couple of more questions about AWS
>
>                 Date: Wed, 20 Feb 2013 12:49:42 -0500
>
>                 Great!
>
>
>                 Using Beanshell scripts is like writing java code, but
>         you can
>                 also do
>                 all the macro calls in nicer way. Let me know if you
>         need help.
>
>
>                 ignacio
>
>                 On Wed, Feb 20, 2013 at 5:11 AM, Dionysios Lefkaditis
>                 <[hidden email]> wrote:
>                         Hi Ignacio,
>
>                         Thank you so much for your detailed response.
>         That's
>                 quite a lot
>                         for me
>                         to take in, but that's very good. I was trying
>         to avoid
>                 having
>                         to move
>                         to a more powerful scripting language, but I
>         guess I
>                 have
>                         reached the
>                         limits of the macro language and I have to move
>         on. For
>                 some
>                         reason, I
>                         was unaware of the "Scripting the Trainable
>                 Segmentation" page,
>                         was it
>                         added recently? It totally blew my mind! Anyway,
>         let me
>                 study
>                         all this
>                         and I will try to make the most of it.
>
>                         thanks again,
>                         Dionysios
>
>
>
>                         -----Original Message-----
>                         From: Ignacio Arganda-Carreras
>         <[hidden email]>
>                         To: Dionysios Lefkaditis
>         <[hidden email]>
>                         Subject: Re: A couple of more questions about
>         AWS
>                         Date: Tue, 19 Feb 2013 16:44:21 -0500
>
>                         OK, let me answer your questions between your
>         lines:
>
>
>                                 Would it be possible/easy to allow the
>         addition
>                 of more
>                         than 5
>                                 classes
>                                 AWS? And I have another one below...
>
>
>
>                         The answer is yes, but you need to change the
>         code. More
>                 exactly
>                         the
>                         variable
>                         MAX_NUM_CLASSES:
>
>
>
> http://fiji.sc/javadoc/trainableSegmentation/WekaSegmentation.html#MAX_NUM_CLASSES
>
>
>
>                                 As you probably know, I was interested
>         to apply
>                 a weka
>                                 classifier and
>                                 call it with exec() from within a macro,
>         but it
>                 fails. I
>                         was
>                                 wondering
>                                 how could you access the internal weka
>                 instalation of
>                         Fiji with
>                                 call()?
>
>
>                         I remember you wanted to call Weka from a macro
>         to make
>                 a system
>                         call
>                         and apply the classifier. But I don't understand
>         why.
>                 Can't you
>                         just run
>                         that from the command line?
>
>
>                         Even better, can't you use a script instead of a
>         macro?
>                 From a
>                         script
>                         you could already call any method from Weka. You
>         could
>                 do for
>                         example:
>
>
>                         chooser = new GUIChooser();
>
>                         On a Beanshell script (or interpreter) that
>         would open
>                 the Weka
>                         chooser.
>
>
>                                 I am trying to classify multispectral
>         images
>                 using
>                         features
>                                 computed
>                                 with AWS for each band as separate
>         features. I
>                 have
>                         trained a
>                                 classifier
>                                 to use features from all bands, but I
>         need to
>                 apply the
>                                 classifier
>                                 outside AWS as it cannot accept renamed
>         or
>                 unknown
>                         features. You
>                                 can
>                                 find more info on my question on
>         listserv
>
>
>
>
> https://list.nih.gov/cgi-bin/wa.exe?A2=ind1302&L=IMAGEJ&F=&S=&X=4EE85010E69A2EBF8E&Y=lefkaditis%40gmail.com&P=22626
>
>
>
>                         There are some methods in WekaSegmentation.java
>         that you
>                 can use
>                         to
>                         train and test a classifier using custom
>         external
>                 features, for
>                         example:
>
>
>                         To add the data to the WekaSegmentation object
>         (you need
>                 to
>                         create the
>                         FeatureStack before):
>
>                             /**
>                              * Add instances to a specific class from a
>         label
>                 (binary)
>                         image.
>                              * Only white (non black) pixels will be
>         added to
>                 the
>                         corresponding
>                         class.
>                              *
>                              * @param labelImage binary image
>                              * @param featureStack corresponding feature
>         stack
>                              * @param className name of the class which
>         receives
>                 the
>                         instances
>                              * @return false if error
>                              */
>                             public boolean addBinaryData(
>                                     ImagePlus labelImage,
>                                     FeatureStack featureStack,
>                                     String className)
>
>
>                         If you have a specific set of filter kernels
>         that you
>                 want to
>                         use:
>
>
>
>
>                             /**
>                              * Add binary training data from input and
>         label
>                 images.
>                              * The features will be created out of a
>         list of
>                 filters.
>                              * Input and label images can be 2D or
>         stacks and
>                 their
>                              * sizes must match.
>                              *
>                              * @param inputImage input grayscale image
>                              * @param labelImage binary label image
>                              * @param filters stack of filters to create
>                 features
>                              * @param whiteClassName class name for the
>         white
>                 pixels
>                              * @param blackClassName class name for the
>         black
>                 pixels
>                              * @return false if error
>                              */
>                             public boolean addBinaryData(
>                                     ImagePlus inputImage,
>                                     ImagePlus labelImage,
>                                     ImagePlus filters,
>                                     String whiteClassName,
>                                     String blackClassName)
>
>
>
>
>                             /**
>                              * Assign an arbitrary filter stack array
>                              * @param fsa new filter stack array
>                              */
>                             public void
>         setFeatureStackArray(FeatureStackArray
>                 fsa)
>
>
>                         Then you can just train the classifier and
>         finally test
>                 on some
>                         data by
>                         providing again the custom feature stack:
>
>
>                             /**
>                              * Apply current classifier to a given image
>         with
>                         precomputed
>                         features.
>                              *
>                              * @param imp image (2D single image or
>         stack)
>                              * @param fsa precomputed feature stack
>         array
>                              * @param numThreads The number of threads
>         to use.
>                 Set to
>                         zero for
>                         auto-detection.
>                              * @param probabilityMaps create probability
>         maps
>                 for each
>                         class
>                         instead of a classification
>                              * @return result image
>                              */
>                             public ImagePlus applyClassifier(
>                                     final ImagePlus imp,
>                                     FeatureStackArray fsa,
>                                     int numThreads,
>                                     final boolean probabilityMaps)
>
>
>                         Or if you have a specific set of filter kernels:
>
>
>                             /**
>                              * Apply current classifier to a given image
>         with
>                         precomputed
>                         features.
>                              *
>                              * @param imp image (2D single image or
>         stack)
>                              * @param filters stack of filters to apply
>         to the
>                 original
>                         image in
>                         order to create the features
>                              * @param numThreads The number of threads
>         to use.
>                 Set to
>                         zero for
>                         auto-detection.
>                              * @param probabilityMaps create probability
>         maps
>                 for each
>                         class
>                         instead of a classification
>                              * @return result image
>                              */
>                             public ImagePlus applyClassifier(
>                                     final ImagePlus imp,
>
>                                     final ImagePlus filters,
>                                     int numThreads,
>                                     final boolean probabilityMaps)
>
>
>
>
>
>
>
>                                 I have also tried to load and apply and
>                 classifier with
>                                 custom-made
>                                 features to AWS, but it doesn't work,
>         right as I
>                         expected.
>
>
>
>
>                         Have you had a look at this page of the wiki?
>
>
>
>
>         http://fiji.sc/wiki/index.php/Scripting_the_Trainable_Segmentation
>
>                                 Thank you very much in advance,
>
>
>
>
>                         Let me know if this helped!
>
>
>                         ignacio
>
>                                 --
>                                 Dionysios Lefkaditis
>
>                                 Project Engineer
>
>                                 FMTC
>
>                                 www.fmtc.be
>
>                                 Celestijnenlaan 300D
>
>                                 3001 Heverlee
>
>                                 Belgium
>
>                                 Tel: +32-16-328041
>
>                                 GSM: +32-498-919436
>
>                                 Fax: +32 16 32 80 64
>
>                                 Meet JADA, the first badminton robot in
>         the
>                 world!
>                          YouTube -
>                                 FMTCvzw's Channel
>
>
>
>
>
>
>
>                         --
>                         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://biocomp.cnb.csic.es/~iarganda/index_EN.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://biocomp.cnb.csic.es/~iarganda/index_EN.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://biocomp.cnb.csic.es/~iarganda/index_EN.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://biocomp.cnb.csic.es/~iarganda/index_EN.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://bioweb.cnb.csic.es/~iarganda/index_EN.html

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