python-bioformats icon indicating copy to clipboard operation
python-bioformats copied to clipboard

Reading Tiles

Open darosio opened this issue 8 years ago • 1 comments

Hi

I am trying to read OME-TIF containg a tiled acquisition (which was composed of 3x3 array of multichannel, multitime images)

following suggestion from https://github.com/CellProfiler/python-bioformats/issues/23 I have crafted the following code:

rdr = javabridge.JClassWrapper('loci.formats.in.OMETiffReader')()
rdr.setOriginalMetadataPopulated(True)

clsOMEXMLService = javabridge.JClassWrapper('loci.formats.services.OMEXMLService')
serviceFactory = javabridge.JClassWrapper('loci.common.services.ServiceFactory')()
service = serviceFactory.getInstance(clsOMEXMLService.klass)

metadata = service.createOMEXMLMetadata()
rdr.setMetadataStore(metadata)

importer_options = javabridge.JClassWrapper('loci.plugins.in.ImporterOptions')
options = importer_options()
options.setStitchTiles(True)
#options.doStitchTiles()

ts = javabridge.JClassWrapper('loci.formats.TileStitcher')(rdr)
#ist = ts.makeTileStitcher(rdr)

rdr.setId(filepath)
ts.getSizeT(), ts.getSizeC(), ts.getSizeY(), ts.getSizeX(), ts.getSizeZ()

with the following output:

(3, 3, 0, 0, 1)

Perhaps, I should use something like:

BF = javabridge.JClassWrapper('loci.plugins.BF')

to actually use the importer options but this miserably failed:

JavaException                             Traceback (most recent call last)
<ipython-input-11-ed48aa6321fe> in <module>()
----> 1 BF = javabridge.JClassWrapper('loci.plugins.BF')

/home/dan/.venvs/nimg/lib/python3.6/site-packages/javabridge/wrappers.py in __init__(self, class_name)
    185         self.static_methods = {}
    186         env = J.get_env()
--> 187         jmethods = env.get_object_array_elements(self.klass.getMethods())
    188         methods = {}
    189         for jmethod in jmethods:

/home/dan/.venvs/nimg/lib/python3.6/site-packages/javabridge/jutil.py in method(self, *args)
    952     def method(self, *args):
    953         assert isinstance(self.o, _javabridge.JB_Object)
--> 954         result = call(self.o, name, sig, *args)
    955         if fn_post_process is not None:
    956             result = fn_post_process(result)

/home/dan/.venvs/nimg/lib/python3.6/site-packages/javabridge/jutil.py in call(o, method_name, sig, *args)
    883     ret_sig = sig[sig.find(')')+1:]
    884     nice_args = get_nice_args(args, args_sig)
--> 885     result = fn(*nice_args)
    886     x = env.exception_occurred()
    887     if x is not None:

/home/dan/.venvs/nimg/lib/python3.6/site-packages/javabridge/jutil.py in fn(*args)
    850             x = env.exception_occurred()
    851             if x is not None:
--> 852                 raise JavaException(x)
    853             return result
    854     else:

JavaException: [Lij/ImagePlus;

What am I missing?

Thank you

daniele

darosio avatar Jun 01 '17 16:06 darosio

Hi @darosio

It looks like you'll need to add ij.jar to the classpath when you start the JVM. You can download the jar from ImageJ. Then, you'd start the JVM like this:

import bioformats
import javabridge


jars = bioformats.JARS + ["/path/to/ij.jar"]

javabridge.start_vm(class_path=jars, run_headless=True)

mcquin avatar Aug 18 '17 14:08 mcquin