Problem in reading 16 bit image

Hi All,

I am trying to read a 16 bit dicom series which has values ranging from 0- 4095. The below code is the one I am using for reading the pixel values.

    typedef unsigned short    PixelType;
 const int      Dimension = 3;
  typedef itk::Image< PixelType, Dimension >         ImageType;
   typedef itk::ImageSeriesReader< ImageType > ReaderType;
  ReaderType::Pointer reader = ReaderType::New();
  typedef itk::GDCMImageIO       ImageIOType;
  ImageIOType::Pointer dicomIO = ImageIOType::New();
  ImageType::Pointer image3d=reader->GetOutput();
  ImageType::IndexType ind=image3d->GetBufferedRegion().GetIndex();
 unsigned short testval=image3d->GetPixel(ind);

The maximum value which is read is 2 and minimum value is 0 but the same thing read in matlab using the function dicomread is giving me maximum value of 4095 and minimum value of 0.

Is my datattype correct? How do I fix this issue?

Hi @swetha.bsharma,

The given snippet seems to be correct.
Have you tried to load your Dicom dataset into Slicer ? Does it exhibit the same issue ?


1 Like

I do not have slicer at the moment do not have much space in my computer ,I loaded it in ITK-SNAP the image did not load correctly and minimum and maximum values were -0.6 to 3.1 .It dosen’t match the matlab values. I will check it with slicer tomorrow.

DICOM images have slope and intercept tags. ITK automatically applies them. It is conceivable that DICOM image’s raw values range 0-4095, but transformed values range -0.6 to 3.1 - or some other similar range which might be a product of applying scale and intercept at lower precision (e.g. using integer math).

1 Like

These images has grayvalues and color LUT maps also when using the dicomread function of matlab it gives the grayvalues and LUTmap separately . Is there a similar functionality which I can use in ITK.

You could use a code similar to the code fragment from the migration guide about how to counteract the rescale slope and rescale intercept. You can also use GDCMImageIO->GetRescaleSlope() instead of going via meta-data dictionary.