Operating system: Windows 10 Pro
Slicer version: 4.10 and / or 4.11
Hi all,
I have a set of fiducial points and a segmentation and I need to obtain the segments which the points belong to.
There are so many points that I need an automated way to do that.
How can I obtain the segments for each point using the Python interface ?
I can see the regions manually by pointing the mouse on them, but I don’t know how I can get them by code.
“coordinates of the whole 3-D region” is undefined. A region’s boundaries have coordinates, the region’s center of gravity has coordinates, each non-zero voxel in the region has coordinates, etc. If you explain what you want to do with the data (maybe draw a sketch or annotate a screenshot) then it may make it more clear.
Let’s assume we have a region in a segmentation. That region covers a 3-D region in the MRI space.
I need coordinates of the voxel in this 3-D, but not only in the MRI space, also in the RAS coordinates.
Or, if I can get the coordinates of all of the boundary points, that would also work well.
You can get all segment voxels as numpy array (using arrayFromVolume method), get IJK coordinates of non-zero voxels using standard numpy array operations (where, …),and convert IJK to RAS as shown in examples in the script repository (see here). You can also export segmentation to model and get coordinates of model points (see examples in script repository).
Although you can obtain all these data, this should be very rarely necessary. Are you sure you need coordinates of all these hundreds of thousands or millions of points? What is your overall goal?
I agree but I need this for a complicated project where the segmentation itself is not perfect…
I tried your suggestion but I have some problems - the resulting RAS coordinates are not correct yet.
Also, I get this warning :
arrayFromSegment is deprecated! Binary labelmap representation may be shared between multiple segments! Use arrayFromSegmentBinaryLabelmap to access a copy of the binary labelmap that will not modify the original labelmap. Use arrayFromSegmentInternalBinaryLabelmap to access a modifiable internal lablemap representation that may be shared between multiple segments.
I must be doing a mistake during IJK to RAS conversion, but I don’t know what it is.
I am using Slicer 4.11. Should I do anything different for this version ? Or is the code provided in
This is just a deprecation warning. Since you don’t modify the segment, you can still use arrayFromSegment, but it would be more clear if you switched to arrayFromSegmentBinaryLabelmap function.
That’s fine - there is no such thing as a perfect segmentation. There are tools and best practices to manage that. If you tell what is your overall goal and what your problems are then we can give advice of what methods have been developed to address them.
I need to assign some fiducial points to their corresponding segments. But since the segmentation has errors, some points, though they are quite close to the segment, are not assigned to their regions.
So I am trying to assign the points if they are close enough to a segment (say, 1mm away from the segment boundaries). This is why I need the RAS coordinates.
But if there is a built-in function in Slicer which can do these kind of things, that would work, too.
The model that Segmentations module generates from the segment should not be worse. Maybe you can smooth the binary labelmap representation and disable smoothing for the surface generation to make the generated surface more closely match the labelmap. Can you attach an example image so that we have a better idea of the difficulty of the problem?
Here is an example. I think the model boundaries aren’t really close enough to the segmentation itself.
Also in some cases, two neighboring models cross each other , i.e. one single point seems to belong to two different models at the same time.
Computaiton of closed surface representation takes time, so it is not created unless it is requested.
You can create it in Segmentations module by clicking “Create” button in the corresponding row in Representations section (or in Segment Editor module click “Show 3D”).
Negative distance means inside, positive distance means outside.