Load three PET/CTs in a separate window


I am making an extension where I load three CT images into the separate windows (Green, Red and Yellow). If available, I would also like to load the PET scan as foreground. Loading the three CT images is successful, but adding the PET scan does not work yet. Can someone help?

self.volume0_node = slicer.util.loadVolume(file_path[0]["image"])
        self.volume1_node = slicer.util.loadVolume(file_path[1]["image"])
        self.volume2_node = slicer.util.loadVolume(file_path[2]["image"])

        layoutManager = slicer.app.layoutManager()
        sliceWidget0 = layoutManager.sliceWidget('Red')
        sliceNode0 = sliceWidget0.mrmlSliceNode()
        compositeNode0 = sliceWidget0.mrmlSliceCompositeNode()
        if file_path[0]["PET"]:
            self.pet0_node = slicer.util.loadVolume(file_path[0]["PET"])

        sliceWidget1 = layoutManager.sliceWidget('Green')
        sliceNode1 = sliceWidget1.mrmlSliceNode()
        compositeNode1 = sliceWidget1.mrmlSliceCompositeNode()
        if file_path[1]["PET"]:
            self.pet1_node = slicer.util.loadVolume(file_path[1]["PET"])

        sliceWidget2 = layoutManager.sliceWidget('Yellow')
        sliceNode2 = sliceWidget2.mrmlSliceNode()
        compositeNode2 = sliceWidget2.mrmlSliceCompositeNode()
        if file_path[2]["PET"]:
            self.pet2_node = slicer.util.loadVolume(file_path[2]["PET"])

I have also tried this:
slicer.util.setSliceViewerLayers(background=self.volume2_node, foreground=self.pet2_node)
But then I get the same CT/PET scan for each window.

If you haven’t already you also will need to set the foreground opacity.

(As a side note, to get better debugging advice it’s good to narrow down to a small example that replicates what you are trying to solve and that is easy for anyone to test themselves. Here for example, if you set up your script to use the SampleData module and you only included the code for one slice view and made it so that anyone could paste the code into their own python console then you may get more helpful responses).

1 Like