# Obtain voxels coordinate of an image

**URL:** https://discourse.slicer.org/t/obtain-voxels-coordinate-of-an-image/7739
**Category:** Support
**Created:** [July 24, 2019, 10:23am UTC](https://discourse.slicer.org/t/obtain-voxels-coordinate-of-an-image/7739 "2019-07-24T10:23:04Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Mohsen\_Taheri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mohsen_taheri/32/4108_2.png) [@Mohsen\_Taheri](https://discourse.slicer.org/u/Mohsen_Taheri)
#### Post date: [July 24, 2019, 10:23am UTC](https://discourse.slicer.org/t/obtain-voxels-coordinate-of-an-image/7739/1 "2019-07-24T10:23:04Z")

</div>

Hi,

I used 3d slicer to segment a part of a brain image (from a \*.nrrd file) and I need to obtain the the voxel coordinates of the segmentation. Actually I need the coordinates of all the inner and boundary voxels as a list like {[x1,y1,z1],…,[xn,yn,zn]} and the order of the coordinates is not important.  
I appreciate if any one could help me.

---

<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: [July 24, 2019, 1:21pm UTC](https://discourse.slicer.org/t/obtain-voxels-coordinate-of-an-image/7739/2 "2019-07-24T13:21:00Z")

</div>

You can export the segmentation as labelmap volume and then voxels as a numpy array using `slicer.util.arrayFromVolume`. If you need voxel IJK coordinates then you can use this [example](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Get_volume_voxel_coordinates_from_markup_fiducial_RAS_coordinates).

Note that storing a segmentation by listing coordinates of all its points is an extremely inefficient representation to read, write, and process. Are you sure this is what you need? What do you plan to do with the coordinate list?

---

<div class="post-metadata">

### Author: ![Mohsen\_Taheri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mohsen_taheri/32/4108_2.png) [@Mohsen\_Taheri](https://discourse.slicer.org/u/Mohsen_Taheri)
#### Post date: [July 24, 2019, 3:50pm UTC](https://discourse.slicer.org/t/obtain-voxels-coordinate-of-an-image/7739/3 "2019-07-24T15:50:39Z")

</div>

Thanks for the quick reply,  
As a matter of fact I need voxelized visualization and in addition I need to use the norm distance between different voxels for some data analysis purpose, for these reasons I considered to have a list of coordinate so I can find for example the mean point of the voxels and etc.

---

<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: [July 24, 2019, 4:23pm UTC](https://discourse.slicer.org/t/obtain-voxels-coordinate-of-an-image/7739/4 "2019-07-24T16:23:44Z")

</div>

Unless you have very sparse data (e.g., few ten points in a grid containing millions of points), computations can be implemented much more efficiently if points are represented in a rectilinear grid rather than as a list of random coordinates. Computing center of gravity, distance map, Hausdorff distance, etc. are all available for labelmap representation and you don’t even need to think about implementing, testing, and maintaining them.

---

<div class="post-metadata">

### Author: ![Mohsen\_Taheri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mohsen_taheri/32/4108_2.png) [@Mohsen\_Taheri](https://discourse.slicer.org/u/Mohsen_Taheri)
#### Post date: [July 24, 2019, 5:01pm UTC](https://discourse.slicer.org/t/obtain-voxels-coordinate-of-an-image/7739/5 "2019-07-24T17:01:22Z")

</div>

Let me be more precise, imagine I have a segmentation and I want to select for example 5 specific points (they are not on the boundary) from the segmentation and then find the mean value of them (call it M), after that I want to measure the distance of all the segmentation’s voxels to the point M  
the questions are

1. How to find the coordinates of the 5 points
2. How to find the coordinates of the segmentation’s voxels

---

<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: [July 24, 2019, 8:09pm UTC](https://discourse.slicer.org/t/obtain-voxels-coordinate-of-an-image/7739/6 "2019-07-24T20:09:54Z")

</div>

> [@Mohsen\_Taheri](#):
>
> How to find the coordinates of the 5 points

You can specify points using markups and use this [script to get IJK coordinates](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Get_volume_voxel_coordinates_from_markup_fiducial_RAS_coordinates).

> [@Mohsen\_Taheri](#):
>
> How to find the coordinates of the segmentation’s voxels

You can export all segments to a merged labelmap and use the script referenced above. Or, slightly modify the script to use segmentation node instead of volume node (the difference is that you need to retrieve VTK image data from the segmentation object stored in the segmentation node; instead of getting it from a volume node).

---

<div class="post-metadata">

### Author: ![Mohsen\_Taheri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mohsen_taheri/32/4108_2.png) [@Mohsen\_Taheri](https://discourse.slicer.org/u/Mohsen_Taheri)
#### Post date: [July 24, 2019, 8:27pm UTC](https://discourse.slicer.org/t/obtain-voxels-coordinate-of-an-image/7739/7 "2019-07-24T20:27:05Z")

</div>

Thank you Andras that was really Helpful 🙏
