- Operating system: Windows 10
- Slicer version: 5.0.2
- Expected behavior: getting the vtkImageData of a reformatted slice shown in Red widget.
- Actual behavior: the returned vtkImageData is of another volume in the background layer.
Hello Prof. Andras and everyone else,
I have a question on how to get the reslice image from a slice node. And all of the following steps were performed by code.
 To begin, I have loaded several scalar volumes into 3D Slicer. I suppose their names are in the background-to-foreground order as vol0, vol1, vol2, and vol3.
 Next, I have successfully shown a reformatted slice of vol2 as the background layer of the ‘Red’ widget. Please see the attached image for reference.
 Now, I want to obtain above reformatted slice as a vtkImageData (not the screenshot) by following code:
sliceLogic = slicer.app.applicationLogic().GetSliceLogicByLayoutName(‘Red’)
sliceLayerLogic = sliceLogic.GetBackgroundLayer()
reslice = sliceLayerLogic.GetReslice()
reslicedImage = vtk.vtkImageData()
(reslicedImage is then used for exporting PNG file)
However, when executing the code within my scripted module, the returned image is the slice of vol0 (instead of vol2). Meanwhile, if I type code into the Slicer console, the returned image is as expected (slice of vol2).
I can’t figure out what my mistake is. So I would like to ask for your help or advice.