# DICOM upside down using vtkDICOMImageReader

**URL:** https://discourse.vtk.org/t/dicom-upside-down-using-vtkdicomimagereader/13735
**Category:** Support
**Created:** [April 18, 2024, 8:28am UTC](https://discourse.vtk.org/t/dicom-upside-down-using-vtkdicomimagereader/13735 "2024-04-18T08:28:28Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![lo\_andrew](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lo_andrew/32/8744_2.png) [@lo\_andrew](https://discourse.vtk.org/u/lo_andrew)
#### Post date: [April 18, 2024, 8:28am UTC](https://discourse.vtk.org/t/dicom-upside-down-using-vtkdicomimagereader/13735/1 "2024-04-18T08:28:28Z")

</div>

Hi,  
I was using vtkGDCMImageReader from vtkgdcm (build from GDCM with USE\_VTK on) to import DICOM data and toggling the FileLowerLeftOn() to solve the upside down issue.

**Recently when I changed from vtkGDCMImageReader to vtkDICOMImageReader, I am experiencing the upside down issue same as [this post](https://discourse.vtk.org/t/dicom-reslice-upside-down-problem/7631), even with the FileLowerLeft toggled on.**

The minimal code is as follows:

```auto
import numpy as np
import vtk
from vtk.util import numpy_support
import os 
from gdcm import vtkgdcm

dir = 'path to DICOM dataset'
list_of_dcm = os.listdir(dir)
shape = (len(list_of_dcm), 512, 512)
volume_array = np.zeros(shape)

for n, path in enumerate(list_of_dcm):
    dicom_reader = vtkgdcm.vtkGDCMImageReader()
    # dicom_reader = vtk.vtkDICOMImageReader()
    dicom_reader.SetFileName(os.path.join(dir, path))
    dicom_reader.FileLowerLeftOn()
    dicom_reader.Update()
    vtk_image_data = dicom_reader.GetOutput()
    dx, dy, dz = vtk_image_data.GetDimensions()
    im_array = numpy_support.vtk_to_numpy(
        vtk_image_data.GetPointData().GetScalars())
    if dz == 1:
        im_array.shape = dy, dx
    else:
        im_array.shape = dz, dy, dx
        
    volume_array[n] = im_array
    print(f"finish {n}")
    
np.savez_compressed('vtkgdcmimagereader', a=volume_array)
# np.savez_compressed('vtkdicomimagereader', a=volume_array)

```

I ran this code two times, with different dicom reader and saved as different name (the commented line above)

after that I visualized them using a simple matplotlib codes:

```auto
import numpy as np
test_gdcm = np.load('vtkgdcmimagereader.npz')['a']
test_vtkdicom = np.load('vtkdicomimagereader.npz')['a']
import matplotlib.pyplot as plt

fig, axes = plt.subplots(2, 3, figsize=(100, 75)) 

axes[0, 0].imshow(test_gdcm[:, :, 100], cmap='gray') 
axes[0, 0].set_title('gdcm sagittal')        
axes[0, 0].axis('off')                  

axes[0, 1].imshow(test_gdcm[:, 100, :], cmap='gray')  
axes[0, 1].set_title('Image coronal')       
axes[0, 1].axis('off')                  

axes[0, 2].imshow(test_gdcm[100, :, :], cmap='gray')  
axes[0, 2].set_title('Image axial')    
axes[0, 2].axis('off') 

axes[1, 0].imshow(test_vtkdicom[:, :, 100], cmap='gray')  
axes[1, 0].set_title('gdcm sagittal')
axes[1, 0].axis('off')                 

axes[1, 1].imshow(test_vtkdicom[:, 100, :], cmap='gray')  
axes[1, 1].set_title('Image coronal')     
axes[1, 1].axis('off')                  

axes[1, 2].imshow(test_vtkdicom[100, :, :], cmap='gray')  
axes[1, 2].set_title('Image axial')         
axes[1, 2].axis('off')                    

plt.tight_layout()

plt.show()

```

I am using a custom build VTK (v8.1.2) and GDCM(3.0.9), but I have tried using the VTK from Pypi for vtkDICOMImageReader(), and the result is the same.

For both vtkgdcm.vtkGDCMImageReader() and vtk.vtkDICOMImageReader(): if FileLowerLeft is set to False, their output are the same (upside down)

If FileLowerLeft is set to True, vtkgdcm.vtkGDCMImageReader() is now correct but vtk.vtkDICOMImageReader() gives me the same output with upside down image.

Could I ask why is this happening? How do I get the same result from vtkgdcm.vtkGDCMImageReader() using vtk.vtkDICOMImageReader()? Any help is appreciated.
