ome / bioformats

Bio-Formats is a Java library for reading and writing data in life sciences image file formats. It is developed by the Open Microscopy Environment. Bio-Formats is released under the GNU General Public License (GPL); commercial licenses are available from Glencoe Software.
https://www.openmicroscopy.org/bio-formats
GNU General Public License v2.0
371 stars 241 forks source link

bfconvert: Using channel option does not remove additional channel elements from OME-XML #4149

Closed dgault closed 2 months ago

dgault commented 5 months ago

Issue was reported on forum thread https://forum.image.sc/t/extracting-a-single-channel-using-bfconvert/91632

The original error was reported when trying to read using AICSImage resulted in the error:

ValueError: conflicting sizes for dimension 'C': length 1 on the data but length 2 on coordinate 'C'

The issue can be reproduced with command line tools from BF 7.1.0 and using sample file from https://github.com/NEUBIAS/training-resources/blob/2145f31cd46b81fc24f31cad4de1ca30ccaf24f6/image_data/xyc_8bit__membranes_nuclei.tif

Running the below command then generates an OME-TIFF which contains 2 channel elements in the OME-XML:

bfconvert -channel 1 xyc_8bit__membranes_nuclei.tif xyc_8bit__membranes_nuclei.ome.tiff

Note that this is not apparent when using showinf -omexml but instead can be seen when using a tool such as tiffinfo to view the image description tag.

When viewed with showinf -omexml only a single channel element is seen:

   <Image ID="Image:0" Name="xyc_8bit__membranes_nuclei.tiff">
      <Description/>
      <Pixels BigEndian="true" DimensionOrder="XYCZT" ID="Pixels:0" Interleaved="false" SignificantBits="8" SizeC="1" SizeT="1" SizeX="475" SizeY="354" SizeZ="1" Type="uint8">
         <Channel ID="Channel:0:0" SamplesPerPixel="1">
            <LightPath/>
         </Channel>
         <TiffData FirstC="0" FirstT="0" FirstZ="0" IFD="0" PlaneCount="1">
            <UUID FileName="xyc_8bit__membranes_nuclei.ome.tiff">urn:uuid:26dd8113-b0f8-465d-b860-52ef2d031195</UUID>
         </TiffData>
      </Pixels>
   </Image>

When using tiffinfo you see 2 channel elements:

   <Image ID="Image:0" Name="xyc_8bit__membranes_nuclei.tiff">
       <Description/>
       <Pixels BigEndian="true" DimensionOrder="XYCZT" ID="Pixels:0" Interleaved="false" SignificantBits="8" SizeC="1" SizeT="1" SizeX="475" SizeY="354" SizeZ="1" Type="uint8">
           <Channel ID="Channel:0:0" SamplesPerPixel="1">
              <LightPath/>
           </Channel>
           <Channel ID="Channel:0:1" SamplesPerPixel="1"><LightPath/></Channel>
           <TiffData FirstC="0" FirstT="0" FirstZ="0" IFD="0" PlaneCount="1">
              <UUID FileName="xyc_8bit__membranes_nuclei.ome.tiff">urn:uuid:26dd8113-b0f8-465d-b860-52ef2d031195</UUID> 
           </TiffData>
       </Pixels>
   </Image>
imagesc-bot commented 5 months ago

This issue has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/extracting-a-single-channel-using-bfconvert/91632/4