Example for a simple IJ2 / Fiji Plugin

Wonder how to write a IJ2 / Fiji Plugin (Command) that can run nicely from within Eclipse and Fiji or ImageJ2?

There are several answer Google gives you, and most of them go the old IJ (1) way. If you want to use ops or any of the IJ2 services you will appreciate this:

https://github.com/imagej/imagej-tutorials/blob/9baa3bffded39736c0e41cb46ddba7dc15f88260/simple-commands/src/main/java/OpenImage.java#L92-L105

Or this one (which also uses ops to work on images):

https://github.com/imagej/imagej-tutorials/blob/master/simple-commands/src/main/java/OpenScaleSaveImage.java

Using maven to deploy directly to a Fiji installation

This is extremely useful just before you want to upload your plugin(s) to your/a update site. If this really is you use case, you might want to check that the parent POM version you are using coincides with the one of the latest Fiji release!

The command for this is:

mvn -Dimagej.app.directory=/Applications/Fiji.app/ -Ddelete.other.versions=true clean install

And in case the enforcer annoys you — it can be turned off like this:

mvn -Dimagej.app.directory=/Applications/Fiji.app/ -Ddelete.other.versions=true -Denforcer.skip=true clean install

Enjoy,
Florian

Trouble saving KNIME workflow after >3 days without saving?

Recently we ran a very intense training procedure from within a KNIME workflow. The whole thing ran for roughly 4 days.

Finally terminated we ran into troubles saving the workflow, getting some ‘File access problems: /var/folders… etc. etc’ error dialog.

Turns out that Java cleans up its temp folder after 3 days or so (on MacOS at least). In doing so KNIME ended up having the open workflow being corrupted.

Way out: before starting such a monstrous run you might want to configure KNIME to use another temp folder… one that Java does not wipe out every now and then.

  • In KNIME open via menu: KNIME – Preferences
  • Then choose ‘KNIME’ on the left side, and
  • enter a folder name of your choice in the text field with the label ‘Directory for temporary files’.
  • Restart KNIME – done!

Ilastik installation — the easy way using conda!

Sure, go ahead and download the binaries from the elastik.org page. You are done and this page is noise for you.

If, on the other hand, you need to get the latest Ilastik version and some feature you only know about because you are deep into things… then you might njoy this nice page: https://github.com/ilastik/ilastik-build-conda

Interested in tracking?

Once you reach point 2 on that page, use a modified version of  this line:

  • env CPLEX_ROOT_DIR=~/Applications/IBM/ILOG/CPLEX_Studio126 conda install --channel stuarteberg ilastik-deps-tracking

Note: precondition is to have a running version of CPLEX installed on your machine.

If you set your .bashrc correctly, this should now start ilastik for you:

  1. source activate ilastikenv
  2. PYTHONPATH="ilastik:lazyflow:volumina" python ilastik/ilastik.py

Note: Step two above works if you are in the ‘ilastik-meta’ git repository. All libraries dowloaded for the conda environment are below your conda installation folder (in env/ilastikenv).

Hope this does the trick and your ilastik start screen looks somewhat like this:

Ilastik_start_after_conda_success

If CPLEX refuses to work on your machine, here a description for how to get CPLEX running: http://ilastik.org/documentation/basics/installation.html

Does ilastik not show you the tracking workflows after you installed as described above — you might miss the necessary CPLEX dylibs. Here an excerpt of the ilastik installation documentation for how to create them:

First figure which gcc version you use by calling…

gcc --version

and look at the output. This should be either GCC 4.2.1, or Apple LLVM (clang). The folders used to specify the location of the libraries in cases involving clang depend on whether you installed from cplex_studio1251.macos.bin or cplex_studio1251.osx.bin. If you installed the first one, you need to replace x86-64_osx by x86-64_darwin.

  • If the compiler is GCC 4.2.1, use the commands below (in the respective folders where the files are located)
    g++ -fpic -shared -Wl,-all_load libcplex.a -Wl,-noall_load -o libcplex.dylib
    g++ -fpic -shared -Wl,-all_load libilocplex.a -Wl,-noall_load -o libilocplex.dylib
    g++ -fpic -shared -Wl,-all_load libconcert.a -Wl,-noall_load -o libconcert.dylib
    
  • If the compiler is clang and you have OSX version < 10.9, then you need to supply the symbols of cplex and concert when building libilocplex.dylib:
    g++ -fpic -shared -Wl,-all_load libcplex.a -Wl,-noall_load -o libcplex.dylib
    g++ -fpic -shared -Wl,-all_load libconcert.a -Wl,-noall_load -o libconcert.dylib
    g++ -fpic -shared -Wl,-all_load libilocplex.a -Wl,-noall_load -L. -L../../../../concert/lib/x86-64_osx/static_pic -lcplex -lconcert -o libilocplex.dylib
    
  • If the compiler is clang and you have OSX 10.9 Mavericks, then you need to specify the correct C++ standard library to use in addition to the commands above:
    g++ -fpic -shared -Wl,-all_load libcplex.a -Wl,-noall_load -stdlib=libstdc++ -o libcplex.dylib
    g++ -fpic -shared -Wl,-all_load libconcert.a -Wl,-noall_load -stdlib=libstdc++ -o libconcert.dylib
    g++ -fpic -shared -Wl,-all_load libilocplex.a -Wl,-noall_load -L. -L../../../../concert/lib/x86-64_osx/static_pic -lcplex -lconcert -stdlib=libstdc++ -o libilocplex.dylib
    install_name_tool -id @executable_path/../Frameworks/libcplex.dylib libcplex.dylib
    install_name_tool -id @executable_path/../Frameworks/libconcert.dylib libconcert.dylib
    install_name_tool -id @executable_path/../Frameworks/libilocplex.dylib libilocplex.dylib
    install_name_tool -change libcplex.dylib @executable_path/../Frameworks/libcplex.dylib libilocplex.dylib
    install_name_tool -change libconcert.dylib @executable_path/../Frameworks/libconcert.dylib libilocplex.dylib
    

If you replace ‘@executable_path/../Frameworks' by the absolute path (this is in fact required for the whole thing to work with conda) to respective libraries you are guarenteed to

  • get working dylibs, and
  • prevent any reuse in different location... ;) 

otool -L <library-name> can be used to check if your dylib mods where successful.

Change the Fiji temp Folder (by passing JVM arguments)

Why? For example if you run Fiji headless on a cluster and you would like it to use a fast local folder instead of a network drive.

This page tells you how you can pass on JVM arguments to Fiji upon start: http://fiji.sc/Java_Options

One can specify the “temp” directory using the following command:

$ fiji -Djava.io.tmpdir=~/tmp -- &

Double dash at the end is required to specify that the given argument is for Java.

Debugging Fiji/ImageJ App

You can reproduce some misbehavior / bug in Fiji – good! But what next?

You could post your problem on the ImageJ mailing list and hope somebody solves the problem  for you, or you could debug the problem yourself. The page below shows you how you can attach eclipse in debug mode to a running (and failing) Fiji/ImageJ instance. Very cool!

http://fiji.sc/Debugging