I am using a grayscale image as a numpy array as the “image” keyword argument for the ImageStim constructor. I use PIL to read the images and convert them to grayscale (0 - 255), but I keep getting a warning that says: “WARNING : numpy arrays used as textures must be in the range of -1:1” or something along these lines, and the images are just totally mangled on the display (they appear mostly red with some black). I tried re-scaling the images using sci-kit learn’s exposure module (see the code below), and I verified that the minimum and maximum values in these arrays are -1 and +1 respectively; however, I still get this warning, and pixels with an intensity of exactly -1 are displayed as blue. Can someone explain this behavior to me and help me find a solution? Here is a minimal example of how I process the images and create the stimulus:
import numpy as np
from PIL import Image
from skimage import exposure
from psychopy import visual
tif = <some image file>
image = np.array(Image.open(tif).convert('L')) # only 2 dimensions
image_rescaled = exposure.rescale_intensity(image, in_range=(0, 255), out_range=(-1, 1))
win = visual.Window()
stim = visual.ImageStim(win, image=image_rescaled)
I’m using psychopy version 2020.1.2