I have a markups curve along a vessel and I would like the red slice to be automatically centred on the markups point. This would be very useful when setting a plane perpendicular to the centreline, how can I do this?
Furthermore, is it possible to obtain which coordinate in i,k,j of the perpendicular reformatted images corresponds to each point of the centreline in x,y,z?
The easiest is to click on the markup point, which centers all slice views on the point (except the view that you are interacting with, as you would not want the point to jump away from your mouse pointer).
The code you suggest (voxel-coordinates-from-markup) works perfectly when using the original volume. However it does not work when using the resliced volume.
What I have is a centerline along a vessel. Then I use endoscopy and volume reslice driver modules to obtain a perpendicular view as in:
I need to obtain the coordinate of the centerline point of the perpendicular image (red point in the image). What I’m doing now is
curveNode = slicer.util.getNode("MarkupsCurve")
points = vtk.util.numpy_support.vtk_to_numpy(curveNode.GetCurve().GetPoints().GetData())
input("Adjust view") #Manually adjust view (I want to automatize this aswell)
# Create a Fiducial so I can use getCenter
myFidNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLMarkupsFiducialNode")
centers = 
for index in range(0, len(points)):
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()
# Create new volume node using resliced image
volumeNodeResliced = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLScalarVolumeNode")
# Get voxels as a numpy array
voxels = slicer.util.arrayFromVolume(volumeNodeResliced)
# Get vessel center in (i,j)
center = getCenter("myFidNode", volumeNodeResliced)
I would recommend using Curved Planar Reformat module (in Sandbox extension). It provides a straightened image (series of slices obtained by reslicing along the curve) and also a transform that you can conveniently use to transform between the original image space and the straightened image space.
If this is not what you want then you can use or customize Cross-section analysis module (in SlicerVMTK extension), it probably already contains all the computations you need.