Howdy, Stranger!

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

Supported by

[open] Spectrum image, from what participants can choose colors. It is possible?

edited February 2013 in OpenSesame

Hello,

I need to design an experiment, in that participants could choose a color from a spectrum of colors image. I need something like in photoshop (when you choose what colour to use), and that the color of that region where is mouse pointer to be seen in a square on the bottom corner of the display, and that colour need to be registered after normal mouse click on the choosed color.
Is possible to do something like this in OpenSesame?

PS: Sorry if my description is not so clear... :)

Comments

  • edited February 2013

    Hi,

    This would be a handy tool for research on synesthesia (for example), but currently such a tool does not exist. You might want to look at inline_scripting, especially the canvas functions: http://osdoc.cogsci.nl/python-inline-code/canvas-functions/

    If you're not so great at Python, this might be a good opportunity to learn ;) Otherwise, it shouldn't be too difficult :)

    Good luck!

  • edited 3:00PM

    The easiest approach is probably to just use an image that is exactly the size of the display. That way you don't have to read the contents of the screen (which is hard), but can simply extract the contents from the image (which is easy). Perhaps this script will get you started. It reads an image called my_image.jpg from the file pool and goes into 'photoshop mode' until you click a button.

    from PIL import Image
    from openexp.mouse import mouse
    from openexp.canvas import canvas
    
    # Load an image from the file pool. This image must have the same
    # dimensions as the display resolution of the experiment!
    # See: http://www.pythonware.com/library/pil/handbook/image.htm
    src = exp.get_file('my_image.jpg') 
    img = Image.open(src)
    
    # Create a mouse object and make the cursor visible
    # See: http://osdoc.cogsci.nl/python-inline-code/mouse-functions/
    mouse = mouse(exp)
    mouse.set_visible(True)
    
    # Create a canvas object
    # See: http://osdoc.cogsci.nl/python-inline-code/canvas-functions/
    canvas = canvas(exp)
    
    # Loop infinitely
    while True:
        # Get the mouse position
        pos, time = mouse.get_pos()
        # Get the color of the image at the mouse position
        col = img.getpixel(pos)
        # Draw a canvas with the image and a rectangle with the extracted color
        canvas.clear()
        canvas.image(src)
        canvas.rect(10, 10, 100, 100, color=col, fill=True)
        canvas.show()
        # Break the loop if a button is clicked
        if mouse.get_click(timeout=1)[0] != None:
            break
    

    If you're not so great at Python, this might be a good opportunity to learn

    But this is definitely true! You will probably want to (at least) tweak this script, and this will require knowledge of Python. A good start:

    Cheers!
    Sebastiaan

Sign In or Register to comment.