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

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. :slight_smile:

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

Hello @constantine !

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

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

val = np.uint8(34)

image[0,0] = val
2 Likes