glencoesoftware/bioformats2raw

`--pixel-type` behaves incorrectly

melissalinkert opened this issue · 0 comments

The float to integer conversion introduced in #53 either needs a rewrite or to be removed.

Pixel type conversion is done as each tile is processed, which means that each tile (single channel for FL data) is handled separately:

https://github.com/glencoesoftware/bioformats2raw/blob/master/src/main/java/com/glencoesoftware/bioformats2raw/Converter.java#L1008

The pixels are actually changed here:

https://github.com/glencoesoftware/bioformats2raw/blob/master/src/main/java/com/glencoesoftware/bioformats2raw/Converter.java#L1805

What that does is take the original floating point tile and normalize the pixel values so that the minimum pixel value in the tile is 0.0 and the maximum pixel value is 1.0. Then each pixel value is multiplied by the output pixel type's maximum range, so that for uint16 you would get pixel values between 0 and 65535. That does a better job of preserving the pixel intensity range than just casting float values to a smaller type, but it means that different tiles will be normalized differently. This is more obvious when looking at multiple channels with different min/max ranges in the input image.

I don't think there is a way to fix this without knowing in advance what the overall min/max pixel values are for the entire input dataset.

/cc @mgheirat