rapidsai / cucim

cuCIM - RAPIDS GPU-accelerated image processing library
https://docs.rapids.ai/api/cucim/stable/
Apache License 2.0
321 stars 55 forks source link

[FEA] Support and apply ICC profile to the decompressed image #370

Open cooperlab opened 1 year ago

cooperlab commented 1 year ago

@gigony .svs images contain an ICC profile that is important for color standardization of these images. We see significant variability in color properties across scanner models and individual scanners when the ICC profile is not applied.

Currently, the ICC profile can be applied using using PIL. For cucim it would be ideal to apply the transform on device since the data is decompressed there. Otherwise the uncompressed data needs to make a round trip to the host to be normalized and returned to the device.

thumbnail_image005

gigony commented 1 year ago

Hi @cooperlab , Thank you for the feature request. Updated the title of this issue.

Actually, ICC profile is applied when decoding in cuCIM, but only for jpeg2000-compressed TIFF tiles (Please see https://github.com/rapidsai/cucim/blob/fb85f01e3ed7441127cda4b0a85ea7afbcc21d97/cpp/plugins/cucim.kit.cuslide/src/cuslide/jpeg2k/libopenjpeg.cpp#L281). It apply ICC profile in the image to convert into sRGBProfile. I think I can apply it to other decoders such as JPEG.

Implementing it comes with design choices because applying the profile takes time and some people doesn't want to apply ICC profile by default. Do you think it is a good idea to expose an API to access TIFF image's ICC profile so that user can apply ICC profile to the image through cuCIM's another API or other library such as Pillow(https://pillow.readthedocs.io/en/stable/reference/ImageCms.html)? Do you have any use cases or friendly API in your mind?

cooperlab commented 1 year ago

@gigony Ideally it could be (optionally) applied to the array while on GPU. I think this implies a cuCIM operation. The cuCIM reader has the easiest access to the profile since it is handling the file, so one possibility is to set an ICC flag in for the reader or .read_region. Another would be to create a separate cuCIM function that can be applied to the array returned by .read_region and figure out how to pass the ICC profile to that operation.

I think Pillow is undesirable since it requires bringing the array back from device -> host and then sending the result back to device again.

cooperlab commented 1 year ago

Hello Gigon, here is a bit of information from Leica on their design using ICC: https://www.leicabiosystems.com/us/life-sciences-and-research-solutions/articles/from-microscope-to-monitor-a-proprietary-color-match/. It is important for standardization of colors, and can have a profound impact on the performance of image analysis.

cooperlab commented 1 year ago

ICC correction of svs files has been investigated extensively by @ghsmith here: https://github.com/ghsmith/SVSUtil.