![]() 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. View Methods.docx from SOCIAL PSY 830 at Rutgers University. # 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. For example, to draw a line from the bottom left to the top. The two critical arguments to create a line are start and end, which are each two-item lists that specify the x and y coordinates of the start and end points of the line, respectively. float ) / 255.0 ) # convert to float in 0-1 range, assuming image is 8-bit uint. Perhaps the most simple shape stimulus is a line, which we can create in psychopy using Line. 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. from psychopy import visual, core setup stimulus win visual. ![]() 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. |