imi-bigpicture / wsidicom

Python package for reading DICOM WSI file sets.
Apache License 2.0
33 stars 5 forks source link

read_region() tile width and height appear to be reversed #136

Closed psavery closed 10 months ago

psavery commented 10 months ago

For the following example, it looks to me that the tile width and height are reversed:

from wsidicom import WsiDicom, WsiDicomWebClient

url = 'https://idc-external-006.uc.r.appspot.com/dcm4chee-arc/aets/DCM4CHEE/rs'
study_uid = '2.16.756.5.41.446.20190905094928'
series_uid = '2.16.756.5.41.446.20190905094928.20190905102252'

client = WsiDicomWebClient.create_client(url)

slide = WsiDicom.open_web(client, study_uid, series_uid)

size = (1000, 900)
print(f'{size=}')
tile = slide.read_region((0, 0), 0, size)
print(f'{tile.width=} {tile.height=}')

It prints out the following:

size=(1000, 900)
tile.width=900 tile.height=1000

If I look into the API for read_region, it looks like the size parameter is specified via (width, height). However, the returned tile appears to have the width and height reversed.

erikogabrielsson commented 10 months ago

This looks like a problem with the PydicomDecoder. The numpy array returned from the pydicom pixel handler is 1-dimensional and needs to be reshaped into the correct width and height. The reshape size is however incorrect, as the first dimension for a numpy array corresponds to height, and the second to width. Switching these and one gets the correct size in the output. This also fixes so that the image is not totally scrambled.

But additionally, this image is monochrome2 (i.e. grayscale) and the LUT needs to be applied in order to get similar results as the Slim viewer. And as you noticed earlier the LUT parser does not work for the LUT in this image.