Help! How can I save an ArrayImg object into TIFF file?

save
tiff
imagej2
Tags: #<Tag:0x00007fb87e4b9d88> #<Tag:0x00007fb87e4b9bd0> #<Tag:0x00007fb87e4b9978>

#1

I have a net.imglib2.img.array.ArrayImg object of a 5-D image.

I’d like to save this image as a TIFF file via ImageJ2 API, but could not find a way to do it.

I realized that although net.imglib2.img.display.imagej.ImageJFunctions.show(img); can open the image in ImageJ, that image cannot be reached from ImageJ GUI.

The closest I found is a static method ImgLib.save()

However, net.imglib2.script.ImgLib.save(img,"filename.tif")); did not work, and I’m wondering why.

Undefined variable "net" or class "net.imglib2.script.ImgLib". 

Because net.imglib2.img.display.imagej.ImageJFunctions.show(img); works, the path should be accessible.

Any ideas?


#2

Hi @kouichi-c-nakamura,

I’m surprised that what you tried gave that error, but I’m not familiar with the ImgLib class…

One way is to use ImageJFunctions (which you know about) to turn your ArrayImg into an ImagePlus and then use IJ in the ImageJ1 kind of way.

See here for some tricks and possible issues

If you’re using ImageJ2 Parameter annotations, then it’ll be something like

#@IOService ioService
...
ioService.save( myArrayImgObject, "my file path")

or something like:

ij = new ImageJ()
ij.io().save( ...) 

Hope one of these is what you’re looking for,
John


#3

Regarding net.imglib2.script.ImgLib it really isn’t distributed with Fiji, so that explains the error.
It is very old though, so better to stick with ImageJFunctions and the ImageJ2 stuff.

Now the mystery is why it’s in the javadoc… :confused:

John


#4

Thank you for the very helpful comments. I’ll look into it.

This worked for me.

imp = net.imglib2.img.display.imagej.ImageJFunctions.show(img)
ij.IJ.saveAsTiff(imp,'hoo.tif');