Extract points from vtkImageData

Hi,

My question is how can I extract points from vtkImageData. For example, considering 3D image(labelMap), if in voxels there are 3 voxel values, I would get the coordinates of those voxels.

vtkImageData->getPoint() return the point coordiantes in physical space. However I want the point coordinates in ijk space then convert them to RAS space.

Thank’s in advance

To get the coordinates in index space [ijk], You would use
vtkImageData->TransformPhysicalPointToContinuousIndex(point[3], index[3])

See: https://vtk.org/doc/nightly/html/classvtkImageData.html#aa37a2184cb38394a8828d4998f0628fc

Thank’s for the response. What about if I takes I,J,K voxel coordinates directly? where

vtkImageData-- >GetExtent(Kmin,Kmax,Jmin,Jmax,IMin,Imax)

i in range (kmin, kmax)
j in range (jMin,Jmax)
k in range (iMin,Imax)

That would also work.

There are also a few complete examples in script repository, for example:

https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Get_value_of_a_volume_at_specific_voxel_coordinates

https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Get_volume_voxel_coordinates_from_markup_fiducial_RAS_coordinates

2 Likes

Thank’s for your responses.

I will try to clarify more my issue.

I have a label Map (vtkImage Data) on which I have applied “vtkImageLabelOutlines” filter to keep only labelMap boundries.

What I want is to recover the 3D points corresponding to labelMap boundries labelMapBoundry) and store them in vtkPoints array

I am trying athe following test, but I don’t know if it can resolve the issue:

vtkVariant variant = labelMapBoundry->GetPointData()->GetScalars()->GetVariantValue(labelMapBoundry->computePointId(ijk_coords);

if(variant==1)
then store (i,j,k).

I don’t understand this. You can convert between voxel and physical coordinates as described in the script repository examples I linked above.