[ome-devel] Problems reading/writing calibrations in metadata
Sebastien Besson (Staff)
s.besson at dundee.ac.uk
Mon Jun 29 17:49:09 BST 2015
Hi Jean,
looking quickly at your code snippet, could you try setting the extension to ‘ome.tif’ instead
of plain ‘tif’? This should force Bio-Formats to use the OMETiffWriter and OMETiffReader
when writing and reading your sample file.
Best regards
Sebastien
> On 29 Jun 2015, at 17:38, Jean Ollion <smogollion at yahoo.fr> wrote:
>
> 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
> http://lists.openmicroscopy.org.uk/mailman/listinfo/ome-devel
The University of Dundee is a registered Scottish Charity, No: SC015096
More information about the ome-devel
mailing list