I’m trying to do a project on slicer with simpleITK.
I create a labelmap volume node and read it as a SimpleITKimage.
Now I show this labelmap volume in red, green and yellow slice window.
I want to know how to get a leftmost/rightmost coordinate in slice window.
Since I’m not familiar with SimpleITK, I have no idea about the problem.
Thank you.
Here is my code:
labelmapVolumeNode = slicer.mrmlScene.AddNewNodeByClass(“vtkMRMLLabelMapVolumeNode”)
labelmapVolumeNode.SetName(“Test_volume”)
slicer.modules.segmentations.logic().ExportAllSegmentsToLabelmapNode(segmentationNode, labelmapVolumeNode, slicer.vtkSegmentation.EXTENT_REFERENCE_GEOMETRY)
test_volume = slicer.util.getNode(“Test_volume”)
inputImage = sitkUtils.PullVolumeFromSlicer(test_volume)
Not sure that this answers your question, not too clear what it is you want to do, so a bit of guessing here:
If you want to get the world coordinates of a specific index in the image (corners of the volume):
# two opposite corners, add all other index combinations if needed
corner_indexes = [[0]*inputImage.GetDimension(),[sz-1 for sz in inputImage.GetSize()]]
corner_coordinates = [inputImage.TransformIndexToPhysicalPoint(index) for index in corner_indexes]
Thanks for the clarification. So there’s one additional step, getting the bounding box of the specific label of interest. The code should look something like this:
# Assuming inputImage has discrete labels (e.g. 1, 2)
label_shape_filter = sitk.LabelShapeStatisticsImageFilter()
label_shape_filter.Execute(inputImage)
# The bounding box's first "dim" entries are the starting index and
# last "dim" entries the size. Get the bounding box for label 2
bounding_box = label_shape_filter.GetBoundingBox(2)
corner_indexes = [bounding_box[0:inputImage.GetDimension()]]
corner_indexes.append([i+sz-1 for i, sz in zip(min_indexes, bounding_box[inputImage.GetDimension():])])
corner_coordinates = [inputImage.TransformIndexToPhysicalPoint(index) for index in corner_indexes]
In the code, the comment says “Get the bounding box for label 2” . If you only have a single label then the only valid value is 1. Likely that is your situation.
Thank you.
However, I try the code with index= (image.GetSize()[0], image.GetSize()[1], image.GetSize()[2]) and use FiducialNode to show in 3d view, the position looks like not situated at the corner.
Here is my testing code:
inputImage.TransformIndexToPhysicalPoint(index)
Then, I try a stupid way to find the leftmost/rightmost coordinates.
I visualize what I’m going to do. I want to find the coordinate of every point on green line, and than I will fill the hole by replacing 0 with 1 in the image.
I think this is more of a Slicer question, than SimpleITK one. Since you already posted it on the Slicer forum, it is probably best if main conversation is continued there.