# ViewImage in Python

**URL:** <https://discourse.itk.org/t/viewimage-in-python/951>\
**Category:** Engineering\
**Tags:** vtk, python\
**Created:** [May 25, 2018, 4:16pm UTC](https://discourse.itk.org/t/viewimage-in-python/951 "2018-05-25T16:16:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![phcerdan](https://discourse.itk.org/user_avatar/discourse.itk.org/phcerdan/32/286_2.png) [@phcerdan](https://discourse.itk.org/u/phcerdan)\
**Post date:** [May 25, 2018, 4:16pm UTC](https://discourse.itk.org/t/viewimage-in-python/951/1 "2018-05-25T16:16:34Z")

</div>

With the module ‘ITKVtkGlue’ wrapped the following script works to visualize images without the need for external software in python:

```python
import itk
PixelType = itk.UC
Dimension = 3
ImageType = itk.Image[PixelType, Dimension]

imagePath = '/path/image3D.nrrd'
reader = itk.ImageFileReader.New(FileName=imagePath)
reader.Update()
itk.ViewImage[ImageType].View(reader.GetOutput())

```

Alternatively without declaring the ImageType beforehand:

```python
import itk
imagePath = '/path/anyImage.nrrd'
reader = itk.ImageFileReader.New(FileName=imagePath)
reader.Update()
itk.ViewImage[type(reader.GetOutput())].View(reader.GetOutput())

```

* * *

Some samples:  
**2D**

```auto
itk.ViewImage[type(reader.GetOutput())].View(reader.GetOutput(), '2DImage')

```

 ![screen_viewImage2D](https://discourse.itk.org/uploads/default/original/1X/f3431b516dc7f77a50a887edd90aea8dc865dc4f.jpg)

* * *

**3D**

```auto
itk.ViewImage[type(reader.GetOutput())].View(reader.GetOutput(), '3DImage')

```

 ![screen_3Dimage](https://discourse.itk.org/uploads/default/original/1X/761679d42921493c6ac6dfb754768ac12c15b80a.jpg)

* * *

ViewImage.View only requires passing the input image, optional arguments are ‘title’, windowWidth and windowHeight.
