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

Jean Ollion smogollion at yahoo.fr
Tue Jun 30 10:20:09 BST 2015


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>:

> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openmicroscopy.org.uk/pipermail/ome-devel/attachments/20150630/df5545ac/attachment.html>


More information about the ome-devel mailing list