Hi,
We want to extract pixel values from reformatted red slice to obtain a perpendicular view. To do that, we use endoscopy module in the following way:
# Get curve info
curveNode = slicer.util.getNode(curveName)
pointsCurve = vtk.util.numpy_support.vtk_to_numpy(curveNode.GetCurve().GetPoints().GetData())
modelNode = slicer.util.getNode("model_" + curveName)
# Set endoscopy params
pointsEndoscopy = slicer.util.arrayFromModelPoints(modelNode)
endoscopyGUI = slicer.modules.endoscopy.widgetRepresentation().self()
endoscopyGUI.flyTo(0)
# Storage vectors
volumeNodes_slices = []
voxels_slices = []
curvePoints = []
for index in range(0, len(pointsEndoscopy)-1):
sliceNodeID = "vtkMRMLSliceNodeRed"
# Get image data from slice view
sliceNode = slicer.mrmlScene.GetNodeByID(sliceNodeID)
appLogic = slicer.app.applicationLogic()
sliceLogic = appLogic.GetSliceLogic(sliceNode)
sliceLayerLogic = sliceLogic.GetBackgroundLayer()
reslice = sliceLayerLogic.GetReslice()
reslicedImage = vtk.vtkImageData()
reslicedImage.DeepCopy(reslice.GetOutput())
# Create new volume node using resliced image
volumeNodeResliced = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLScalarVolumeNode")
volumeNodeResliced.SetIJKToRASMatrix(sliceNode.GetXYToRAS())
volumeNodeResliced.SetAndObserveImageData(reslicedImage)
volumeNodeResliced.CreateDefaultDisplayNodes()
volumeNodeResliced.CreateDefaultStorageNode()
volumeNodes_slices.append(volumeNodeResliced)
# Get voxels as a numpy array
voxels = slicer.util.arrayFromVolume(volumeNodeResliced)
voxels_slices.append(voxels)
# Save voxels as .npy
The problem is that pixel values in .npy file do not match with the values in slicer.
For example:
Left: .npy file → HU = 470 in vessel center
Right: red slice → HU = 419 in vessel center