# Problem in reading 16 bit image

**URL:** https://discourse.itk.org/t/problem-in-reading-16-bit-image/536
**Category:** Engineering
**Created:** [December 18, 2017, 9:31am UTC](https://discourse.itk.org/t/problem-in-reading-16-bit-image/536 "2017-12-18T09:31:10Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![swetha.bsharma](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/6de8d8/32.png) [@swetha.bsharma](https://discourse.itk.org/u/swetha.bsharma)
#### Post date: [December 18, 2017, 9:31am UTC](https://discourse.itk.org/t/problem-in-reading-16-bit-image/536/1 "2017-12-18T09:31:10Z")

</div>

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();
  reader->SetImageIO(dicomIO);
  reader->SetFileNames(fileNames);
  reader->Update();
  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?  
-swetha

---

<div class="post-metadata">

### Author: ![tim-evain](https://discourse.itk.org/user_avatar/discourse.itk.org/tim-evain/32/220_2.png) [@tim-evain](https://discourse.itk.org/u/tim-evain)
#### Post date: [December 18, 2017, 2:07pm UTC](https://discourse.itk.org/t/problem-in-reading-16-bit-image/536/2 "2017-12-18T14:07:20Z")

</div>

Hi @swetha.bsharma,

The given snippet seems to be correct.  
Have you tried to load your Dicom dataset into [Slicer](https://www.slicer.org/) ? Does it exhibit the same issue ?

Tim

---

<div class="post-metadata">

### Author: ![swetha.bsharma](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/6de8d8/32.png) [@swetha.bsharma](https://discourse.itk.org/u/swetha.bsharma)
#### Post date: [December 18, 2017, 4:02pm UTC](https://discourse.itk.org/t/problem-in-reading-16-bit-image/536/3 "2017-12-18T16:02:00Z")

</div>

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.  
-swetha

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [December 18, 2017, 4:17pm UTC](https://discourse.itk.org/t/problem-in-reading-16-bit-image/536/4 "2017-12-18T16:17:54Z")

</div>

DICOM images have slope and intercept tags. ITK [automatically](https://blog.kitware.com/dicom-rescale-intercept-rescale-slope-and-itk/) 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).

---

<div class="post-metadata">

### Author: ![swetha.bsharma](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/6de8d8/32.png) [@swetha.bsharma](https://discourse.itk.org/u/swetha.bsharma)
#### Post date: [December 21, 2017, 8:47am UTC](https://discourse.itk.org/t/problem-in-reading-16-bit-image/536/5 "2017-12-21T08:47:16Z")

</div>

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.  
-swetha

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [December 21, 2017, 3:29pm UTC](https://discourse.itk.org/t/problem-in-reading-16-bit-image/536/6 "2017-12-21T15:29:34Z")

</div>

You could use a code similar to the code [fragment](https://itk.org/migrationv4/index.php?sid=2778900&lang=en&action=artikel&cat=3&id=155&artlang=en) from the migration guide about how to counteract the rescale slope and rescale intercept. You can also use [GDCMImageIO-\>GetRescaleSlope()](https://itk.org/Doxygen/html/classitk_1_1GDCMImageIO.html#a5d9858c69b29595be21150c8227083ea) instead of going via meta-data dictionary.
