> Hi,
>
> I am writing a python macro which iterate over all rois in ROI Manager
> and then use setCropRegion function from bioformat plugin to open a
> cropped region of an image.
>
> Now I would like to save this cropped image to OME Tiff but I don’t
> know how to do that… should I use IJ I/O, SCIFIO, BF plugin ?
>
> I am using an updated version of Fiji.
>
> Here is my macro.
>
> from ij.plugin.frame import RoiManager
> from ij import ImageStack
> from ij import ImagePlus
> from ij import IJ
> from ij.io import FileSaver
>
> from loci.plugins import BF
> from loci.plugins.in import ImporterOptions
> from loci.common import Region
> from loci.plugins import LociExporter
> from loci.plugins.out import Exporter
>
> import os
>
> base_dir = "/data/"
> fname = os.path.join(base_dir, "path_to_tif.ome.tif")
>
> for i, roi in enumerate(RoiManager.getInstance().getRoisAsArray()):
> bounds = roi.getBounds()
>
> x = bounds.x
> y = bounds.y
> w = bounds.width
> h = bounds.height
>
> options = ImporterOptions()
> options.setCrop(True)
> options.setCropRegion(0, Region(x, y, w, h))
> options.setId(fname)
> imps = BF.openImagePlus(options)
>
> imp = imps[0]
> #imp.show()
>
> #fs = FileSaver(imp)
> #fs.saveAsTiff("/home/hadim/test.ome.tif")
> #IJ.saveAs(imp, "ome.tif", "/home/hadim/test.ome.tif")
> plugin = LociExporter()
> plugin.arg = "outfile=/home/hadim/test.ome.tif"
> exporter = Exporter(plugin, imp)
> exporter.run()
>
> print('Done')
>
> Bonus question : I am currently using
> RoiManager.getInstance().getRoisAsArray() to retrieve all rois. How
> can I directly get a ROIManager instance from RoiSet.zip file ?
>
> Thank you for all !
>
> --
> Hadrien Mary
>
> Ph.D student in Biology
> Tournier-Gachet Team
> CNRS - LBCMCP - UMR 5088
>
> Université de Toulouse - Bât. 4R3B1
> 118, route de Narbonne - 31062 Toulouse
>
> --
> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html>