imagej scripting using kawa - can't use plugins

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

imagej scripting using kawa - can't use plugins

David Pirotte
Hello,

        Scripting using higher level languages such as Kawa [an/or Clojure], I
        can't make things happen so that I can use plugins

        I am using Kawa (1) but please note that what is described in this report
        also fails using clojure, since the problem is 'with/within' the ImageJ 'eco
        system' itself (2), not 'with/within' these higher level languages.


1] Short story:

        No matter what higher level programing language I use, I am unable to use any
        plugins, neither using Kawa nor using Clojure.

I generally can do most, but not everything, of what is defined in the imagej core
jar (3)  - but nothing that is defined in plugins.

A quick look at the imagej launcher code [note that my java knowledge is close to
zero], and it appears that, indeed, an impressive bit of magic occurs at launching
time:

        I wonder if someone else did solve this problem [even if for clojure] and
        would be happy to share the solution with me?


2] Example - "Non-local Means Denoising" (4)

        Attached: nlm-small.png a small image to test

        Code: ij-core.scm a kawa scheme very short snipset
        ( here  -> ) http://paste.lisp.org/+3CB7

        [ see at the end of ij-core.scm for a session example if would like to try
        [ it, in which case you need kawa of course, then you would compile the
        [ ij-core.scm file like this:

        [ kawa -C ij-core.scm
        [ -> ij$Mncore.class

My directory setting is:

        ~/lpdi/projects/kawa
                images/
                        nlm-small.png
                jars/
                        ij-1.49v.jar
                        ij.jar -> ij-1.49v.jar
                        NL_Means_1_3.jar
                        nl-mean.jar -> NL_Means_1_3.jar
                ij-core.scm
                ij$Mncore.class

Then cd to this location and here a trace of  a simple session:

        export CLASSPATH=.:./jars/ij.jar:./jars/nl-mean.jar
        kawa
        (import (ij-core))
        (define iplus1 (ij-open "nlm-small.png"))
        (ij-show iplus1)
  (ij-run iplus1 "Non-local Means Denoising" "sigma=3")
        ->
                Unrecognized command: "Non-local Means Denoising"
                #!null

But Kawa sees the classes, here:

        (module-classes "jars/nl-mean.jar")
        ->
                jars/nl-mean.jar:
                META-INF/
                META-INF/MANIFEST.MF
                de/
                de/biomedical_imaging/
                de/biomedical_imaging/ij/
                de/biomedical_imaging/ij/nlMeansPlugin/
                de/biomedical_imaging/ij/nlMeansPlugin/FastMathStuff.class
                de/biomedical_imaging/ij/nlMeansPlugin/NLMeansDenoising_$WorkerDouble.class
                de/biomedical_imaging/ij/nlMeansPlugin/NLMeansDenoising_$WorkerInt.class
                de/biomedical_imaging/ij/nlMeansPlugin/NLMeansDenoising_.class
                plugins.config

        Plugins.config
        ...
        Plugins, "Non-local Means Denoising", de.biomedical_imaging.ij.nlMeansPlugin.NLMeansDenoising_

Thanks for some usefull hint(s),
Cheers,
David


(1) menu driven, parameterized strings arguments
(2) https://www.gnu.org/software/kawa/
(3) I'm currently using ij149v.jar
(4) https://github.com/thorstenwagner/ij-nl-means



















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

nlm-small.png (99K) Download Attachment
attachment1 (484 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: imagej scripting using kawa - can't use plugins

ctrueden
Hi David,

> No matter what higher level programing language I use, I am unable to
> use any plugins, neither using Kawa nor using Clojure.

Some ideas:

1) Try setting the plugins.dir system property to specify your ImageJ
plugins folder [1].

2) Run your Clojure scripts from within ImageJ using the Script Editor [2],
or from the CLI using the ImageJ launcher [3].

3) Try putting all plugin JARs individually on your classpath.

Regards,
Curtis

[1] http://imagej.net/Plugins#Configuring_where_ImageJ_looks_for_plugins
[2] http://imagej.net/Script_Editor
[3] http://imagej.net/Launcher

On Tue, Sep 29, 2015 at 1:37 AM, David Pirotte <[hidden email]> wrote:

> Hello,
>
>         Scripting using higher level languages such as Kawa [an/or
> Clojure], I
>         can't make things happen so that I can use plugins
>
>         I am using Kawa (1) but please note that what is described in this
> report
>         also fails using clojure, since the problem is 'with/within' the
> ImageJ 'eco
>         system' itself (2), not 'with/within' these higher level languages.
>
>
> 1]      Short story:
>
>         No matter what higher level programing language I use, I am unable
> to use any
>         plugins, neither using Kawa nor using Clojure.
>
> I generally can do most, but not everything, of what is defined in the
> imagej core
> jar (3)  - but nothing that is defined in plugins.
>
> A quick look at the imagej launcher code [note that my java knowledge is
> close to
> zero], and it appears that, indeed, an impressive bit of magic occurs at
> launching
> time:
>
>         I wonder if someone else did solve this problem [even if for
> clojure] and
>         would be happy to share the solution with me?
>
>
> 2]      Example - "Non-local Means Denoising" (4)
>
>         Attached:       nlm-small.png           a small image to test
>
>         Code:           ij-core.scm             a kawa scheme very short
> snipset
>         ( here  -> )    http://paste.lisp.org/+3CB7
>
>         [ see at the end of ij-core.scm for a session example if would
> like to try
>         [ it, in which case you need kawa of course, then you would
> compile the
>         [ ij-core.scm file like this:
>
>         [               kawa -C ij-core.scm
>         [               -> ij$Mncore.class
>
> My directory setting is:
>
>         ~/lpdi/projects/kawa
>                 images/
>                         nlm-small.png
>                 jars/
>                         ij-1.49v.jar
>                         ij.jar -> ij-1.49v.jar
>                         NL_Means_1_3.jar
>                         nl-mean.jar -> NL_Means_1_3.jar
>                 ij-core.scm
>                 ij$Mncore.class
>
> Then cd to this location and here a trace of  a simple session:
>
>         export CLASSPATH=.:./jars/ij.jar:./jars/nl-mean.jar
>         kawa
>         (import (ij-core))
>         (define iplus1 (ij-open "nlm-small.png"))
>         (ij-show iplus1)
>         (ij-run iplus1 "Non-local Means Denoising" "sigma=3")
>         ->
>                 Unrecognized command: "Non-local Means Denoising"
>                 #!null
>
> But Kawa sees the classes, here:
>
>         (module-classes "jars/nl-mean.jar")
>         ->
>                 jars/nl-mean.jar:
>                 META-INF/
>                 META-INF/MANIFEST.MF
>                 de/
>                 de/biomedical_imaging/
>                 de/biomedical_imaging/ij/
>                 de/biomedical_imaging/ij/nlMeansPlugin/
>                 de/biomedical_imaging/ij/nlMeansPlugin/FastMathStuff.class
>
> de/biomedical_imaging/ij/nlMeansPlugin/NLMeansDenoising_$WorkerDouble.class
>
> de/biomedical_imaging/ij/nlMeansPlugin/NLMeansDenoising_$WorkerInt.class
>
> de/biomedical_imaging/ij/nlMeansPlugin/NLMeansDenoising_.class
>                 plugins.config
>
>         Plugins.config
>         ...
>         Plugins, "Non-local Means Denoising",
> de.biomedical_imaging.ij.nlMeansPlugin.NLMeansDenoising_
>
> Thanks for some usefull hint(s),
> Cheers,
> David
>
>
> (1)     menu driven, parameterized strings arguments
> (2)     https://www.gnu.org/software/kawa/
> (3)     I'm currently using ij149v.jar
> (4)     https://github.com/thorstenwagner/ij-nl-means
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: imagej scripting using kawa - can't use plugins

Kyle Harrington
Hi David,

I¹m regularly using Clojure with existing ImageJ/FIJI plugins. We have a
package that allows you to use ImageJ/FIJI functions from Clojure in a
standalone mode (I.e. You can run your scripts as independent Clojure
projects instead of within Clojure): https://github.com/funimage/funimage
. It provides type-hinted wrappers to a large number of ImageJ functions,
some imglib2 functions, and a few extra ones. I admit that the code is
currently a bit messy, but there will be some example documentation
getting posted in conjunction with the BioImage Informatics meeting next
month. Until then, feel free to contact me offline if you have specific
Clojure issues.

If you want to do it yourself, I bootstrapped using the same suggestions
Curtis made. First (2), as FIJI should be managing the classpath for you
already. To get things working a standalone way, both (1) and (2) were
necessary to make an Clojure project that could call IJ functions which
relied on plugins (like ij.IJ/run).

Cheers,
Kyle


--
Kyle I S Harrington, PhD
Postdoctoral Fellow
Bentley Group, Computational Biology Lab
Center for Vascular Biology Research,
Beth Israel Deaconess Medical Center
Harvard Medical School, Boston, MA
web: http://www.kyleharrington.com




On 9/29/15, 9:41 AM, "Curtis Rueden" <[hidden email]> wrote:

>Hi David,
>
>> No matter what higher level programing language I use, I am unable to
>> use any plugins, neither using Kawa nor using Clojure.
>
>Some ideas:
>
>1) Try setting the plugins.dir system property to specify your ImageJ
>plugins folder [1].
>
>2) Run your Clojure scripts from within ImageJ using the Script Editor
>[2],
>or from the CLI using the ImageJ launcher [3].
>
>3) Try putting all plugin JARs individually on your classpath.
>
>Regards,
>Curtis
>
>[1] http://imagej.net/Plugins#Configuring_where_ImageJ_looks_for_plugins
>[2] http://imagej.net/Script_Editor
>[3] http://imagej.net/Launcher
>
>On Tue, Sep 29, 2015 at 1:37 AM, David Pirotte <[hidden email]> wrote:
>
>> Hello,
>>
>>         Scripting using higher level languages such as Kawa [an/or
>> Clojure], I
>>         can't make things happen so that I can use plugins
>>
>>         I am using Kawa (1) but please note that what is described in
>>this
>> report
>>         also fails using clojure, since the problem is 'with/within' the
>> ImageJ 'eco
>>         system' itself (2), not 'with/within' these higher level
>>languages.
>>
>>
>> 1]      Short story:
>>
>>         No matter what higher level programing language I use, I am
>>unable
>> to use any
>>         plugins, neither using Kawa nor using Clojure.
>>
>> I generally can do most, but not everything, of what is defined in the
>> imagej core
>> jar (3)  - but nothing that is defined in plugins.
>>
>> A quick look at the imagej launcher code [note that my java knowledge is
>> close to
>> zero], and it appears that, indeed, an impressive bit of magic occurs at
>> launching
>> time:
>>
>>         I wonder if someone else did solve this problem [even if for
>> clojure] and
>>         would be happy to share the solution with me?
>>
>>
>> 2]      Example - "Non-local Means Denoising" (4)
>>
>>         Attached:       nlm-small.png           a small image to test
>>
>>         Code:           ij-core.scm             a kawa scheme very short
>> snipset
>>         ( here  -> )    http://paste.lisp.org/+3CB7
>>
>>         [ see at the end of ij-core.scm for a session example if would
>> like to try
>>         [ it, in which case you need kawa of course, then you would
>> compile the
>>         [ ij-core.scm file like this:
>>
>>         [               kawa -C ij-core.scm
>>         [               -> ij$Mncore.class
>>
>> My directory setting is:
>>
>>         ~/lpdi/projects/kawa
>>                 images/
>>                         nlm-small.png
>>                 jars/
>>                         ij-1.49v.jar
>>                         ij.jar -> ij-1.49v.jar
>>                         NL_Means_1_3.jar
>>                         nl-mean.jar -> NL_Means_1_3.jar
>>                 ij-core.scm
>>                 ij$Mncore.class
>>
>> Then cd to this location and here a trace of  a simple session:
>>
>>         export CLASSPATH=.:./jars/ij.jar:./jars/nl-mean.jar
>>         kawa
>>         (import (ij-core))
>>         (define iplus1 (ij-open "nlm-small.png"))
>>         (ij-show iplus1)
>>         (ij-run iplus1 "Non-local Means Denoising" "sigma=3")
>>         ->
>>                 Unrecognized command: "Non-local Means Denoising"
>>                 #!null
>>
>> But Kawa sees the classes, here:
>>
>>         (module-classes "jars/nl-mean.jar")
>>         ->
>>                 jars/nl-mean.jar:
>>                 META-INF/
>>                 META-INF/MANIFEST.MF
>>                 de/
>>                 de/biomedical_imaging/
>>                 de/biomedical_imaging/ij/
>>                 de/biomedical_imaging/ij/nlMeansPlugin/
>>
>>de/biomedical_imaging/ij/nlMeansPlugin/FastMathStuff.class
>>
>>
>>de/biomedical_imaging/ij/nlMeansPlugin/NLMeansDenoising_$WorkerDouble.cla
>>ss
>>
>> de/biomedical_imaging/ij/nlMeansPlugin/NLMeansDenoising_$WorkerInt.class
>>
>> de/biomedical_imaging/ij/nlMeansPlugin/NLMeansDenoising_.class
>>                 plugins.config
>>
>>         Plugins.config
>>         ...
>>         Plugins, "Non-local Means Denoising",
>> de.biomedical_imaging.ij.nlMeansPlugin.NLMeansDenoising_
>>
>> Thanks for some usefull hint(s),
>> Cheers,
>> David
>>
>>
>> (1)     menu driven, parameterized strings arguments
>> (2)     https://www.gnu.org/software/kawa/
>> (3)     I'm currently using ij149v.jar
>> (4)     https://github.com/thorstenwagner/ij-nl-means
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>
>
>--
>ImageJ mailing list: http://imagej.nih.gov/ij/list.html


________________________________

This message is intended for the use of the person(s) to whom it may be addressed. It may contain information that is privileged, confidential, or otherwise protected from disclosure under applicable law. If you are not the intended recipient, any dissemination, distribution, copying, or use of this information is prohibited. If you have received this message in error, please permanently delete it and immediately notify the sender. Thank you.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: imagej scripting using kawa - can't use plugins

David Pirotte
Hi Kyle,
Curtis,

        thanks both, sorry for the delay, I had to jump on another project and
        experiment a bit with the proposed solutions as well...


A] NL Mean works!

Using the directory setting and ij-core.scm -> ij$Mncore.class mentioned in my
previous emal, plus this define in ij-nl-mean.scm [kawa -C  ij-nl-mean.scm ->
ij$Mnnl$Mnmean.class]:

        (define (ij-nl-mean iplus1 sigma)
          (ij-run iplus1
                  "Non-local Means Denoising"
                  (string-append "sigma="
                                 (number->string sigma))))

then the nl-mean kawa script does work [1]



B] "Linear Stack Alignment with SIFT" does not work

                Note: the images we use are too big to send them here, but who might
                help probably knows the mpicbg source code and has images to
                test locally ...

        ~/lpdi/projects/kawa
                jars/
                        ij-1.49v.jar
                        ij.jar -> ij-1.49v.jar
                        mpicbg_-1.0.2.jar
                        mpicbg.jar -> mpicbg_-1.0.2.jar
                ij-core.scm
                ij$Mncore.class

Session example:

david@capac:~/lpdi/projects/kawa 67 $ export CLASSPATH=.:./jars/ij.jar:./jars/mpicbg.jar
david@capac:~/lpdi/projects/kawa 68 $ kawa -Dplugins.dir=./jars
#|kawa:1|# (import (ij-core))
#|kawa:2|# (define iplus1 (ij-open "/usr/lpdi/projects/tests/mfer/vale/dipe/mosaic1/bf.png"))
#|kawa:3|# (define iplus2 (ij-open "/usr/lpdi/projects/tests/mfer/vale/dipe/mosaic1/cpol.png"))
#|kawa:4|# (ij-show iplus1)
#|kawa:6|# (ij-show iplus2)
#|kawa:7|# (ij-run "Images to Stack" "method=[Copy (center)] name=Stack title=[] use")
#|kawa:9|#   (ij-run "Linear Stack Alignment with SIFT" "initial_gaussian_blur=1.60 steps_per_scale_octave=3 minimum_image_size=64 maximum_image_size=1024 feature_descriptor_size=4 feature_descriptor_orientation_bins=8 closest/next_closest_ratio=0.92 maximal_alignment_error=25 inlier_ratio=0.05 expected_transformation=Translation interpolate")

->
        Class not found while attempting to run "SIFT_Align"
           java.lang.NoClassDefFoundError: mpicbg/models/TranslationModel2D

        Indeed, it is not in mpcibg

What other plugin/jar should I add to my CLASSPATH to make this work?

Thanks,
David


[1] nl-mean kawa script

#!/bin/sh
# -*- mode: scheme; coding: utf-8 -*-
export CLASSPATH=\
/usr/lpdi/projects/kawa:\
/usr/lpdi/projects/kawa/jars/ij.jar:\
/usr/lpdi/projects/kawa/jars/nl-mean.jar
exec kawa -Dplugins.dir=/usr/lpdi/projects/kawa/jars --script8 "$0" "$@"
!#

;;;;
;;;; Copyright (C) 2015
;;;; David Pirotte <david at altosw dot be>

;;;; This module is part of a set of image processing modules and
;;;; scripts written using Kawa and ImageJ.

;;;; This module is free software: you can redistribute it and/or modify
;;;; it under the terms of the GNU General Public License as published
;;;; by the Free Software Foundation, either version 3 of the License,
;;;; or (at your option) any later version.

;;;; It is distributed in the hope that it will be useful, but WITHOUT
;;;; ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;;;; General Public License for more details.

;;;; You should have received a copy of the GNU General Public License
;;;; along with this s/w.  If not, see <http://www.gnu.org/licenses/>.
;;;;

;;; Commentary:

;;; Code:


(import (utils)
        (ij-core)
        (ij-nl-mean))


(let* ((cmd (command-line))
       (dir (list-ref cmd 1))
       (im-name (list-ref cmd 2))
       (im-type (list-ref cmd 3))
       (im-out (list-ref cmd 4))
       (sigma (string->number (list-ref cmd 5)))
       (im-filename (string-append dir "/" im-name "." im-type))
       (iplus (ij-open im-filename)))
  (ij-nl-mean iplus sigma)
  (ij-save iplus
           (string-append dir "/" im-out "." im-type))
  (exit))


#|

 ./nl-mean . images/nlm-small png images/nlm-out 30

|#

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

attachment0 (484 bytes) Download Attachment