# Computing distance from point to first non-zero voxel in an image

**URL:** https://discourse.itk.org/t/computing-distance-from-point-to-first-non-zero-voxel-in-an-image/5944
**Category:** Beginner Questions
**Created:** [May 15, 2023, 9:29am UTC](https://discourse.itk.org/t/computing-distance-from-point-to-first-non-zero-voxel-in-an-image/5944 "2023-05-15T09:29:10Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![reox](https://discourse.itk.org/user_avatar/discourse.itk.org/reox/32/4490_2.png) [@reox](https://discourse.itk.org/u/reox)
#### Post date: [May 15, 2023, 9:29am UTC](https://discourse.itk.org/t/computing-distance-from-point-to-first-non-zero-voxel-in-an-image/5944/1 "2023-05-15T09:29:10Z")

</div>

Given an voxel based image, a point in physical space and a direction vector (i.e., unit vector): can I somehow compute the distance from that point to the first non-zero voxel in the image in the given direction?  
Ideally available in the Python API 😅 But C++ would also be fine.

I already found the [LineIterator](https://itk.org/Doxygen/html/classitk_1_1LineIterator.html) and it would be possible to calculate a starting and end point in voxel coordinates, then iterate the voxels, find the first non-zero one and calculate the distance. But maybe there is something I missed and such a function is already implemented, especially one that takes physical coordinates and vectors?

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [May 15, 2023, 12:54pm UTC](https://discourse.itk.org/t/computing-distance-from-point-to-first-non-zero-voxel-in-an-image/5944/2 "2023-05-15T12:54:14Z")

</div>

Hello @reox,

A related task, summation of intensities along a ray, is done by the [SiddonJacobsRayCastInterpolateImageFunction](https://github.com/InsightSoftwareConsortium/ITKTwoProjectionRegistration/blob/2cf7d9522031c613a3edcdcd76aee2896536672e/include/itkSiddonJacobsRayCastInterpolateImageFunction.hxx#L95-L392), possibly useful for this case too.

---

<div class="post-metadata">

### Author: ![reox](https://discourse.itk.org/user_avatar/discourse.itk.org/reox/32/4490_2.png) [@reox](https://discourse.itk.org/u/reox)
#### Post date: [May 15, 2023, 3:52pm UTC](https://discourse.itk.org/t/computing-distance-from-point-to-first-non-zero-voxel-in-an-image/5944/3 "2023-05-15T15:52:09Z")

</div>

Thanks for the hint, that looks indeed useful!
