Randomly select image stimuli within certain combinations

OS: Win10
PsychoPy version : 2021.1.2
**Standard Standalone? : y
What are you trying to achieve?:

I’m trying to set the image stimuli condition of different levels(A,B,C) and also different types(1,2).

Q0308_1

What I’d like to do is to present 6 stimuli of these combination (1,A), (1,B), (1,C), (2,A), (2,B), (2,C) among them in a random order, but every combination has to appear once.

However, as you can see, there are two stimuli images in each level for each type (for instance, row2 and row3 are both Type=1 & Level=1 stimuli).
I can’t figure it out how to randomly select one of those two stimuli for every combination, also in a random order.

It would be really helpful if anyone shares any idea about this…!
Thanks!!

The easiest way to do this is to have 7 rows in your spreadsheet instead of 13 with Path1 and Path2 containing the two image options.

Then in your experiment you could add a code component with the following in Begin Routine

if random()>.5:
     Path=Path1
     thisExp.addData('Path',1)
else:
     Path=Path2
     thisExp.addData('Path',2)
1 Like

Thanks for your comment…!

However, it’s still a bit confusing.
Is this what you mean by having 7 rows with Path1 and Path2?




What I’d like to achieve is to show 6 combinations of images [ (Type = 1, Level = A), (1,B), (1,C), (2,A), (2,B), (2,C) ] in a random order.

So, for every Type=1 images, 3 images of each Level A, B, C should be selected once, as well as for every Type=2 image.

In sum, total 6 images will be shown in a random order which corresponds to every combination, no overlap.

Hope to get your response soon…!!
Best wishes,

That wasn’t the spreadsheet I was imagining.

stimuli/1.PNG and stimuli/2.PNG should be in the same row because you want only one of the two of them to be shown. You still need a Type column.

1 Like

Oh I see…!

I changed the spreadsheet like this below, but then how can I set the path of image ?
Q0309_1

When there’s only one path, I could set up the image path like ‘$Path’.
In this case, I have two path columns and how should I assign the image path that corresponds to the random selection by code (path1 or path2) ?


Thank you so much...!!

Sincerely,

You need to do this in a code component.

1 Like

Thank you so much…! It worked perfectly !!
I really appreciate your time and efforts.
Thank you again.

Best wishes,

Hello, thank you for the helpful message. What if you have more than 2 paths how would you change the code?
in my case,
6 for images:
(image1 image2, image3,… image6) and

6 for words:
(word1, word2,… word6)
I want to randomly select one of the images and one of the words and simultaneously show one image and one word on the screen.

You could have

columnChoice = [1,2,3,4,5,6]

shuffle(columnChoice)
thisExp.addData('imageN',columnChoice[0])
if columnChoice == 1:
     thisImage = image1
elif columnChoice == 2:
     thisImage = image2
elif columnChoice == 3:
     thisImage = image3
elif columnChoice == 4:
     thisImage = image4
elif columnChoice == 5:
     thisImage = image5
elif columnChoice == 6:
     thisImage = image6

then repeat for the words

Thank you!

Begin Exp:
image_list = [ ]
word_list = [ ]

This gives error : thisImage = image_list.append(image1, image2, image3, image4, image5, image6)
thisWord = word_list.append (word1, word2, word3, word4, word5, word6)
How am I going to define each column?
what is the image path for the Image component? what should I write there?

Thank you!

Begin Exp:
image_list = [ ]
word_list = [ ]

This gives error : thisImage = image_list.append(image1, image2, image3, image4, image5, image6)
thisWord = word_list.append (word1, word2, word3, word4, word5, word6)
How am I going to define each column?
what is the image path for the Image component? what should I write there?

Why are you appending?

I’m assuming that image1-image6 are names of your columns. That could include the path or you could add that in the code thisImage = 'images/'+image6+’.jpg’

Yes, image1-6 are the column names. Also I have word1-6 column names

thisImage = 'images/'+image6 +’.png’ it gives Syntax Error

++ What am I going to do for the word list

Check your quotes. They need to be 'dumb', not ‘smart’.

shuffle(columnChoice)
thisExp.addData('wordN',columnChoice[0])
if columnChoice == 1:
     thisWord = word1
elif columnChoice == 2:
     thisWord = word2
elif columnChoice == 3:
     thisWord = word3
elif columnChoice == 4:
     thisWord = word4
elif columnChoice == 5:
     thisWord = word5
elif columnChoice == 6:
     thisWord = word6

thisImage = ‘images/’+image6 +’.png’
NameError: name ‘image6’ is not defined
still gives error :confused:

I meant how to define thisWord = …
as you did for thisImage

Are you trying to set thisImage before you reach the loop pointing at your spreadsheet with a column called image6?

Since this topic has been solved, then I’d recommend that you start a new thread that refers back to it, with more detailed information of what you have tried if you want more support.

Please visit here: Simultaneous presentation of image and word randomization problem