Imagej Jython Z-Projection for Virtual Stack

Hi,
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

from ij.plugin import ZProjector

zp = ZProjector(vstack)
zp.run(vstack, “avg”)
zp.setMethod(ZProjector.AVG_METHOD)
zp.doProjection()
averageImage = zp.getProjection()

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…

Hello Teedo -

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_vstack.show()
imp_zproj = ZProjector.run (imp_vstack, 'avg')
imp_zproj.show()

Here’s the result I get (saved as a .png to make it more browser-friendly):

AVG_bat-cochlea-renderings.png

AVG_bat-cochlea-renderings

*How to get bat-cochlea-renderings.tif:

File > Open Samples > Bat Cochlea Renderings (449K)
File > Save As > Tiff...

Or download bat-cochlea-renderings.zip, and extract the .tif file.

Thanks, mm

Thank you very much for your fast response. You brought me to the right conclusion, that my stack was at fault although I could view it. My working code is now as follows:

# @File(label = "Input directory", style = "directory") srcFile

from ij.plugin import ZProjector, FolderOpener

def makeAverageMask():
  srcDir = srcFile.getAbsolutePath()
  vstack = FolderOpener.open(srcDir, "virtual");
  #vstack.show()
  averageImage = ZProjector.run(vstack,"avg");
  IJ.run(averageImage, "Convert to Mask", "method=Otsu background=Light")
  #averageImage.show()
  #Return Average
  return averageImage

averageImageBinary = makeAverageMask()

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)