1

I have been working on DICOM CT scan images. I used simleITK to read the images to a numpy array. But the image pixel values are negative float values as shown in the image and the dtype of each pixel is float32. How to convert this pixel values to be able to train a TensorFlow 3D CNN model?

# Read the .nii image containing the volume with SimpleITK:
sitk_obj = sitk.ReadImage(filename)

# and access the numpy array:
image = sitk.GetArrayFromImage(sitk_obj)

negative pixel values negative pixel values

The images read are of different shapes, how can I resize them to a specific constant image shapes?(as shown in below image)

different image shapes

Sai Teja
  • 153
  • 1
  • 8

1 Answers1

2

If you use SimpleITK's RescaleIntensity function, you can rescale the pixel values to whatever range you require. Here's the docs for that function:

https://simpleitk.org/doxygen/latest/html/namespaceitk_1_1simple.html#af34ebbd0c41ae0d0a7a152ac1382bac6

To resize your images you can use SimpleITK's ResampleImageFilter. Here's the docs for that class:

https://simpleitk.org/doxygen/latest/html/classitk_1_1simple_1_1ResampleImageFilter.html

The following StackOverflow answer shows how to create a reference image that you resample your image onto:

https://stackoverflow.com/a/48065819/3712577

And this Github Gist how to resample several images to the same reference image:

https://gist.github.com/zivy/79d7ee0490faee1156c1277a78e4a4c4

Note that SimpleITK considers images as objects in physical space. So if the image origins, directions, and pixel spacings do not match up, then you will not get the result you expect.

Dave Chen
  • 1,905
  • 1
  • 12
  • 18