Reslice / Reorient Slice view

Prof @lassoan ,

I was following the discussion at

At this momement, if we tell to grow the margin by 0.5 mm in a cylinder, is only 0.25 mm is grown on either side ? so if we want 0.5 in one side do we need to grow it by 1 mm ?

Margin size will mean the how much a boundary will be moved (if you set 1mm as margin then the object will be 2mm wider).

1 Like

Dear Prof @lassoan @Juicy

Now as margin growing working perfectly we started working on analysis of data and we noticed a very minor offset of the ROI.

We expected the Bar of the ROI to align to all the fiducials. we initially thought it was due to error in placement of marks and we incorporated auto update and played around

Update slice plane automatically whenever points are changed

markupObservation = [markups, markups.AddObserver(slicer.vtkMRMLMarkupsNode.PointModifiedEvent, UpdateSlicePlane, 0)]

In Slice view it is nicely in plane but the ROI does not fit perfectly to that. Is this expected ? Is there something that need to be changed in the ROI code ?

The Coplanar script is working perfectly i think as you can see. It is something wrong with the ROI.

How did you position the ROI? Is it the oriented bounding box provided by Segment statistics?

I could not figure out how to gt the bounding box with the segment statistics.
I did it with the Script in the repository.

segmentationNode = getNode(‘Segmentation’)

Compute bounding boxes

import SegmentStatistics
segStatLogic = SegmentStatistics.SegmentStatisticsLogic()
segStatLogic.getParameterNode().SetParameter(“Segmentation”, segmentationNode.GetID())
segStatLogic.getParameterNode().SetParameter(“LabelmapSegmentStatisticsPlugin.obb_origin_ras.enabled”,str(True))
segStatLogic.getParameterNode().SetParameter(“LabelmapSegmentStatisticsPlugin.obb_diameter_mm.enabled”,str(True))
segStatLogic.getParameterNode().SetParameter(“LabelmapSegmentStatisticsPlugin.obb_direction_ras_x.enabled”,str(True))
segStatLogic.getParameterNode().SetParameter(“LabelmapSegmentStatisticsPlugin.obb_direction_ras_y.enabled”,str(True))
segStatLogic.getParameterNode().SetParameter(“LabelmapSegmentStatisticsPlugin.obb_direction_ras_z.enabled”,str(True))
segStatLogic.computeStatistics()
stats = segStatLogic.getStatistics()

Draw ROI for each oriented bounding box

import numpy as np
for segmentId in stats[‘SegmentIDs’]:
# Get bounding box
obb_origin_ras = np.array(stats[segmentId,“LabelmapSegmentStatisticsPlugin.obb_origin_ras”])
obb_diameter_mm = np.array(stats[segmentId,“LabelmapSegmentStatisticsPlugin.obb_diameter_mm”])
obb_direction_ras_x = np.array(stats[segmentId,“LabelmapSegmentStatisticsPlugin.obb_direction_ras_x”])
obb_direction_ras_y = np.array(stats[segmentId,“LabelmapSegmentStatisticsPlugin.obb_direction_ras_y”])
obb_direction_ras_z = np.array(stats[segmentId,“LabelmapSegmentStatisticsPlugin.obb_direction_ras_z”])
# Create ROI
segment = segmentationNode.GetSegmentation().GetSegment(segmentId)
roi=slicer.mrmlScene.AddNewNodeByClass(“vtkMRMLAnnotationROINode”)
roi.SetName(segment.GetName()+’ bounding box’)
roi.SetXYZ(0.0, 0.0, 0.0)
roi.SetRadiusXYZ((0.5obb_diameter_mm))
# Position and orient ROI using a transform
obb_center_ras = obb_origin_ras+0.5*(obb_diameter_mm[0] * obb_direction_ras_x + obb_diameter_mm[1] * obb_direction_ras_y + obb_diameter_mm[2] * obb_direction_ras_z)
boundingBoxToRasTransform = np.row_stack((np.column_stack((obb_direction_ras_x, obb_direction_ras_y, obb_direction_ras_z, obb_center_ras)), (0, 0, 0, 1)))
boundingBoxToRasTransformMatrix = slicer.util.vtkMatrixFromArray(boundingBoxToRasTransform)
transformNode = slicer.mrmlScene.AddNewNodeByClass(‘vtkMRMLTransformNode’)
transformNode.SetAndObserveMatrixTransformToParent(boundingBoxToRasTransformMatrix)
roi.SetAndObserveTransformNodeID(transformNode.GetID())