We're Hiring!

Python's exportOmeTiff and ROI's

General and open developer discussion about using OMERO APIs from C++, Java, Python, Matlab and more! Please new questions at https://forum.image.sc/tags/omero
Please note:
Historical discussions about OMERO. Please look for and ask new questions at https://forum.image.sc/tags/omero

If you are having trouble with custom code, please provide a link to a public repository, ideally GitHub.

Python's exportOmeTiff and ROI's

Postby markmendell » Wed Jul 27, 2016 12:32 am

Hi,

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)
)
markmendell
 
Posts: 2
Joined: Thu Apr 14, 2016 7:01 am

Re: Python's exportOmeTiff and ROI's

Postby dgault » Wed Jul 27, 2016 1:20 pm

Hi Mark,

Thanks for spotting and reporting this issue as well investigating the problem. This was indeed a bug and as per the OME XML specification the correct points data should be a list of comma separated x,y coordinates seperated by spaces like "x1,y1 x2,y2 x3,y3"

A fix to export the data in the correct format has actually just been implemented recently so should be coming soon to future Omero release.

David
User avatar
dgault
Team Member
 
Posts: 208
Joined: Fri Aug 14, 2015 2:56 pm


Return to Developer Discussion

Who is online

Users browsing this forum: No registered users and 0 guests