# itkImageUC2.SetPixel(index, value) Does Not Like numpy.uint8 Values, which are \[0, 255\] As Expected

**URL:** <https://discourse.itk.org/t/itkimageuc2-setpixel-index-value-does-not-like-numpy-uint8-values-which-are-0-255-as-expected/6694>\
**Category:** Uncategorized\
**Created:** [June 12, 2024, 4:52am UTC](https://discourse.itk.org/t/itkimageuc2-setpixel-index-value-does-not-like-numpy-uint8-values-which-are-0-255-as-expected/6694 "2024-06-12T04:52:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![constantine](https://discourse.itk.org/user_avatar/discourse.itk.org/constantine/32/3915_2.png) [@constantine](https://discourse.itk.org/u/constantine)\
**Post date:** [June 12, 2024, 4:52am UTC](https://discourse.itk.org/t/itkimageuc2-setpixel-index-value-does-not-like-numpy-uint8-values-which-are-0-255-as-expected/6694/1 "2024-06-12T04:52:19Z")

</div>

Hello Everyone,

Say, in Python I have a numpy.uint8 value within [0, 255] range, but Python’s ITK bindings are quick to point out:

TypeError: in method ‘itkImageUC2\_SetPixel’, argument 3 of type ‘unsigned char’

And, when I have to cast the uint8 to an int, which is not pretty and a bit fishy, just between us. 🙂

Is there a better way of passing unsigned char values to SetPixel?

---

<div class="post-metadata">

**Author:** ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)\
**Post date:** [July 19, 2024, 7:25pm UTC](https://discourse.itk.org/t/itkimageuc2-setpixel-index-value-does-not-like-numpy-uint8-values-which-are-0-255-as-expected/6694/2 "2024-07-19T19:25:06Z")

</div>

Hello @constantine !

The following is more efficient computationally and a more direct syntax:

```python
image = itk.imread('cthead1.png')

val = np.uint8(34)

image[0,0] = val

```
