I am new to PsychoPy and I am trying to do something as easy as to plot some images that I have in a folder.
The routine works but the orientation of the images is different - some are correctly oriented and some not… Does anyone know the reason/solution?
Here the part of the code (changing “ori” does not seem to be enough…)
for i in range(len(images)):
img = visual.ImageStim(win=win,image=images[i],units="pix",mask=None, ori = 270,
pos=(0, 0), flipHoriz=False, flipVert=True, size = screen_size)
What does that mean? Does changing the ori value have no effect, or an unexpected effect, or…
We really need to know more detail. It is very hard to judge the code in isolation (e.g. as shown, at the end of the loop, only one imagestim would exist).
Hi Michael,
Thanks for your reply.
By original value I mean the “default” value of 0. I put 270 and others but not all the images are presented in the correct orientation.
Do you know whether the problem might be related to the format of the images? I have them in .png.
# CREATE PRESENTATION OF IMAGES
n_repetition_images = 4
images = [os.path.join(image) for image in
glob.glob('*.jpg')]
images = images * n_repetition_images
shuffle(images) # randomise images
# make sure the same target doesn't appear on consecutive trials
double_stim = False
list_ok = False
while list_ok == False:
for i in range(len(images) - 1):
# check for equal neighbours:
if images[i] == images[i + 1]:
double_stim = True # D'oh!
break # can stop checking on this run
if double_stim == True:
shuffle(images) # try a new order
double_stim = False
else:
list_ok = True # Yay! The loop won't run again.
# PRESENT IMAGES
text_3 = visual.ImageStim(win=win,image=images[trials.thisRepN],units="pix",mask=None, ori = 0,
pos=(0, 0), flipHoriz=False, flipVert=True, size = screen_size)
key_resp = keyboard.Keyboard()
As you said, I am adapting one existing experiment to be able to launch the script on Pavlovia. I have however the same error of image orientation when I display only the images without anything else.
There is no obvious fix to this, as it is not at all clear why the problem would arise. I’d suggest that what you need to do is create an absolutely minimal example (e.g. an experiment with just three images) that shows the issue and share it here so that we could work through it.
I’m not entirely sure of the root of your problem. However, you seem to be creating a new visual object every time which is very inefficient, and they all have the same name which may cause issues.
I would recommend that you only have as many objects as you need objects on screen simultaneously and then update the content and orientation in code using text_3.setImage() and text_3.setOri() (I think)
For multiple images I append them to a list so I can use them in loops.
Hi Michael.
Here is the code that i use to present the images:
# SET THE WINDOW PARAMETERS
screen_size = 1024
win = visual.Window(
size=[screen_size, 768], fullscr=False,
winType='pyglet', allowGUI=False, allowStencil=False,
color=[-1.000,-1.000,-1.000], colorSpace='rgb',
blendMode='avg', useFBO=True,
units='height')
# CREATE AND RANDOMISE IMAGE'S PRESENTATION
n_repetition_images = 4
images = [os.path.join(image) for image in
glob.glob('*.jpg')]
images = images * n_repetition_images
shuffle(images) # randomise images
# randomise images
double_stim = False
list_ok = False
while list_ok == False:
for i in range(len(images) - 1):
# check for equal neighbours:
if images[i] == images[i + 1]:
double_stim = True # D'oh!
break # can stop checking on this run
if double_stim == True:
shuffle(images) # try a new order
double_stim = False
else:
list_ok = True # Yay! The loop won't run again.
# PRESENT IMAGES IN THE LOOP
for thisTrial in trials:
currentLoop = trials
text_3 = visual.ImageStim(win=win,image=images[trials.thisRepN],units="pix",mask=None, ori = 0.0,
pos=(0, 0), flipHoriz=True, flipVert=False, size = screen_size) # screen_size
key_resp = keyboard.Keyboard()
I checked it several times and the images are well presented. I also tried downloading other images from the internet but they are also presented with the wrong orientation.
Haven’t found the error yet…
Well, I do create a list with images that I randomize. Then, in the loop, I select them one by one. As you can see in the code, the orientation is always the same for all the images.I have also tried to play with the text_3 parameters but none appear to have any effect…
Something that I notice is that the variable → units=“pix” in text_3 needs to be in pix. Otherwise, the image is not visible. I wonder whether this might be related to the problem…?
That isn’t complete code (for example, the object trials is not created in it), so we can’t help identify the flaw in it. As suggested, we need to see a working, complete but minimal-size example, with a clear description of the problem and the associated images.
This is not a clear description of the problem (it is internally contradictory).
I have now do as you suggested and upload here below a code that plot the images (only 1 for the shake of rapidity; the field “nbr_stimuli_rep = 1” can be modified to present more).
To make it run, you need to put a couple of images in the directory where you put the code and change of course the directory.
I checked again everything but I am unable to understand why the orientation of the images is not appropriate…mysterious
Hi,
I finally figured it out.
It was a problem of the images size. I just adjusted its length and they are all presented according to the orientation assigned.