# Display an image in a separate window

**URL:** <https://discourse.slicer.org/t/display-an-image-in-a-separate-window/8821>\
**Category:** Development\
**Created:** [October 17, 2019, 7:34pm UTC](https://discourse.slicer.org/t/display-an-image-in-a-separate-window/8821 "2019-10-17T19:34:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![giovform](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/giovform/32/4687_2.png) [@giovform](https://discourse.slicer.org/u/giovform)\
**Post date:** [October 17, 2019, 7:34pm UTC](https://discourse.slicer.org/t/display-an-image-in-a-separate-window/8821/1 "2019-10-17T19:34:59Z")

</div>

Hello. I am trying to display a grayscale OpenCV image in separate window, but no success so far. The code I am executing is as follows and causes Slicer to crash:

```
    height, width = image.shape
    qImg = qt.QImage(np.asarray(image), width, height, qt.QImage.Format_Grayscale8)
    pixmap = qt.QPixmap.fromImage(qImg)
    myLabel = qt.QLabel()
    myLabel.setPixmap(pixmap)
    myLabel.show()

```

Before this, I was successfully displaying the image using OpenCV imshow() method, but it also caused Slicer to crash when I tried to interact with it while maintaining the OpenCV window open.

Any suggestions? I am using Slicer 4.11.0-2019-09-01 r28473.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [October 17, 2019, 8:39pm UTC](https://discourse.slicer.org/t/display-an-image-in-a-separate-window/8821/2 "2019-10-17T20:39:34Z")

</div>

You can show a proper image viewer outside the view layout as shown here: [https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Show\_a\_slice\_view\_outside\_the\_view\_layout](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Show_a_slice_view_outside_the_view_layout)

If you want to convert a numpy array to QImage then I would recommend to use qimage2ndarray package:

```auto
try:
    import qimage2ndarray
except ImportError:
    pip_install('qimage2ndarray')
    import qimage2ndarray

import numpy as np
image = np.fromfunction(lambda i, j: i + j, (100, 100), dtype='uint8')
qImg = qimage2ndarray.array2qimage(image, normalize=True)
pixmap = qt.QPixmap.fromImage(qImg)
myLabel = qt.QLabel()
myLabel.setPixmap(pixmap)
myLabel.show()

```
