rapidsai / cucim

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

Images with no color channel! #230

Open drbeh opened 2 years ago

drbeh commented 2 years ago

Describe the bug When using cuCIM to load TIFF files that does not have color channel (a grayscale 2D image), no error is thrown and instead the values will be repeated to create an RGBA image, representing the grayscale image. This may cause confusion, like here: https://github.com/Project-MONAI/MONAI/issues/3858

Steps/Code to reproduce bug

import numpy as np                                                                                                                                                                                                                           
from skimage import io    
from cucim import CuImage

image_path = "test.tif"
x = np.random.randint(low=0, high=256, size=(128,128), dtype=np.uint8)
io.imsave(image_path, x) 

img = np.array(CuImage(image_path).read_region())
print(f"{img.shape = }")
print(f"{img[0, 0, :] = }")
img.shape = (128, 128, 4)
img[0, 0, :] = array([121, 121, 121, 255], dtype=uint8)
drbeh commented 2 years ago

@gigony is there any update on this? thanks

gigony commented 2 years ago

@drbeh we would eventually need to support multi-band and other data types

Currently, if the image is not RAW/LZW/JPEG/JPEG2000-compressed tiled/multi-resolution RGB images, it delegates its processing to libtiff's TIFFRGBAImageGet() method that creates a 4-channel RGBA array.

What would you suggest until we support single-channel image data? Maybe raising a warning message would be one we can do?

drbeh commented 2 years ago

Thank you, @gigony! Raising an error would satisfy the purpose of this open issue. Currently, we don't have any need for single-channel images in digital pathology but it might be a good feature to have.

gigony commented 10 months ago

Thank you, @gigony! Raising an error would satisfy the purpose of this open issue. Currently, we don't have any need for single-channel images in digital pathology but it might be a good feature to have.

Now raising a warning message (by https://github.com/rapidsai/cucim/pull/293) and updated tag from bug to feature request.

siemdejong commented 7 months ago

Currently, we don't have any need for single-channel images in digital pathology but it might be a good feature to have.

One use case would be where another imaging modality is used, such as higher harmonic generation microscopy, from which we only want to fetch one channel, as the other channels might sometimes be undescriptive and might confuse deep learning models.

Another use case is when a mask's pixels intensity serve as labels. If high resolution masks are available, it might still be beneficial to read them with cucim.