Howdy, Stranger!

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

Supported by

[solved] image display speed

edited October 2013 in OpenSesame

hey
I am building my third exp/ in opensesame and the program is great
in my new exp i want to display an image that looks like it is coming to or from the viewer
I used the scale image option but the problem is that the image animation is not smooth but "jumps"
I attached the image display code
would appreciate you help


https://gist.github.com/anonymous/6963547

Comments

  • edited 2:04PM

    Hi Dror,

    I see. In principle your approach is fine: Simply draw a series of frames that scale the image differently. But your implementation may be too slow, which is why it jumps. The easiest way to make the process faster is to construct all canvas objects first, and then show them one after another. That way the animation won't be slowed down by the canvas preparation time. For example:

    import numpy as np
    from openexp.canvas import canvas
    
    # Create an array (numpy list) of scaling factors
    # from 0.5 to 1 in 20 steps.
    scale_array = np.linspace(0.5, 1, 20)
    
    # The full path to the image in the file pool
    my_image = exp.get_file('image.png')
    
    # Create a list of canvas objects with differently
    # scaled images.
    canvas_list = []
    for scale in scale_array:
        my_canvas = canvas(exp)
        my_canvas.image(my_image, scale=scale)
        canvas_list.append(my_canvas)
    
    # Show the canvas objects one after another!
    for my_canvas in canvas_list:
        my_canvas.show()
    

    Alternatively, you can directly use the PsychoPy or Expyriment functions, which allow you to scale images as well. This will probably be even more efficient, but I doubt that it will be necessary in this case:

    Cheers!
    Sebastiaan

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

  • edited 2:04PM

    hi
    I used the array and it works better(the animation itself)
    but.
    every trail is a different stim and it takes 5-8 seconds before every trail starts
    is there a way to speed things up
    I have a fixation of 1 second before every animation and scaling procedure after every stim in every trail
    dror

  • edited 2:04PM

    As I mentioned, an alternative would be to use PsychoPy directly. PsychoPy allows you to change the size of the object on the fly, without requiring you to prepare each frame separately. The downside is (or could be) that you are tied to the psycho back-end when you use this approach:

    from psychopy.visual import ImageStim
    import numpy as np
    from scipy.misc import imread
    
    # Create an array (numpy list) of scaling factors
    # from 0.5 to 1 in 10 steps.
    scale_array = np.linspace(0.5, 1, 100)
    
    # The full path to the image in the file pool
    my_image = exp.get_file('image.png')
    
    # Get the size of the image by reading into a numpy array
    # and getting the shape of the array
    height, width = imread(my_image, flatten=True).shape
    
    # Create an ImageStim object
    img = ImageStim(win, image=my_image)
    
    # Repeatedly show the image and change the size on each
    # showing
    for scale in scale_array:
        img.setSize( (width*scale, height*scale) )
        img.draw()
        win.flip()
    

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

  • edited 2:04PM

    works like a charm/
    thank you/

Sign In or Register to comment.