Write OME-TIFF using LociExporter from script

Hi guys,

I try to write a python script that does write on OME-TIFF without using any IJ.run methods. So far I got this

from loci.plugins.out import Exporter
from loci.plugins import LociExporter

# open image file and get a specific series
imp, MetaInfo = ImportTools.openfile(r"c:\temp\test.czi")

plugin = LociExporter()
plugin.arg = r"c:\temp\test.ome.tiff"
exporter = Exporter(plugin, imp)
exporter.run()

imp.close()

But I still have several questions or things I cannot figure out …

  • Even the filename is specified the script opens a dialog prompting me to enter a filename to save the image. How do I avoid this?
  • How to I avoid the dialog the write every plane separately?
  • How do I avoid the request for the compression and how do I uncheck the option to export ROIs?

I need to run this completely without any user interaction.

Sebi

Hi Sebi,
did you see this previous post ?

It points to this https://gist.github.com/ctrueden/6282856 that gives some hint of how to use the API. I think the command options.setId(PathToFile) is key.
I guess you want to read the metadata of the original czi file too right ?

Good luck !

Hi Thomas,

yes I did. But this is mainly about reading OME-TIFF and just a few hints on how this might work from a python script. Based on this post I was using so far:

IJ.run(imp, "Bio-Formats Exporter", "save=[" + savepath + "] compression=Uncompressed")

but for whatever reason that code does not work i headless mode. It works fine when used from Fiji directly inside a python script. See my post: Strange Issue with using BioFormats from python script in headless mode only

Sebi

Hi @sebi06, to avoid the dialogs I think what you are looking for is the below:

plugin.arg = r"outfile=/path/to/outfile/test.ome.tiff windowless=true"

The link below is the source code for parsing of the argument with the keys for each option:

This was it. See here for the script I use now: Strange Issue with using BioFormats from python script in headless mode only

The important lines are:

from loci.plugins.out import Exporter
from loci.plugins import LociExporter

paramstring = "outfile=" + savepath + " " + "windowless=true compression=Uncompressed saveROI=false"

# open image file and get a specific series
imp, MetaInfo = ImportTools.openfile(filename)

lociplugin = LociExporter()
lociplugin.arg = paramstring
exporter = Exporter(lociplugin, imp)
exporter.run()