Need help with using BioFormats Exporter from python script

export
ome-tiff
script
python
bio-formats
Tags: #<Tag:0x00007fd5430561b0> #<Tag:0x00007fd543055f30> #<Tag:0x00007fd543055df0> #<Tag:0x00007fd543055c88> #<Tag:0x00007fd543055918>

#1

Hi guys,

inside one of my python scripts I wnat to export an image as OME-TIFF using the BioFormats exporter. I searched and looked aroud for examples and so far I got

def bfexporter(imp, savepath):

	print('Savepath: ', savepath)
	plugin = LociExporter()
	plugin.arg = savepath
	exporter = Exporter(plugin, imp)
	exporter.run() 

	return None

THis works OK, but I still could not find out how to set the options programmatically (save single T, Z, C, ROI, uncompressed etc). I need to run that export completly without any user interaction and therefore I need to set all those option programmatically. Has anyone an exmaple to point me into the right direction?

Sebi


#2

Dear @sebi06,

I fear you will have to do some manual labor to get that working. Something like

bufferedImage = imp.getBufferedImage();
w = BufferedImageWriter();
w.setXXX(); # something like setCompression(), setCodecOptions()
w.saveImage(0, bufferedImage); # replace 0 with the image number

I’d be happy to learn a better way (since that’s how I have done it recently)…

Best,
Stefan


#3

Hi Stefan,

thanks for the hint. I will try that soon. Right now use workaround, which seems to be ok for now.

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

But I not sure if that approach is really a good idea. or what is your take on that?

Sebastian


#4

I think using IJ.run to call the “Bio-Formats Exporter” is probably your easiest option. I put a lot of effort into coding a high-level-but-configurable opener API via the BF utility class, ImporterOptions, etc., but never put similar effort into an analogous saver API. Hence, in general, Bio-Formats export features are less thorough than import features.


#5

Hi Curtis,

thanks for the answer. That makes sense. So for now my workflow is fine. And if time allows I will try to dig deeper.

Sebastian