ImageJ2 library set up and referencing?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

ImageJ2 library set up and referencing?

Vera Andrejchenko
Dear ImageJ Dev community,

I would like to ask if ImageJ2 can be used as a library for developing stand alone applications, (not only for plugins)?

What I would like to use it is:
- reading, writing, accessing pixel values of multidimensional (multispectral) images,
- FFT, histograms, using the Filters (as they are in the ImageJ app)
- Addition, multiplication etc. of image pixel values as they are in the Image Calculator methods (add, divide, multiply...)

What I tried so far is using the .jars from the ImageJ.app and referenced them as external libraries from my project. But on the very beginning when I try creating the ImageJ object
I keep receiving error messages related to some of the Services, for example:

 java.lang.UnsupportedOperationException: Cannot instantiate more than one DefaultLegacyService at net.imagej.legacy.DefaultLegacyService.checkInstance(DefaultLegacyService.java:514)
and
Invalid service: net.imagej.legacy.DefaultLegacyService
        at org.scijava.service.ServiceHelper.createExactService(ServiceHelper.java:279)

So I was wondering if I can use ImageJ2 as an image processing library for my proejct...

If it is meant to be used as an image processing library which can be referenced from other projects? If yes, could you send me some links I can read how to properly set it up and reference the necessary libraries?

Thanks a lot in advance!

Greetings,
Vera


_______________________________________________
ImageJ-devel mailing list
[hidden email]
http://imagej.net/mailman/listinfo/imagej-devel
Reply | Threaded
Open this post in threaded view
|

Re: ImageJ2 library set up and referencing?

dscho
Administrator
Hi Vera,

On Wed, 6 Aug 2014, Vera Andrejchenko wrote:

> I would like to ask if ImageJ2 can be used as a library for developing
> stand alone applications, (not only for plugins)?

Yes, the idea of ImageJ2 is to future-proof ImageJ for many more use
cases, including writing a new application.

For details, see http://imagej.net/ImageJ2#Features_of_ImageJ2

> What I would like to use it is:
> - reading, writing, accessing pixel values of multidimensional
> (multispectral) images,
> - FFT, histograms, using the Filters (as they are in the ImageJ app)
> - Addition, multiplication etc. of image pixel values as they are in the
> Image Calculator methods (add, divide, multiply...)

It sounds as if you would benefit from the modular structure of ImageJ2:
you can basically cherry-pick which parts you want to use. In particular,
it looks as if you could benefit from ImageJ OPS -- which is still in the
hot phase of development. To get an idea how to make use of ImageJ OPS,
please have a look here: https://github.com/imagej/imagej-ops (scroll down
to the README)

> What I tried so far is using the .jars from the ImageJ.app and referenced
> them as external libraries from my project. But on the very beginning when
> I try creating the ImageJ object I keep receiving error messages related
> to some of the Services, for example:
>
>  java.lang.UnsupportedOperationException: Cannot instantiate more than one
> DefaultLegacyService at net.imagej [...]

The problem you face is caused by *more* than one ImageJ object being
instantiated: every ImageJ object (which we call "gateway" because it is
basically a gateway to all the different services) is connected to a
"SciJava context" that basically offers all the services such as the
plugin service, the event service, the log service, etc

Due to limitations in ImageJ 1.x' design, the legacy service --
responsible for executing any function in ImageJ 1.x -- can be
instantiated only once per class loader. That means that you have to
*dispose* of a SciJava context offering a legacy service *before* you can
instantiate a new context.

> So I was wondering if I can use ImageJ2 as an image processing library
> for my proejct...

Absolutely.

> If it is meant to be used as an image processing library which can be
> referenced from other projects? If yes, could you send me some links I can
> read how to properly set it up and reference the necessary libraries?

The best examples we have live in this source code repository:

        https://github.com/imagej/imagej-tutorials/

I would like to point you in particular to 'load-and-display-dataset' and
'using-ops'.

Ciao,
Johannes

_______________________________________________
ImageJ-devel mailing list
[hidden email]
http://imagej.net/mailman/listinfo/imagej-devel
Reply | Threaded
Open this post in threaded view
|

Re: ImageJ2 library set up and referencing?

