[ome-devel] Channel Plane Names Set but not Recognised in ImageJ/BioFormats Plugin

Balaji Ramalingam (Staff) b.ramalingam at dundee.ac.uk
Sun Oct 16 11:17:27 BST 2016


Hi,


Thank you for sharing your issue and the code as well.


You have definitely populated the ome-xml appropriately in your code and Bio-Formats does not currently support the inclusion of channel names in the slice labels, of the ImagePlus object.


We have filed a ticket to populate the slice labels of the ImagePlus object appropriately,

https://trac.openmicroscopy.org/ome/ticket/13306


and you have been added to the cc list. You will be notified when there is a status change on this ticket.


As a workaround you could use the following method to populate the global-metadata with an hashmap as follows,

addGlobalMetaList(“Slice 1:”, ChannelName1);

addGlobalMetaList(“Slice 2:”, ChannelName1);

addGlobalMetaList(“Slice 3:”, ChannelName1);

addGlobalMetaList(“Slice 4:”, ChannelName1);


This will be populate the original-metadata table with the hash-map as shown above and will thus be available, when you open the image using the ImageJ importer,


This is definitely not an ideal solution but can be used as a workaround for the time being(if need be).

Hope that helps.


Best,

Balaji


__________________

Mr Balaji Ramalingam

Software Developer

OME Team

School of Life Sciences

University of Dundee

From: ome-devel <ome-devel-bounces at lists.openmicroscopy.org.uk<mailto:ome-devel-bounces at lists.openmicroscopy.org.uk>> on behalf of Michael Ellis <michael.ellis at dsuk.biz<mailto:michael.ellis at dsuk.biz>>
Reply-To: OME External Developer List <ome-devel at lists.openmicroscopy.org.uk<mailto:ome-devel at lists.openmicroscopy.org.uk>>
Date: Thursday, 13 October 2016 at 11:08
To: "ome-devel at lists.openmicroscopy.org.uk<mailto:ome-devel at lists.openmicroscopy.org.uk>" <ome-devel at lists.openmicroscopy.org.uk<mailto:ome-devel at lists.openmicroscopy.org.uk>>
Subject: [ome-devel] Channel Plane Names Set but not Recognised in ImageJ/BioFormats Plugin

Dear ome-devel list.

I am trying to use the bioformats_package.jar in my Java app to save a single image file comprising multiple channels (each channel acquired with a different fluorescence filter set). I am using the setChannelName() and this appears to work insofar as I can see the entry being created in the resulting OME-XML data contained within the the .ome.tif file. However, if I use ImageJ with the BioFormats importer plugin, the multi channel image is loaded and displayed, but the channel names are set not to the names I specify, but “c1/4”, “c:2/4”, “c3/4”, “c:4/4”.

My SSCCE is as follows:

public class BioFormatsTest2 {

    private IMetadata createMetadata(int width, int height, int pixelType, String[] channelNames, Color[] channelColors) {
        IMetadata meta;
        try {
            // create the OME-XML metadata storage object
            ServiceFactory factory = new ServiceFactory();
            OMEXMLService service = factory.getInstance(OMEXMLService.class);
            meta = service.createOMEXMLMetadata();
            meta.createRoot();

            // define each stack of images - this defines a single stack of images
            meta.setImageID("Image:0", 0);
            meta.setPixelsID("Pixels:0", 0);

            // specify that the pixel data is stored in big-endian format
            // change 'TRUE' to 'FALSE' to specify little-endian format
            meta.setPixelsBinDataBigEndian(Boolean.TRUE, 0, 0);

            // specify that the images are stored in ZCT order
            meta.setPixelsDimensionOrder(DimensionOrder.XYCZT, 0);

            // specify that the pixel type of the images
            meta.setPixelsType(
                    PixelType.fromString(FormatTools.getPixelTypeString(pixelType)), 0);

            // specify the dimensions of the images
            meta.setPixelsSizeX(new PositiveInteger(width), 0);
            meta.setPixelsSizeY(new PositiveInteger(height), 0);
            meta.setPixelsSizeZ(new PositiveInteger(1), 0);
            meta.setPixelsSizeC(new PositiveInteger(channelNames.length), 0);
            meta.setPixelsSizeT(new PositiveInteger(1), 0);

            for (int channel = 0; channel < channelNames.length; channel++) {
                meta.setChannelID("Channel:0:" + channel, 0, channel);
                meta.setChannelSamplesPerPixel(new PositiveInteger(1), 0, channel);
                meta.setChannelName(channelNames[channel], 0, channel);
                ome.xml.model.primitives.Color c = new ome.xml.model.primitives.Color(channelColors[channel].getRGB());
                meta.setChannelColor(c, 0, channel);
            }
        } catch (DependencyException | ServiceException | EnumerationException e) {
            System.err.println("Failed to populate OME-XML metadata object.");
            e.printStackTrace();
            meta = null;
        }

        return meta;
    }

    public static void main(String[] args) throws Exception {
        BioFormatsTest2 exporter = new BioFormatsTest2();
        exporter.run();
    }

