psychopy.org | Reference | Downloads | Github

Random selection of single image from pool

Hi,

I’m a student designing a study and am new to PsychoPy. I’ve been able to randomize the order of stimulus presentation within a routine, but want to select a single image at random to present. How would I go about doing that? Do I explicitly need to code or can this be done in Builder?

Best,
Rishi

Hi Rishi,
This is a little bit of a vague question so I don’t have a great idea of how to help, so if you could provide more detail of exactly what you are looking for that would be great.
My first thought though is that you would benefit from using a loop around a single routine, placing your images in a conditions file, so that every time psychopy iterates through this loop it selects a new image indicated by this conditions file.
If that seems like what you are going for I am happy to provide more details on how to do that, just wanted to give a more generalized answer until we pin down exactly what process you are trying to create.

Hi,

Thanks for your response. I’m trying to select a single image randomly from a set of images to present in a block. So far I have been able to randomize order, but all of the images show up instead of just one, which is what I want. Hope this helps clarify what I’m looking to do.

Sorry, that is still really vague. Do you want all the images to come up for a set amount of time, or 1 on each trial where you loop over each trial?
Generally to solve this type of problem you would have a routine in builder that is setup to show a single image. Then you would build a loop around this image, with a conditions file that contains the file names of all the images you would like to show (this conditions file is a separate csv file that you select in your loop settings in psychoPy). You then set your Image path (in your image stimuli) to $VariableNameHere, where VariableNameHere is whatever the header is for the image files in your conditions file (the .csv file). By default PsychoPy has the loop settings on random, so it will automatically randomly order the presentation of the images
Hopefully that gives you some understanding of how to approach this. If not you might need to look at some of the demos and tutorials on using psychopy to better understand the use of loops and conditions files.

I’m trying to make 1 image come up for a set amount of time; I’ll go ahead and try the solution you proposed.

This ended up working out, thanks for your help

1 Like