| Reference | Downloads | Github

Displaying images stored as numpy array


How do I display gray-scale images available as 2D numpy array? I think this was discussed on the old forum, but I can’t find the solution anymore. Thanks.

#2 ?


Indeed, GratingStim should work with gray-scaled images. Is there a more general method that will work with full color image, ie. when a matrix for each of the RGB channels is provided?
ATM, the imshow method from opencv library seems to better fit what I’m trying to achieve.


ImageStim and GratingStim can both take RGB numpy arrays. GratingStim is appropriate if you want multiple cycles of your image/texture and ImageStim is for when you don’t.


What these do better than imshow is they load your array onto the graphics card in advance (so timing is good) and can then modify the shape/position/size/opacity/… on the fly with minimal overhead.


I would prefer ImageStim, but how do I supply the numpy array to the constructor? Should I just link it with the image keyword instead of the filename string?

EDIT: Ok, so it seems that ImageStim constructor accepts numpy array as image argument