[ome-devel] Problems reading/writing calibrations in metadata

Sebastien Besson (Staff) s.besson at dundee.ac.uk
Tue Jun 30 23:11:48 BST 2015


Hi Jean,

At the writing level, the ImageWriter.getWriter() method [1] will select the writer
to use to save the file using the value of the id. If you pass imageTest.tif, it will
return a TiffWriter instance [2] but if you pass imageTest.ome.tif, it will return an
OMETiffWriter instance [3].

If you want to keep imageTest.tif as the filename but want to write the OME-XML,
you could try imposing the writer instance using something like:

IFormatWriter writer = new loci.formats.out.OMETiffWriter();

instead of:

IFormatWriter writer = new loci.formats.ImageWriter();

Best,
Sebastien

[1] http://downloads.openmicroscopy.org/bio-formats/5.1.2/api/loci/formats/ImageWriter.html#getWriter()
[2] http://downloads.openmicroscopy.org/bio-formats/5.1.2/api/loci/formats/out/TiffWriter.html
[3] http://downloads.openmicroscopy.org/bio-formats/5.1.2/api/loci/formats/out/OMETiffWriter.html

On 30 Jun 2015, at 10:20, Jean Ollion <smogollion at yahoo.fr<mailto:smogollion at yahoo.fr>> wrote:

Hello Sebastien,
When I change the format to ome.tif, it works well.
Also for the other problem I mentioned (inversion of number of time points and number of slices)

I also tried to change the format to APNG (.png), and I get the same errors as in .tif (ie the calibration is not readable and the inversion of number of time points and number of slices  )
Does the bug comes from my code or from the bioformats?
Thanks you,
Best,
Jean Ollion

2015-06-29 18:38 GMT+02:00 Jean Ollion <smogollion at yahoo.fr<mailto:smogollion at yahoo.fr>>:
Hello,
I have trouble reading and writing calibration in metadata. Here is a minimal example, written as a JUnit test.

@Rule
    public TemporaryFolder testFolder = new TemporaryFolder();
@org.junit.Test
    public void testIOImageCalibration() {
        String id = testFolder.newFolder("imageTest").getAbsolutePath() + File.separator + "imageTest.tif";
        int w = 512, h = 512, c = 1, z = 1;
        int pixelType = FormatTools.UINT16;
        byte[] img = new byte[w * h * c * FormatTools.getBytesPerPixel(pixelType)];
        for (int i = 0; i < img.length; i++) {
            img[i] = (byte) (256 * Math.random());
        }
        double calX = 0.1d;
        double calZ = 0.23d;
        try {
            ServiceFactory factory = new ServiceFactory();
            OMEXMLService service = factory.getInstance(OMEXMLService.class);
            IMetadata meta = service.createOMEXMLMetadata();
            MetadataTools.populateMetadata(meta, 0, null, false, "XYZCT", FormatTools.getPixelTypeString(pixelType), w, h, z, c, 1, c);
            meta.setPixelsPhysicalSizeX(new Length(calX, UNITS.MICROM), 0);
            meta.setPixelsPhysicalSizeY(new Length(calX, UNITS.MICROM), 0);
            meta.setPixelsPhysicalSizeZ(new Length(calZ, UNITS.MICROM), 0);

            IFormatWriter writer = new loci.formats.ImageWriter();
            writer.setMetadataRetrieve(meta);
            writer.setId(id);
            writer.saveBytes(0, img);
            writer.close();
        } catch (Exception e) {
            fail("problem writing image to disk");
        }

        ImageProcessorReader r = new ImageProcessorReader(new ChannelSeparator(LociPrefs.makeImageReader()));
        IMetadata meta = null;
        try {
            ServiceFactory factory = new ServiceFactory();
            OMEXMLService service = factory.getInstance(OMEXMLService.class);
            try {
                meta = service.createOMEXMLMetadata();
                r.setMetadataStore(meta);
            } catch (ServiceException ex) {
                fail("problem setting metadata");
            }
        } catch (DependencyException ex) {
            fail("problem setting metadata");
        }
        try {
            r.setId(id);
            r.setSeries(0);
            Length lx = meta.getPixelsPhysicalSizeX(0);
            Length lz = meta.getPixelsPhysicalSizeZ(0);
            Assert.assertTrue("testing calibration X is not null?", lx!=null);
            Assert.assertTrue("testing calibration Z is not null?", lz!=null);
            Assert.assertEquals("testing calibration X retrieve", calX, lx.value());
            Assert.assertEquals("testing calibration Z retrieve", calZ, lz.value());
            r.close();
        } catch (FormatException exc) {
            fail("error reading image");
        } catch (IOException exc) {
            fail("error reading image");
        }
    }

It appears the objects "lx" and "lz" are null.
Could you point me the error?

I also have a slide question: here I use the ImageProcessorReader for simplicity, is there a reader that outputs directly one primitive array per plane, in order not to use imageJ's library?
Thank you,
Best,
Jean

_______________________________________________
ome-devel mailing list
ome-devel at lists.openmicroscopy.org.uk<mailto:ome-devel at lists.openmicroscopy.org.uk>
http://lists.openmicroscopy.org.uk/mailman/listinfo/ome-devel


The University of Dundee is a registered Scottish Charity, No: SC015096
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openmicroscopy.org.uk/pipermail/ome-devel/attachments/20150630/dda3155c/attachment.html>


More information about the ome-devel mailing list