# Code to access specific voxels

**URL:** <https://discourse.itk.org/t/code-to-access-specific-voxels/2639>\
**Category:** Algorithms\
**Created:** [January 20, 2020, 10:04am UTC](https://discourse.itk.org/t/code-to-access-specific-voxels/2639 "2020-01-20T10:04:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![EE18D504\_SINDHURA\_C](https://discourse.itk.org/letter_avatar_proxy/v4/letter/e/b3f665/32.png) [@EE18D504\_SINDHURA\_C](https://discourse.itk.org/u/EE18D504_SINDHURA_C)\
**Post date:** [January 20, 2020, 10:04am UTC](https://discourse.itk.org/t/code-to-access-specific-voxels/2639/1 "2020-01-20T10:04:49Z")

</div>

I have a 3D image and a sphere equation. I need to take out all the voxels that are outside the circle and want to apply a transformation to them. How do I differentiate those points from all the points? I’m not understanding how to actually write the code to access each voxel that satisfies my criteria.

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [January 20, 2020, 2:49pm UTC](https://discourse.itk.org/t/code-to-access-specific-voxels/2639/2 "2020-01-20T14:49:47Z")

</div>

Start from this [iterator example](https://itk.org/ITKExamples/src/Core/Common/IterateRegionWithAccessToIndexWithWriteAccess/Documentation.html). Use `image->TransformIndexToPhysicalPoint()` . Apply your sphere equation to physical point coordinates to determine whether a pixel is inside or outside. If you want to modify pixel values, `it.Set(newValue);` should do it. Possibly look at other [iterator examples](https://itk.org/ITKExamples/src/Core/Common/index.html).
