Howdy, Stranger!

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

Supported by

[solved] Easy way to use a lot of photos?

edited September 2014 in OpenSesame

Hi,
I already posted this question a couple of days ago but I can't find the discussion anymore.
I am making an experiment which uses a lot of photos (over 2000). The way I understand it, the only way to use these photos is to drag them to the file pool, but to use them in a loop you have to enter each file name manually. I was wondering, is there a way to just direct openSesame to a folder outside of the openSesame environment and program something like 'for this loop, use random photos from this folder'? That would help me a lot.
Thanks,
Floor

Comments

  • edited 12:29PM

    I have exactly the same request :)
    We have a set of 3500 fractals, and a lot of variation of the code.
    The hard drive is quite full... :p

  • edited 12:29PM

    Hi, I already posted this question a couple of days ago but I can't find the discussion anymore.

    Technical issues, sorry. But we're back online now!

    Yes, you can certainly read images from a folder. OpenSesame doesn't just accept files from the file pool, it also looks in the experiment folder, and accepts relative and absolute paths.

    In your case, what you could do is build a list of images at the start of your experiment. Something like this:

    import os
    import random
    # Specify the folder with your images
    my_image_folder = '/home/sebastiaan/Pictures'
    # Walk through all files in this folder ...
    my_image_list = []
    for fname in os.listdir(my_image_folder):
        # ... but only take those that end with .png. Change this to .jpg,
        # .bmp, etc. as required.
        if fname.endswith('.png'):
            # Add the full path (i.e. including the folder) of the image to
            # a list.
            path = os.path.join(my_image_folder, fname)
            my_image_list.append(path)
    # Shuffle the list
    random.shuffle(my_image_list)
    # Print it out so we can see in the debug window. This way you can check
    # if things work as expected.
    print my_image_list
    

    Once you have this list (my_image_list), you can simply take one item from the top at the beginning of every trial. Like so (in the prepare phase on an inline_script):

    # Take the last image from the list ('pop').
    image = my_image_list.pop()
    # And set it as an experimental variable.
    exp.set('image', image)
    

    Because you've set image as an experimental variable, you can log it, use it in a sketchpad, etc.

    See? Not that hard, really.

    Cheers!
    Sebastiaan

  • edited 12:29PM

    Thank's a lot :) I'll try as soon as possible

  • edited 12:29PM

    Yes, thank you! This helps a lot.
    However, with each photo, there is also a correct keyboard response. Is there a way to link a correct keyboard response to a particular picture this way?

  • edited 12:29PM

    so, to clarify: can I implement something that says "if the filename ends with 3.jpg the correct keybord response is 3"?

  • edited 12:29PM

    Nevermind, I found a way which works! (after a little bit of testing).
    for those who are interested:
    after
    exp.set('image', image)
    write: if image.endswith('3.JPG'):
    exp.set("correct_answer", 3)

    Thanks again for your help Sebastiaan, you saved me a lot of work! :D

Sign In or Register to comment.