psychopy.org | Reference | Downloads | Github

Go/No-Go task can't get image to display

images

#1

Hi there!

I am super new to psychopy and also coding in general and I am having trouble making an image appear in my task.
To create a go no go task I have been using existing code from GitHub for a go no-go task and trying to edit the code to suit our purposes but I have not been able to get an image to display instead of the string variable that was displayed at this point in the task previously.
I defined the image here (which is where the string variable was previously defined)

# Setup the Window
win = visual.Window(
    size=(1024, 768), fullscr=True, screen=0,
    allowGUI=False, allowStencil=False,
    monitor='testMonitor', color=[0,0,0], colorSpace='rgb',
    blendMode='avg', useFBO=True)

GO_TRIAL_IMAGE = visual.ImageStim(
    win=win, name='GO_TRIAL_IMAGE',
    image='snake.jpg', mask=None,
    ori=0, pos=(0, 0), size=(0.5, 0.5),
    color=[1,1,1], colorSpace='rgb', opacity=1,
    flipHoriz=False, flipVert=False,
    texRes=128, interpolate=True, depth=0.0) 

and later I try to call the image here

 # based on trial type create appropriate stimuli
    if(CURRENT_TRIAL == 'G'):
        EXP_STIM = visual.ImageStim(win,GO_TRIAL_IMAGE)
    elif(CURRENT_TRIAL == 'NG'):
         EXP_STIM = visual.TextStim(win,NOGO_TRIAL_STRING)
    # draw stimuli
    EXP_STIM.draw()
    win.flip()
    STIM_ONSET_TIME = time.time()  

These are the only things in the code that i have changed the rest is the same as the code I have been editing which works perfectly

I keep getting the following error message:
AttributeError: Couldn’t make sense of requested image.

The more detailed error message is
25.9193 ERROR Couldn’t make sense of requested image.
Traceback (most recent call last):
File “/Applications/PsychoPy3.app/Contents/Resources/lib/python3.6/psychopy/visual/basevisual.py”, line 827, in _createTexture
im = tex.copy().transpose(Image.FLIP_TOP_BOTTOM)
AttributeError: ‘ImageStim’ object has no attribute ‘copy’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

EXP_STIM = visual.ImageStim(win,GO_TRIAL_IMAGE)

File “/Applications/PsychoPy3.app/Contents/Resources/lib/python3.6/psychopy/visual/image.py”, line 102, in init
self.setImage(image, log=False)
File “/Applications/PsychoPy3.app/Contents/Resources/lib/python3.6/psychopy/visual/image.py”, line 301, in setImage
setAttribute(self, ‘image’, value, log)
File “/Applications/PsychoPy3.app/Contents/Resources/lib/python3.6/psychopy/tools/attributetools.py”, line 141, in setAttribute
setattr(self, attrib, value)
File “/Applications/PsychoPy3.app/Contents/Resources/lib/python3.6/psychopy/tools/attributetools.py”, line 32, in set
newValue = self.func(obj, value)
File “/Applications/PsychoPy3.app/Contents/Resources/lib/python3.6/psychopy/visual/image.py”, line 288, in image
forcePOW2=False)
File “/Applications/PsychoPy3.app/Contents/Resources/lib/python3.6/psychopy/visual/basevisual.py”, line 832, in _createTexture
raise AttributeError(msg)
AttributeError: Couldn’t make sense of requested image.
e


#2

Hi @hayley13, instead of

if(CURRENT_TRIAL == 'G'):
    EXP_STIM = visual.ImageStim(win,GO_TRIAL_IMAGE)
elif(CURRENT_TRIAL == 'NG'):
    EXP_STIM = visual.TextStim(win,NOGO_TRIAL_STRING)

try

if(CURRENT_TRIAL == 'G'):
    EXP_STIM = GO_TRIAL_IMAGE
elif(CURRENT_TRIAL == 'NG'):
    EXP_STIM = NOGO_TRIAL_STRING

In your code, you have already created the visual objects in the first block of code, but in the second block you are attempting to create the objects using objects, which does not work.


#3

This worked, thank you so much.