0

i also encountered a strange division by 2 problem with my dicom files (I got them from https://wiki.cancerimagingarchive.net/pages/viewpage.action?pageId=52758026). I am not sure how to upload files, but the following is how I read

image_bytes = tf.io.read_file(fname )
image = tfio.image.decode_dicom_image(image_bytes, dtype=tf.uint16, on_error = 'lossy')
im = image.numpy () [0, :, :, 0].astype (np.uint16)

the values of the images are twice the correct value (so I have to divide everything by 2 to get the correct value). I am using tf 2.3 and tfio 0.16.

BTW. I was able to read the tutorial chest x-ray image; but I am not sure if there's a division by 2 issue as well, since I don't know what the correct values should be.

Thanks.

Amit Joshi
  • 15,448
  • 21
  • 77
  • 141
balcony
  • 13
  • 3

1 Answers1

0

For anything DICOM related, I can recommend using pydicom. Reading the image and accessing pixel_array looks fine to me.

code-lukas
  • 1,586
  • 9
  • 19
  • yes, pydicom and pixel_array indeed work very well, and gives the correct pixel value. The issue here is to use tensorflow io to directly work with dcm files and convert to a tf tensor, without going through the numpy array step. – balcony Mar 16 '23 at 10:48
  • What happens if you substitute your last line with `im = np.squeeze(image.numpy())`? How do you figure out that you have to divide by 2? Did you try to load the same image with `pydicom` and `tfio` and compared the resulting image arrays? – code-lukas Mar 17 '23 at 08:47