Upon rendering I store an image containing pass_index property as a 16 bit, single channel. However upon loading this image using bpy.data.images.load it returns a 4 channel image.

My issue is that I need to access the pass_index property from the image once again, but I am unable to find those values in the 4 channel image. So how do I get the pass_index values again?

I use the following code

maskPath            = Path()
maskImg             = bpy.data.images.load(str(maskPath))
width, height       = maskImg.size[0], maskImg.size[1]
print ('\n width: {}, height: {}'.format(width, height))

imgArray            = np.array(maskImg.pixels[:], dtype=np.float32).reshape(height, width, 4)
print (np.unique(imgArray))

Note: I am able to load this image from a different python terminal using non-Blender image loading techniques and am able to access the pass_index values.

  • $\begingroup$ Hello. Don't the 4 channels of each pixel contain the same value duplicated 4 times ? $\endgroup$
    – Gorgious
    Apr 30, 2023 at 9:33
  • $\begingroup$ Yes, they do. But when you read the values they are not the pass_index values that I actually have. $\endgroup$
    – prerakmody
    May 5, 2023 at 16:08
  • $\begingroup$ you seem to decode the values as 32 bit float but you stored it as a 16 bit float. Could that cause an issue ? $\endgroup$
    – Gorgious
    May 5, 2023 at 16:17


You must log in to answer this question.

Browse other questions tagged .