I’m trying to do an average Z-projection of a virtual Stack in ImageJ Jython (For background substraction of big image datasets). Is it possible to cast a Virtual Stack variable to be an ImagePlus type? The following code gives me the error:TypeError: ij.plugin.ZProjector(): 1st arg can’t be coerced to ij.ImagePlus
With vstack being a Virtual Stack of Images
The documentations says I need an ImagePlus type for the ZProjector constructor.
What is strange to me is that I can use ImageJ to Z Project a Virtual Stack to an average Image but the Jython ImageJ API ZProjector doesn’t even accept stacks…
I don’t know if I can mimic exactly what you are trying to do, but
the static method ZProjector.run() works for me if I pass it
an ImagePlus that wraps a virtual stack.
The following jython script works for me:
(Place a copy* of bat-cochlea-renderings.tif – or some other multi-image
.tif – in a know location.)
from ij import IJ
from ij.plugin import ZProjector
imp_vstack = IJ.openVirtual ('<path-to-bat-directory>/bat-cochlea-renderings.tif')
imp_zproj = ZProjector.run (imp_vstack, 'avg')
Here’s the result I get (saved as a .png to make it more browser-friendly):
*How to get bat-cochlea-renderings.tif:
File > Open Samples > Bat Cochlea Renderings (449K) File > Save As > Tiff...
Thank you very much, hope this will help anyone who has to make an average Image out of an Virtual Stack. This should work for most Image data types. (I think IJ.openVirtual is only for tiff format, correct me if I’m wrong)