Python's exportOmeTiff and ROI's
Posted: Wed Jul 27, 2016 12:32 am
Hi,
I had trouble opening an exported OME-TIFF into ImageJ, specifically this error:
It looks like exportOmeTiff sets the "Points" attributes of "Polygon" elements in the XML to something like:
and bioformats is expecting something like
Here's a relevant part of the upload script I used: view
Here's the uploaded image in OMERO's viewer: view
Here's the broken exported OME-TIFF: download
And here's the working version with fixed Points attributes: download
(Bonus: the python script used to fix the broken image (requires "$ sudo pip install lxml tifffile"; does not preserve tags other than the ome xml):
I had trouble opening an exported OME-TIFF into ImageJ, specifically this error:
- Code: Select all
java.lang.NumberFormatException: For input string: "points[694"
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1222)
at java.lang.Double.parseDouble(Double.java:510)
at loci.plugins.util.ROIHandler.parsePoints(ROIHandler.java:927)
at loci.plugins.util.ROIHandler.openROIs(ROIHandler.java:250)
at loci.plugins.in.DisplayHandler.displayROIs(DisplayHandler.java:214)
at loci.plugins.in.Importer.run(Importer.java:92)
at loci.plugins.LociImporter.run(LociImporter.java:78)
at ij.IJ.runUserPlugIn(IJ.java:216)
at ij.IJ.runPlugIn(IJ.java:180)
at ij.Executer.runCommand(Executer.java:137)
at ij.Executer.run(Executer.java:66)
at java.lang.Thread.run(Thread.java:695)
It looks like exportOmeTiff sets the "Points" attributes of "Polygon" elements in the XML to something like:
points[694,88 695,88 695,89 695,90 696,91 697,91 698,90 ...] points1[694,88 695,88 695,89 695,90 696,91 697,91 698,90 ...] points2[694,88 695,88 695,89 695,90 696,91 697,91 698,90 ...] mask[0,0,0...0]
and bioformats is expecting something like
694,88 695,88 695,89 695,90 696,91 697,91 698,90 ...
Here's a relevant part of the upload script I used: view
Here's the uploaded image in OMERO's viewer: view
Here's the broken exported OME-TIFF: download
And here's the working version with fixed Points attributes: download
(Bonus: the python script used to fix the broken image (requires "$ sudo pip install lxml tifffile"; does not preserve tags other than the ome xml):
- Code: Select all
import lxml.etree
import tifffile
IMAGE_PATH = "path/to/broken.tiff"
with tifffile.TiffFile(IMAGE_PATH) as tif:
data = tif.asarray()
page_0 = tif.pages[0]
ome_xml_string = page_0.tags['image_description'].value
ome_xml = lxml.etree.fromstring(ome_xml_string)
all_polygons = ome_xml.findall(".//{*}Polygon")
for polygon in all_polygons:
points = polygon.get("Points")
i = points.find("[")
j = points.find("]")
new_points = points[i+1:j]
polygon.set("Points", new_points)
new_s = lxml.etree.tostring(ome_xml, encoding="UTF-8", xml_declaration=True)
tifffile.imsave("out.tiff", data, description=new_s)