dscho
Administrator
Hi Vera,

On Wed, 6 Aug 2014, Johannes Schindelin wrote:

> Due to limitations in ImageJ 1.x' design, the legacy service --
> responsible for executing any function in ImageJ 1.x -- can be
> instantiated only once per class loader. That means that you have to
> *dispose* of a SciJava context offering a legacy service *before* you can
> instantiate a new context.

I completely forgot to mention that the best practice is to instantiate
the ImageJ object *once* and then reuse that instance, rather than
instantiating a new ImageJ object everytime you want to call ImageJ
functionality.

Ciao,
Johannes

_______________________________________________
ImageJ-devel mailing list
[hidden email]
http://imagej.net/mailman/listinfo/imagej-devel
Reply | Threaded
Open this post in threaded view
|

Re: ImageJ2 library set up and referencing?

Jay Warrick
Hi All,

I also wrote this help document for just this purpose. I have not received feedback from the ImageJ2 dev crew on it yet, but this is what I learned and it really helped me. Also, I wrote this before the OPS stuff was added so likely, as I learn this interface too, it should be added as well. Feel free to add to the document as it is a work in progress. It is written using an online collaborative latex editor. But if you don't know latex and want to add a section for a topic I missed, just look at the other sections and try to copy what I have done or just add plain text and I'll format for you later.

Here is the link.

https://www.writelatex.com/756020pphsxc

Cheers,

Jay

On Aug 6, 2014, at 4:51 AM, Johannes Schindelin <[hidden email]> wrote:

> Hi Vera,
>
> On Wed, 6 Aug 2014, Johannes Schindelin wrote:
>
>> Due to limitations in ImageJ 1.x' design, the legacy service --
>> responsible for executing any function in ImageJ 1.x -- can be
>> instantiated only once per class loader. That means that you have to
>> *dispose* of a SciJava context offering a legacy service *before* you can
>> instantiate a new context.
>
> I completely forgot to mention that the best practice is to instantiate
> the ImageJ object *once* and then reuse that instance, rather than
> instantiating a new ImageJ object everytime you want to call ImageJ
> functionality.
>
> Ciao,
> Johannes
>
> _______________________________________________
> ImageJ-devel mailing list
> [hidden email]
> http://imagej.net/mailman/listinfo/imagej-devel


_______________________________________________
ImageJ-devel mailing list
[hidden email]
http://imagej.net/mailman/listinfo/imagej-devel
Reply | Threaded
Open this post in threaded view
|

Re: ImageJ2 library set up and referencing?

Vera Andrejchenko
Dear Johannes and Jay,

thank you both for the reply, links and the latex documentation. 
Yes indeed I did had instantiated ImageJ multiple times..

Now I just tried using one of the tutorial examples: image-tutorials/add-two-datasets

So I created a new maven project, added the pom file from this link:
https://github.com/imagej/imagej-tutorials/blob/master/add-two-datasets/pom.xml
and the java file from:
https://github.com/imagej/imagej-tutorials/blob/master/intro-to-imagej-api/src/main/java/IntroToImageJAPI.java

and tried to run the application, but I got the following error:
java.lang.NoClassDefFoundError: net/imagej/updater/UploaderService

Is there anything I'm missing?

Thank you!

Greetings,
Vera





On Wed, Aug 6, 2014 at 12:41 PM, Jay Warrick <[hidden email]> wrote:
Hi All,

I also wrote this help document for just this purpose. I have not received feedback from the ImageJ2 dev crew on it yet, but this is what I learned and it really helped me. Also, I wrote this before the OPS stuff was added so likely, as I learn this interface too, it should be added as well. Feel free to add to the document as it is a work in progress. It is written using an online collaborative latex editor. But if you don't know latex and want to add a section for a topic I missed, just look at the other sections and try to copy what I have done or just add plain text and I'll format for you later.

Here is the link.

https://www.writelatex.com/756020pphsxc

Cheers,

Jay

On Aug 6, 2014, at 4:51 AM, Johannes Schindelin <[hidden email]> wrote:

