IsPointInROI and GetPlanes not available

Hello Slicer users,

In my Python script I try to check if a voxel is inside a ROI. I searched the forum and found two options which are: IsPointInROI() and GetPlanes() on the vtkMRMLMarkupsROINode.

But on both I get an error that the attributes are not available. I use Slicer 4.11, maybe those methods are only available in newer versions of Slicer?

I use the new ROI node because that one has the possibility to rorate/place in the 3D window.

Probably these methods are added in more recent Slicer versions.

I installed Slicer version 5.0.3 r30893 and tested with IsPointInROI. it works for the newer version

1 Like

The functions are available, but I need some help with the usage.
I have a volume and I want to check which voxels are inside the ROI area.
I assume that the IsPointInROI accepts world space coordinates and not voxel space coords. I tried the transformation but I am not successful.

Do we have an example where we check voxels again a rotated ROI?

With a few rare exceptions (when you access voxels by indices) all 3D coordinates in Slicer are in physical coordinate system. You can transform between them by multiplying the coordinates by the volumes IJK to RAS transformation matrix.

What would you like to achieve? Blank out voxels or compute statistics in a ROI?

My module is a tool to adjust a color volume (three scalars/rgb). I indeed would like to adjust the values within the region of interest. I iterate the voxels x,y,z and need to check if they are inside the roi.

If i understand you correctly, i can get the RAS value of each voxel like you described and use that on the rotated ROI using the IsInside function?

Setting voxel values one by one would be extremely slow.

Instead, you can apply processing in a designated region very efficiently using numpy array indexing: Create a segment in Segment Editor to designate your region of interest (it can be a box shape but it can be a complex, free-form shape, too) and export that into a numpy array. You can then use this array as a mask for numpy operations.