waitKeys () # press space to continue win. text = "Showing image from numpy array" image_stim. colorSpace = "rgb1", # img_as_float converts to 0:1 range, whereas PsychoPy defaults to -1:1. shape, ), # here's a gotcha: need to pass the size (x, y) explicitly. ImageStim ( win, image = image_np, units = "pix", size = ( image_np. flip ( image_np, axis = 0 ) image_stim = visual. # flip image (row-axis upside down so we need to reverse it): image_np = np. See the img_as_float # function of scikit image for a more careful conversion. # Note this float conversion is "quick and dirty" and will not # fix potential out-of-range problems if you're going # straight from a numpy array. Attention, Perception, & Psychophysics, 63, 13771388., or the PsychoPy tutorial at In this example, we use an adaptive staircase experiment to determine the minimal amount of noise that makes the participant unable to distinguish between two audio fragments, bat and bet ( bat.wav, bet.wav ). float ) / 255.0 ) # convert to float in 0-1 range, assuming image is 8-bit uint. array ( pil_image, order = "C" ) # convert to numpy array with shape width, height, channels image_np = ( image_np. open ( path_to_image_file ) image_np = np. PsychoPy has an internal # "image2array" function but this only handles single-layer (i.e. Here I use the Python Imaging Library for image loading, # and a conversion function from skimage. waitKeys () # press space to continue # - # Example 2: convert image to numpy array # Perhaps you want to convert an image to numpy, do some things to it, # and then display. TextStim ( win, text = "Showing image from file", pos = ( 0.0, 0.8 ), units = "norm", height = 0.05, wrapWidth = 0.8, ) image_stim. ImageStim ( win, image = path_to_image_file ) text_stim = visual. # you could replace with path to any image: path_to_image_file = Path () / "PsychoPy2_screenshot.png" # simply pass the image path to ImageStim to load and display: image_stim = visual. Window ( ( 900, 900 ), screen = 0, units = "pix", allowGUI = True, fullscr = False, ) # - # Example 1: load a stimulus from disk # - # assume we're running from the root psychopy repo. From pathlib import Path import numpy as np from PIL import Image from psychopy import core, event, visual # - # Setup window # - win = visual.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |