question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

LoadImaged for 2D/3D grayscale tiff files

See original GitHub issue

Using LoadImaged on a 2D grayscale tiff file with WSIReader and backend=cucim returns an array with 3 “color” channels, which are all identical.

For example,

data_dict = {"image": "test.tif"}
x = np.random.randint(low=0,high=256,size=(128,128),dtype=np.uint8)
io.imsave(data_dict["image"],x) 

print("cucim: shape = " + str(cucim.CuImage(data_dict["image"]).shape))
transform = LoadImaged(keys=["image"], reader=WSIReader, backend='cuCIM')
print("LoadImaged-cucim: shape = " + str(transform(data_dict)["image"].shape))

returns,

cucim: shape = [128, 128, 1]
LoadImaged-cucim: shape = (3, 128, 128)

When using backend=tifffile the files are misread entirely

print("tifffule: shape = " + str(tifffile.imread(data_dict["image"]).shape))
transform = LoadImaged(keys=["image"], reader=WSIReader, backend='tifffile')
print("LoadImaged-tifffile: shape = " + str(transform(data_dict)["image"].shape))

returns,

tifffule: shape = (128, 128)
LoadImaged-tifffile: shape = (3, 128)

Is this the expected behavior? Is there a better way to read 2D grayscale tiff files into monai? How about 3D grayscale tiffs?

Thanks, David

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
drbehcommented, Mar 1, 2022

perhaps in the wsireader it’s useful to raise a runtime error when the input doesn’t have the required colour channels?

@wyli, that depends on the backends and each of them handles this differently, so we don’t know it before loading the image. It should be addressed in cuCIM, so I made an issue on their repo.

1reaction
drbehcommented, Mar 1, 2022

@drbeh , you’re right, my application is not whole slide imaging. I work with microCT data, at a user-facility for scientific applications: https://als.lbl.gov/beamlines/8-3-2/. We don’t use medical imaging formats like dicom. Instead we store raw data in hdf5, but typically give users reconstructions in tiffs (either 3D tiffs or individual 2D slices). Would very much appreciate general tiff support in monai.

@perlmutter, I believe we already support functionality via ITK. You should be able to use ITKReader for your use case. For your example above you can change it to:

import numpy as np                                                                                                                                                                                                                           
from skimage import io
from monai.transforms import LoadImaged
from monai.data.image_reader import ITKReader       

data_dict = {"image": "test.tif"}
x = np.random.randint(low=0,high=256,size=(128,128),dtype=np.uint8)
io.imsave(data_dict["image"],x) 

transformD = LoadImaged(keys=["image"], reader=ITKReader)
image = transformD(data_dict)["image"]
print(f"ITKReader: image shape = {image.shape}")
ITKReader: image shape = (128, 128)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Vaa3D and Vaa3D-Neuron: help - NITRC
The istitch plugin we've developed for stitching 2D/3D/4D images with ... The same happens if I try to use TIFF (tiled, 2D) and...
Read more >
Apropos image - FreeBSD
TIF it needs libpng resp. libtiff; jbigtopnm(1): JBIG to PNM image file converter ... for Digital Images; pgm(5): Netpbm grayscale image format description ......
Read more >
Changelog — Ensenso SDK 3.4.715 documentation
Add: NxLib: Support for tiff file format with float and short data types in LoadImage and SaveImage (e.g. for reading/writing DisparityMap or PointMap...
Read more >
CImg_reference.pdf - The CImg Library
on which image slice and vector channel the loop must apply (usually both 0 for grayscale 2D images). Finally, I is.
Read more >
Pylimph Node V2.0.6 - Khan Academy
Most modern media software can view SVG files, including Adobe * products, ... ALPHA_MASK); } // Grayscale and alpha if (curColorMode === PConstants....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found