Color tag in OME-tiff XML

Hello all,

I was wondering where I can lookup the color mapping of a channel in OME-tiff files. I have a fluorescence image with three channels, that are defined in the tiff’s XML as follows:

<ns0:Channel Color="-8519680" ID="Channel:0:0" Name="AF555" SamplesPerPixel="1"><ns0:LightPath /></ns0:Channel>
<ns0:Channel Color="16724736" ID="Channel:0:1" Name="AF488" SamplesPerPixel="1"><ns0:LightPath /></ns0:Channel>
<ns0:Channel Color="10551040" ID="Channel:0:2" Name="DAPI" SamplesPerPixel="1"><ns0:LightPath /></ns0:Channel>

Where can I retrieve the imformation for a given “color id” (e.g. -8519680)? Or is this value just a primitive integer type that can be parsed to a RGBA-value by shifting and masking? So Red is (x >> 24) & 255 et cetera.

Thanks in advance!

Hi @michael_ef

With the following macro
(EDIT: macro corrected, after @joshmoore hint)

values = newArray(-8519680, 16724736, 10551040);

// RGBA conversion
for (n=0; n<3; n++){
     val = values[n];
     r = ( val>>24 ) & 0xff;
     g = ( val>>16 ) & 0xff;
     b = ( val>>8  ) & 0xff;
     a =   val & 0xff;
     print("Value: " + val +  " R = " + r + ",  " + "G: " + g + ",  " + "B: " + b + " alpha: " + a);
}

you get

Value: -8519680 R = 255,  G: 126,  B: 0 alpha: 0
Value: 16724736 R = 0,  G: 255,  B: 51 alpha: 0
Value: 10551040 R = 0,  G: 160,  B: 255 alpha: 0

Is this what you need?

1 Like

Peter,

I think your macro will need to include the alpha channel.

Yup:

In [7]: for x in (-8519680, 16724736, 10551040):
   ...:     print(x, (x>>24)&0xff, (x>>16)&0xff, (x>>8)&0xff, x&0xff)
   ...:
   ...:
-8519680 255 126 0 0
16724736 0 255 51 0
10551040 0 160 255 0

which matches the output of ome_zarr.conversions:

In [17]: from ome_zarr.conversions import int_to_rgba_255

In [18]: for x in (-8519680, 16724736, 10551040):
    ...:     print(x, int_to_rgba_255(x))
    ...:
-8519680 [255, 126, 0, 0]
16724736 [0, 255, 51, 0]
10551040 [0, 160, 255, 0]

~J.

1 Like

Perfect, thanks for the fast reply :slight_smile:

1 Like