How to replace viewer layout with a png image

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!

You can load the image as any other volume:

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

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

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