Dispay Images Randomly from folder

1,181 views
Skip to first unread message

Ahmed Almurshedi

unread,
Oct 21, 2013, 11:13:00 PM10/21/13
to psychop...@googlegroups.com

Hello All,

Thanks for such great
psychopy software ..

I'm new to work with psychopy and python language, Im trying to design my visual stimulation for ERP experiment. I tried to do my task and display individual images on time line.

My question is how about if i want to call display multiple images from folder randomly?


thanks

Zsolt

unread,
Oct 22, 2013, 3:41:54 AM10/22/13
to psychop...@googlegroups.com
Hello Ahmed,

you can display images randomly by inserting a loop around your routine and select loopType to 'random'.
Don't forget to define the relative path of the folder containing your images in your xlsx or csv loop file, for example (on Win): stim/image1.jpg, stim/image2.jpg...where 'stim' is the subfolder of your experiment folder, where all of your images are located.

Hope it was helpful for you!
Zsolt

Ahmed Almurshedi

unread,
Oct 22, 2013, 9:14:36 PM10/22/13
to psychop...@googlegroups.com
Hello Zsolt,

OK, that means we have to load all images one by one even if we have 50 image!

Is there any other way to display images from folder randomly?
can you please give me an example of display images from folder


Thanks a lot,
Ahmed

Jared Roberts

unread,
Oct 22, 2013, 9:38:00 PM10/22/13
to psychop...@googlegroups.com
Hi Ahmed,

The method described is probably the most straight forward method if you're using the builder.  By "loading images one by one" do you mean putting them into the conditions file?  It would be trivial to write a python script to do that.  In fact, here it is:

import os

outfile = open("myoutput.csv",'w')

 #Set this to whatever subfolder inside of your experiment folder has the images.  Leave it blank if they aren't in a subfolder.
relativePath = "stim/"

for image in os.listdir("C:/MyImagePath"):
   outfile.write("%s\n" %(relativePath + image)

outfile.close()




Just stick that in the coder, plug in your image paths, save the script somewhere, and run it.  Then open up myoutput.csv in excel and you can copy and paste into your conditions file.

--
Jared Roberts
Graduate Student
The Yassa Learning and Memory Laboratory
Johns Hopkins University
"A lost cause can be as spiritually satisfying as a victory." - Robert Heinlein
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages