Include nrrd reader in project

maven
scifio
fiji
Tags: #<Tag:0x00007fd543164890> #<Tag:0x00007fd5431646d8> #<Tag:0x00007fd5431644f8>

#1

Hi

I am in the progress of trying to write a plugin that has to deal with nrrd-files. Last thing I heard, is that scifio does not support this format yet.
So I tried to include the sc.fiji.io stuff to my pom (that has pom-scijava as parent):

<dependency>
	<groupId>sc.fiji</groupId>
	<artifactId>IO_</artifactId>
</dependency>

Buit when launching a ImageJ instance

ImageJ ij = new net.imagej.ImageJ();
ij.ui().showUI();

… I cannot find File > Import > Nrrd in the menu
consequently the following code fails:

ImagePlus ref = new ImagePlus();
IJ.run(ref, "Nrrd ...", path.getAbsolutePath());

What do I have to do to have the nrrd reader available in my project?


#2

huh, weird…

File path = new File("path/to/my/file.nrrd");
ImagePlus ref =IJ.openImage(path.getAbsolutePath());
ref.show();

kinda works
but throws

java.io.IOException: io.scif.img.ImgIOException: io.scif.UnsupportedCompressionException: Unsupported encoding: gzip
	at io.scif.services.DefaultDatasetIOService.open(DefaultDatasetIOService.java:136)
	at io.scif.services.DefaultDatasetIOService.open(DefaultDatasetIOService.java:111)
	at io.scif.io.DatasetIOPlugin.open(DatasetIOPlugin.java:75)
	at io.scif.io.DatasetIOPlugin.open(DatasetIOPlugin.java:50)
	at net.imagej.legacy.plugin.DefaultLegacyOpener.open(DefaultLegacyOpener.java:136)
	at net.imagej.legacy.DefaultLegacyHooks.interceptOpenImage(DefaultLegacyHooks.java:341)
	at ij.IJ.openImage(IJ.java)
	at SectionToVolumeRegistration.main(SectionToVolumeRegistration.java:299)
Caused by: io.scif.img.ImgIOException: io.scif.UnsupportedCompressionException: Unsupported encoding: gzip
	at io.scif.img.ImgOpener.openImgs(ImgOpener.java:385)
	at io.scif.img.ImgOpener.openImgs(ImgOpener.java:268)
	at io.scif.img.ImgOpener.openImgs(ImgOpener.java:145)
	at io.scif.services.DefaultDatasetIOService.open(DefaultDatasetIOService.java:126)
	... 7 more
Caused by: io.scif.UnsupportedCompressionException: Unsupported encoding: gzip
	at io.scif.formats.NRRDFormat$Reader.openPlane(NRRDFormat.java:481)
	at io.scif.formats.NRRDFormat$Reader.openPlane(NRRDFormat.java:422)
	at io.scif.AbstractReader.openPlane(AbstractReader.java:167)
	at io.scif.filters.ChannelFiller.openPlane(ChannelFiller.java:171)
	at io.scif.filters.ChannelFiller.openPlane(ChannelFiller.java:151)
	at io.scif.filters.PlaneSeparator.openPlane(PlaneSeparator.java:305)
	at io.scif.filters.PlaneSeparator.openPlane(PlaneSeparator.java:208)
	at io.scif.filters.AbstractReaderFilter.openPlane(AbstractReaderFilter.java:225)
	at io.scif.filters.AbstractReaderFilter.openPlane(AbstractReaderFilter.java:191)
	at io.scif.img.ImgOpener.read(ImgOpener.java:831)
	at io.scif.img.ImgOpener.read(ImgOpener.java:817)
	at io.scif.img.ImgOpener.read(ImgOpener.java:797)
	at io.scif.img.ImgOpener.readPlanes(ImgOpener.java:784)
	at io.scif.img.ImgOpener.openImgs(ImgOpener.java:382)
	... 10 more

#3

Hi @FelixM,

Do you have imagej-legacy on the classpath, i.e. is it a dependency of your project? NrrdReader and NrrdWriter are ImageJ1 plugins and will thus not be shown in the ImageJ2 user interface (which is the one that should be launched if you don’t have imagej-legacy on the classpath).

There is an NRRD implementation in SCIFIO which can’t handle gzipped image planes. This has nothing todo with the added dependency of sc.fiji:IO_ as far as I can tell.

Best,
Stefan


#4

Hey @stelfrich

thanks for your comments.

yes it has been in the class path.

which explains why

ImagePlus ref =IJ.openImage(path.getAbsolutePath());

… works
But I still cannot find the _Menu > File > Import > Nrrd in the menu though.

The error message I posted previously is consistant with that. Its the same when calling

Object obj = ij.io().open(path.getAbsolutePath());

… whith the difference that the above ij2 command does not yield an image display, but the legacy code IJ.openImage(path.getAbsolutePath()); actually does open an image display despite the error message.

I can work with that. But it leaves me a bit confused.


#5

Me too, but then I realized that those readers in IO_ are IJ1 plugins. Such plugins have to be located in a specific directory of an IJ1 installation (defined by the ij.dir property) since they are loaded from files and not discovered from the classpath (which is done for SciJava Commands :clap:). When executing from Eclipse/Netbeans/etc you’ll have to work around that “feature” by setting the ij.dir property. In practice, take a look at the explanation in the wiki (of course there is information on that… duh): http://imagej.net/Developing_ImageJ_in_Eclipse#Running_and_debugging


#6

Thanks @stelfrich

in the following example the nrrd stuff is accessible during runtime and everything works as expected.

@Plugin(type = Command.class, menuPath = "Plugins > Test")
public class TestPlugin implements Command {

    @Override
    public void run() {
        File path = new File("/path/to/file.nrrd");

        ImagePlus ref = new ImagePlus();
        IJ.run(ref, "Nrrd ...", "load=" + path.getAbsolutePath());
        ref.show();
    }

    public static void main(String[] args) {
        Debug.run("Test", "");
    }
}

Calling the plugin like this takes a long time for ImageJ to start though.

However, is there a way that to get the class loader to include everything in the main() method?


#7

Hmm. I have played around with the following project:

Startup time doesn’t seem to be an issue for me compared to the startup time of standalone Fiji. Maybe a second?

However, depending on the dependencies of your project, start up time might differ significantly. Remember that discovery of Commands and stuff like menu entries are created during runtime. So the complete classpath has to be scanned for potential candidates. What other dependencies do you have in your POM?


#8

many :slight_smile:
clearvolume, bigdataviewer, and many more…