Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

trying to manipulate an image within opensesame and display it

edited April 2021 in OpenSesame

Hi, I have an inline code which manipulates a jpeg and saves it , the code is below and it works

________________

import os
from PIL import ImageEnhance  
from PIL import Image,ImageFilter   
ruta= "/Users/dsb/Nextcloud/pythonR/image-processing" 
im = Image.open(os.path.join(ruta) + '/numbers.jpeg')  
enh = ImageEnhance.Contrast(im)  
pepe =  enh.enhance(0.2)
pepe.save(os.path.join(ruta) + '/imagenumbers.jpeg')
var.pepeim = str(os.path.join(ruta) + '/imagenumbers.jpeg')
print (pepeim) 

__________________

then subsequently I try to load the saved image using the sketchpad, and the script section I have

_________________

set duration keypress
set description "Displays stimuli"
draw image center=1 file="[pepeim]" scale=1 show_if=always x=0 y=0 z_index=0

________

however I can not make it work, OS does not recognise the file, I have tried with [pepeim] but it does not see it


any advise will be appreciated!


cheers,

david

Comments

  • Hi David,

    Could it be a problem with the prepare-run strategy? So, have you put the code in the prepare phase of your script? Alternatively, you can try to use a feedback item and not a sketchpad.

    I suppose you checked whether the image actually appeared at the location you saved it to? Ideally the same working directory as your current experiment's location.

    Eduard,

    ps. to improve readability of your code, you could try to format your text (see the little paragraph symbol on the line that you are currently typing (use code Block). I formatted your text already.


    Buy Me A Coffee

  • Hi, I still can not get it to work even in the prepare mode...I get:

    exception message: name 'pepeim' is not defined

    I have attached the files if you could kindly take a look?

    thanks!

    david

  • Hi David,

    when specifying the file in the sketchpad, make sure to use square brackets. So in case, you save your file as var.pepeim , you have to use [pepeim] in the sketchpad. Also make sure to save the image in the same directory as your experiment resides.

    Finally, print (pepeim) will throw an error, because it does not exist. What does exist is var.pepeim . Keep this in mind. var.pepeim and pepeim , are two entirely different objects as far as Opensesame is concerned.

    Hope this helped.

    Eduard

    Buy Me A Coffee

  • yes it works, thanks so much!

Sign In or Register to comment.