Reputation: 33
I want to program a visual search task in which participants are presented with a visual scene and have to identify a target object by clicking on it, at which point the trial ends. For each visual scene with embedded target (visual scene stimuli) I have an accompanying image that is completely blank except for the target (target stimuli), which is black, and in the same exact position as it is in the visual scene stimuli.
I have already created trials in which python pulls a visual scene from an image bank and presents it to participants, like so..
for i in range(numTrials):
theTrial = trialOrder[i] # grab pre-shuffled trial index
win.flip()
core.wait(1.0) # wait one second
living_images[i].draw()
However, I do not know how to create an area of interest for the target for each visual scene stimuli and to make a trial end if that portion is clicked.
I imagine i should create a CSV with the visual scene stimuli in one column and the target in another column, then tell python to create an area of interest for each visual scene stimuli based on the RGB value of each corresponding target image(since they are blank except for black target in the same position as in the visual scene stimuli).
Upvotes: 3
Views: 80
Reputation: 1260
I don't know how you are setting up your UI and how the user is supposed to interact with the images, but if your scene image and the accompanying target image is the same size you can use the accompanying image as a mask.
Have the user click on the image (visual scene) and catch the position they choose. Then check the value of the accompanying target image at that position. If the value is 1 (or 0 depending on your choice of "active" value) you get a hit and move on. Basically, you can use your target images as ROI.
edit: Here is a small example of how it could be done
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots()
ax.imshow(mask)
mask = np.zeros((50,50))
mask[5:10,5:10]=1
xi = 0
yi = 0
def onclick(event):
global xi,yi,mask
xi,yi = event.xdata,event.ydata
if mask[int(xi),int(yi)]>=1:
print('inside')
else:
print('outside')
cid = fig.canvas.mpl_connect('button_press_event', onclick)
The image shown doesn't have to be the mask image, but whatever scene you wish to show. For more on this check https://matplotlib.org/users/event_handling.html.
Upvotes: 1