# Extract points from vtkImageData

**URL:** <https://discourse.slicer.org/t/extract-points-from-vtkimagedata/11054>\
**Category:** Development\
**Created:** [April 9, 2020, 10:58am UTC](https://discourse.slicer.org/t/extract-points-from-vtkimagedata/11054 "2020-04-09T10:58:26Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![loubna](https://avatars.discourse-cdn.com/v4/letter/l/cab0a1/32.png) [@loubna](https://discourse.slicer.org/u/loubna)\
**Post date:** [April 9, 2020, 10:58am UTC](https://discourse.slicer.org/t/extract-points-from-vtkimagedata/11054/1 "2020-04-09T10:58:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sam\_Horvath](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sam_horvath/32/3092_2.png) [@Sam\_Horvath](https://discourse.slicer.org/u/Sam_Horvath)\
**Post date:** [April 9, 2020, 2:11pm UTC](https://discourse.slicer.org/t/extract-points-from-vtkimagedata/11054/2 "2020-04-09T14:11:44Z")

</div>

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](https://vtk.org/doc/nightly/html/classvtkImageData.html#aa37a2184cb38394a8828d4998f0628fc)

---

<div class="post-metadata">

**Author:** ![loubna](https://avatars.discourse-cdn.com/v4/letter/l/cab0a1/32.png) [@loubna](https://discourse.slicer.org/u/loubna)\
**Post date:** [April 9, 2020, 2:58pm UTC](https://discourse.slicer.org/t/extract-points-from-vtkimagedata/11054/3 "2020-04-09T14:58:21Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![Sam\_Horvath](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/sam_horvath/32/3092_2.png) [@Sam\_Horvath](https://discourse.slicer.org/u/Sam_Horvath)\
**Post date:** [April 9, 2020, 3:25pm UTC](https://discourse.slicer.org/t/extract-points-from-vtkimagedata/11054/4 "2020-04-09T15:25:07Z")

</div>

That would also work.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [April 9, 2020, 5:12pm UTC](https://discourse.slicer.org/t/extract-points-from-vtkimagedata/11054/5 "2020-04-09T17:12:16Z")

</div>

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_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](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Get_volume_voxel_coordinates_from_markup_fiducial_RAS_coordinates)

---

<div class="post-metadata">

**Author:** ![loubna](https://avatars.discourse-cdn.com/v4/letter/l/cab0a1/32.png) [@loubna](https://discourse.slicer.org/u/loubna)\
**Post date:** [April 10, 2020, 5:51pm UTC](https://discourse.slicer.org/t/extract-points-from-vtkimagedata/11054/6 "2020-04-10T17:51:33Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [April 10, 2020, 11:47pm UTC](https://discourse.slicer.org/t/extract-points-from-vtkimagedata/11054/7 "2020-04-10T23:47:30Z")

</div>

> [@loubna](#):
>
> vtkVariant variant = labelMapBoundry-\>GetPointData()-\>GetScalars()-\>GetVariantValue(labelMapBoundry-\>computePointId(ijk\_coords);

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