Center slice given a markup

Hi,

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?

Thanks,

Belén

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).

You can also use Cross-section analysis module in SlicerVMTK extension to explore/adjust a centerline.

You can find code snippets for all these kind of commonly needed operations in the script repository. See for example here.

Hi,

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:

imagen

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")
    myFidNode.SetName("myFidNode")
    
    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()
        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()
        
        # Get voxels as a numpy array
        voxels = slicer.util.arrayFromVolume(volumeNodeResliced)
        
        # Get vessel center in (i,j)
        myFidNode.AddFiducialFromArray(points[index])
        center = getCenter("myFidNode", volumeNodeResliced)
        myFidNode.RemoveAllControlPoints()

Where getCenter is voxel-coordinates-from-markup. voxels contains pixel information of the resliced image in redSlice view (get-reformatted-image-from-a-slice-viewer-as-numpy-array).

I want center and voxels to correspond but it’s not working in all slices.
How can I fix that?

Thanks :grinning:

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.

1 Like