# How to replace viewer layout with a png image

**URL:** <https://discourse.slicer.org/t/how-to-replace-viewer-layout-with-a-png-image/34120>\
**Category:** Development\
**Created:** [February 2, 2024, 3:22pm UTC](https://discourse.slicer.org/t/how-to-replace-viewer-layout-with-a-png-image/34120 "2024-02-02T15:22:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tbone](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/tbone/32/69140_2.png) [@tbone](https://discourse.slicer.org/u/tbone)\
**Post date:** [February 2, 2024, 3:22pm UTC](https://discourse.slicer.org/t/how-to-replace-viewer-layout-with-a-png-image/34120/1 "2024-02-02T15:22:46Z")

</div>

Hi everyone, I’m new to Slicer and this might be a simple question, but I’ve been trying to change the viewer layout from a Python script so that I can load a simple png image into it. For example, it could just replace the Red view and show the image.

From the other topics I understood that layouts are customizable with `slicer.vtkMRMLLayoutNode`, and that you can use `slicer.mrmlScene.AddNewNodeByClass` to add new nodes to it.  
But I was having trouble using these methods, so I was uncertain if I was in the right direction of figuring this out.

Would much appreciate help from the experts. Thank you!

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [February 7, 2024, 11:58am UTC](https://discourse.slicer.org/t/how-to-replace-viewer-layout-with-a-png-image/34120/2 "2024-02-07T11:58:42Z")

</div>

You can load the image as any other volume:

```auto
imageVolumeNode = slicer.util.loadVolume('/path/to/image.png')

```

Then something like this to show it in a 2D view:

```auto
redSliceLogic = slicer.app.layoutManager().sliceWidget("Red").sliceLogic()
redSliceLogic.GetSliceCompositeNode().SetBackgroundVolumeID(imageVolumeNode.GetID())
redSliceLogic.GetSliceNode().SetOrientationToAxial()
redSliceLogic.SetSliceOffset(0)
redSliceLogic.GetSliceNode().SetSliceVisible(False)
redSliceLogic.FitSliceToAll()        

```
