# accessing pixel value of a point

**URL:** <https://discourse.itk.org/t/accessing-pixel-value-of-a-point/2765>\
**Category:** Algorithms\
**Created:** [February 26, 2020, 7:52am UTC](https://discourse.itk.org/t/accessing-pixel-value-of-a-point/2765 "2020-02-26T07:52:47Z")\
**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:** [February 26, 2020, 7:52am UTC](https://discourse.itk.org/t/accessing-pixel-value-of-a-point/2765/1 "2020-02-26T07:52:47Z")

</div>

I transformed the image from the index to the physical point.  
Now I want to apply a certain condition to the pointset and set the corresponding pixel value to a new value.

I know that we can access or set pixel value through

```
image->GetPixel(pixelIndex);
image->SetPixel(pixelIndex, pixelValue);

```

I want to know a way of accessing the pixel value of a point and set it to a new value.

---

<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:** [February 26, 2020, 2:09pm UTC](https://discourse.itk.org/t/accessing-pixel-value-of-a-point/2765/2 "2020-02-26T14:09:08Z")

</div>

Hello @EE18D504_SINDHURA_C,

The method you are looking for is [TransformPhysicalPointToIndex](https://itk.org/Doxygen/html/classitk_1_1ImageBase.html#a5c4f893aff7e68ffdc6ec4d6f592bb18):

```auto
image->SetPixel(image->TransformPhysicalPointToIndex(myPoint), pixelValue);

```

One thing to note, the returned index may be outside the image bounds, so SetPixel may throw an exception. It all depends on the parameter value `myPoint`, as long as it is inside the image bounds you are ok.
