glencoesoftware / raw2ometiff

Raw format to OME-TIFF converter
GNU General Public License v2.0
46 stars 20 forks source link

RGB & color handling #96

Closed sbesson closed 1 year ago

sbesson commented 1 year ago

Primarily driven by the discussion at https://forum.image.sc/t/nikon-slide-scanner-brightfield-nd2-files-lacking-rgb-information-after-conversion-to-ome-tif-when-viewed-in-omero/76438

The scenario can be reproduced by using a file similar to

% cat test.fake.ini
sizeC=3
color_0=16711935
color_1=16711935
color_2=16711935

and either running NGFF-Converter 1.1.4 with the--rgb flag in the arguments list or directly:

% bioformats2raw test.fake test.zarr
% raw2ometiff test.zarr test.ome.tiff --rgb

The generated OME-TIFF is a RGB image (SizeC=3, 1 channel with SamplePerPixels=3) as expected but its Channel metadata still contains the green color information

 % tiffinfo ~/Downloads/test.ome.tiff 
=== TIFF directory 0 ===
TIFF Directory at offset 0x27c7f (162943)
  Image Width: 512 Image Length: 512
  Tile Width: 512 Tile Length: 512
  Resolution: 0, 0 pixels/cm
  Bits/Sample: 8
  Sample Format: unsigned integer
  Compression Scheme: LZW
  Photometric Interpretation: RGB color
  Samples/Pixel: 3
  Planar Configuration: separate image planes
  SubIFD Offsets: 162516
  ImageDescription: <?xml version="1.0" encoding="UTF-8"?><OME xmlns="http://www.openmicroscopy.org/Schemas/OME/2016-06" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openmicroscopy.org/Schemas/OME/2016-06 http://www.openmicroscopy.org/Schemas/OME/2016-06/ome.xsd"><Image ID="Image:0" Name="test"><Pixels BigEndian="true" DimensionOrder="XYCZT" ID="Pixels:0" Interleaved="false" SignificantBits="8" SizeC="3" SizeT="1" SizeX="512" SizeY="512" SizeZ="1" Type="uint8"><Channel Color="16711935" ID="Channel:0:0" SamplesPerPixel="3"><LightPath/></Channel><TiffData IFD="0" PlaneCount="1"/></Pixels></Image><StructuredAnnotations><MapAnnotation ID="Annotation:Resolution:0" Namespace="openmicroscopy.org/PyramidResolution"><Value><M K="1">256 256</M></Value></MapAnnotation></StructuredAnnotations></OME>
  Software: OME Bio-Formats 6.11.1

When importing such a file into OMERO, all channels are now populated as green by default. This is at odds with the user expectation when passing a --rgb flag.

dcb6642852e3949fbb2a1c58ab7958bfffd8c652 expands the RGB conversion tests to covert the scenario above and add channel metadata assertions 2cfbd1ec71c0ac82706608a9befbbc3b3b0885d2 proposes to change the behavior of the converter to remove the Channel.Color metadata when --rgb is passed and adjusts the newly introduced unit test accordingly

/cc @DavidStirling

melissalinkert commented 1 year ago

I think this generally makes sense. Two thoughts:

sbesson commented 1 year ago

The last commits should remove any channel metadata that could be used as the source of truth for setting the color as defined in https://github.com/ome/omero-blitz/blob/c4e4d2bbd3ac6d5cdc14621fb89fb97187eca22e/src/main/java/ome/formats/model/ChannelProcessor.java#L129. The channel name is also removed.

All of the above could be made configurable via some command-line options if deemed valuable.

melissalinkert commented 1 year ago

Merging as discussed during today's PR review meeting.