> Hi Vera,
>
> On Wed, 6 Aug 2014, Johannes Schindelin wrote:
>
>> Due to limitations in ImageJ 1.x' design, the legacy service --
>> responsible for executing any function in ImageJ 1.x -- can be
>> instantiated only once per class loader. That means that you have to
>> *dispose* of a SciJava context offering a legacy service *before* you can
>> instantiate a new context.
>
> I completely forgot to mention that the best practice is to instantiate
> the ImageJ object *once* and then reuse that instance, rather than
> instantiating a new ImageJ object everytime you want to call ImageJ
> functionality.
>
> Ciao,
> Johannes
>
> _______________________________________________
> ImageJ-devel mailing list
> [hidden email]
> http://imagej.net/mailman/listinfo/imagej-devel




--
----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------
Artificial Intelligence Program at KULeuven, Belgium
grad.ing at The Faculty of Electrical Engineering and Information Technologies
in Skopje,Macedonia
tel: +32 483 439 906
skype:vercence_zvercence
----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------

_______________________________________________
ImageJ-devel mailing list
[hidden email]
http://imagej.net/mailman/listinfo/imagej-devel
Reply | Threaded
Open this post in threaded view
|

Re: ImageJ2 library set up and referencing?

dscho
Administrator
Hi Vera,

On Thu, 7 Aug 2014, Vera Andrejchenko wrote:

> Now I just tried using one of the tutorial examples:
> image-tutorials/add-two-datasets
>
> So I created a new maven project, added the pom file from this link:
> https://github.com/imagej/imagej-tutorials/blob/master/add-two-datasets/pom.xml
> and the java file from:
> https://github.com/imagej/imagej-tutorials/blob/master/intro-to-imagej-api/src/main/java/IntroToImageJAPI.java
>
> and tried to run the application, but I got the following error:
> java.lang.NoClassDefFoundError: net/imagej/updater/UploaderService

Why not just clone the imagej-tutorials project and import the existing
add-two-datasets Maven project via File>Import>Maven>Import Existing Maven
Project...?

Alternatively, feel free to make your project available on GitHub so I can
have a look and possibly point out what needs to be fixed.

Ciao,
Johannes

_______________________________________________
ImageJ-devel mailing list
[hidden email]
http://imagej.net/mailman/listinfo/imagej-devel
Reply | Threaded
Open this post in threaded view
|

Re: ImageJ2 library set up and referencing?

Vera Andrejchenko
Hi Johannes,

sorry for the confusion. I was actually running my other project where the pom.xml file was not properly set up...
I can now run the add-two-datasets example project, thank you!

I should now try to see if its possible to use ImageJ2 and Repast Simpohony - agent based modeling framework together.
Is there maybe a way not to use Maven, but reference all the ImageJ .jars and this way use them in my agent based modeling framework project (without converting my project to Maven project)?

Thank you again!

Greetings,
Vera




On Fri, Aug 8, 2014 at 10:00 AM, Johannes Schindelin <[hidden email]> wrote:
Hi Vera,

On Thu, 7 Aug 2014, Vera Andrejchenko wrote:

> Now I just tried using one of the tutorial examples:
> image-tutorials/add-two-datasets
>
> So I created a new maven project, added the pom file from this link:
> https://github.com/imagej/imagej-tutorials/blob/master/add-two-datasets/pom.xml
> and the java file from:
> https://github.com/imagej/imagej-tutorials/blob/master/intro-to-imagej-api/src/main/java/IntroToImageJAPI.java
>
> and tried to run the application, but I got the following error:
> java.lang.NoClassDefFoundError: net/imagej/updater/UploaderService

Why not just clone the imagej-tutorials project and import the existing
add-two-datasets Maven project via File>Import>Maven>Import Existing Maven
Project...?

Alternatively, feel free to make your project available on GitHub so I can
have a look and possibly point out what needs to be fixed.

Ciao,
Johannes



--
----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------
Artificial Intelligence Program at KULeuven, Belgium
grad.ing at The Faculty of Electrical Engineering and Information Technologies
in Skopje,Macedonia
tel: +32 483 439 906
skype:vercence_zvercence
----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------

_______________________________________________
ImageJ-devel mailing list
[hidden email]
http://imagej.net/mailman/listinfo/imagej-devel