    public void run() throws IOException, FormatException {
        int width = 256, height = 256;
        int pixelType = FormatTools.UINT8;
        String[] channelNames = {"Dapi", "Fitc", "TxRed", "Aqua"};
        Color[] channelColors = {Color.BLUE, Color.GREEN, Color.RED, Color.CYAN};
        String filePath = "/Users/michaelellis/Documents/Development/SmartCapture4/BioFormat2.ome.tif";

        // Create image data buffer;
        byte[] img = new byte[width * height * FormatTools.getBytesPerPixel(pixelType)];

        try (ImageWriter writer = new ImageWriter()) {
            IMetadata omexml = createMetadata(width, height, pixelType, channelNames, channelColors);
            writer.setMetadataRetrieve(omexml);
            writer.setId(filePath);

            // only save a plane if the file writer was initialized successfully
            for (int planeIndex = 0; planeIndex < channelNames.length; ++planeIndex) {
                // savePlane(planeIndex, width, height, pixelType);
                // byte[] plane = createImage(width, height, pixelType);

                // fill it with random data
                for (int i = 0; i < img.length; i++) {
                    img[i] = (byte) (256 * Math.random());
                }

                writer.saveBytes(planeIndex, img);
            }

        } // Autoclose writer

    }
}

===

The OME-XML in the .ome.tif file is as follows. Note that channel names appear to be Dapi, Fitc, TxRed and Aqua


 <OME UUID="urn:uuid:42b524fd-b842-4052-bf6c-5977c9d06a97" xmlns="http://www.openmicroscopy.org/Schemas/OME/2015-01" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openmicroscopy.org/Schemas/OME/2015-01http://www.openmicroscopy.org/Schemas/OME/2015-01/ome.xsd">
 <Image ID="Image:0">
 <Pixels BigEndian="true" DimensionOrder="XYCZT" ID="Pixels:0" Interleaved="false" SignificantBits="8" SizeC="4" SizeT="1" SizeX="256" SizeY="256" SizeZ="1" Type="uint8">
 <Channel Color="-16776961" ID="Channel:0:0" Name="Dapi" SamplesPerPixel="1">
 <LightPath/>
 <Channel Color="-16711936" ID="Channel:0:1" Name="Fitc" SamplesPerPixel="1">
 <LightPath/>
 <Channel Color="-65536" ID="Channel:0:2" Name="TxRed" SamplesPerPixel="1">
 <LightPath/>
 <Channel Color="-16711681" ID="Channel:0:3" Name="Aqua" SamplesPerPixel="1">
 <LightPath/>
 <TiffData FirstC="0" FirstT="0" FirstZ="0" IFD="0" PlaneCount="1">
 <UUID FileName="BioFormat2.ome.tif">urn:uuid:42b524fd-b842-4052-bf6c-5977c9d06a97</UUID>
 <TiffData FirstC="1" FirstT="0" FirstZ="0" IFD="1" PlaneCount="1">
 <UUID FileName="BioFormat2.ome.tif">urn:uuid:42b524fd-b842-4052-bf6c-5977c9d06a97</UUID>
 <TiffData FirstC="2" FirstT="0" FirstZ="0" IFD="2" PlaneCount="1">
 <UUID FileName="BioFormat2.ome.tif">urn:uuid:42b524fd-b842-4052-bf6c-5977c9d06a97</UUID>
 <TiffData FirstC="3" FirstT="0" FirstZ="0" IFD="3" PlaneCount="1">
 <UUID FileName="BioFormat2.ome.tif">urn:uuid:42b524fd-b842-4052-bf6c-5977c9d06a97</UUID>


After loading the created image with the BioFormats Import plugin into Fiji and running the following script:

  IJ.log("nSlices=" + nSlices);

  for(i = 1; i <= nSlices; i=i+1) {
      setSlice(i);
      name = getInfo("slice.label");
      IJ.log("Slice " + i + ": " + name);
  }

The log output is:

 nSlices=4
 Slice 1: c:1/4
 Slice 2: c:2/4
 Slice 3: c:3/4
 Slice 4: c:4/4

Also, consistent with the script output, the names displayed in the Fiji image window title show the plane names as “c1/4”, “c:2/4”, “c3/4”, “c:4/4”.

What am I doing wrong?
Am I doing something wrong?

Also, I have read the developer documentation at http://www.openmicroscopy.org/site/support/bio-formats5.2/developers/index.html but either I am missing something or there is insufficient explanation for some of the items. For instance in the example http://www.openmicroscopy.org/site/support/bio-formats5.2/_downloads/FileExport.java, where can I find an explanation for the string identifiers used in the following calls:

meta.setImageID("Image:0", 0);
meta.setPixelsID(“Pixels:0", 0);
meta.setChannelID(“Channel:0:0", 0, 0);

Any help gratefully appreciated!

— Michael Ellis





Michael Ellis (Managing Director)
Digital Scientific UK Ltd.
http://www.dsuk.biz
michael.ellis at dsuk.biz<mailto:michael.ellis at dsuk.biz>
tel: +44(0)1223 911215

The Commercial Centre
6 Green End
Cambridge
CB23 7DY


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/20161016/c2fcbc90/attachment.html>


More information about the ome-devel mailing list