Howdy, Stranger!

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

Supported by

blue filter

edited December 2016 in OpenSesame

Hi,

I'm trying to show grayscale pictures in blue in an inline_script.
I want to do this by drawing a transparent blue picture on top of it (because I have about 4200 pictures to colorize myself otherwise).

The pseudo-code would than be something like this:

exp.canvas = self.offline_canvas()
exp.canvas.image(picture, x, y, etc)
exp.canvas.rect(x, y, w, h, color=blue, fill=True, alpha=0.5)

I've already tried it with GratingStim from psychopy.visual, but that opened a new screen next to the screen that the picture was shown on)

Does anyone know a solution that'll help?

Comments

  • Hi,

    A semitransparent overlay changes the colors, but differently from a color-swap—which is presumably what you're after, right? For example, a blue overlay would make a black background blueish.

    Below is a simple script that reads an image file, and then mutes one or more of the color channels. So it does proper recoloring.

    import os
    from scipy import misc
    
    
    def color_filter(source, target, red=False, green=False, blue=False):
    
        a = misc.imread(pool[source])
        if not red:
            a[:,:,0] = 0
        if not green:
            a[:,:,1] = 0
        if not blue:
            a[:,:,2] = 0        
        misc.imsave(os.path.join(exp.pool_folder, target), a)
    

    Do you see the logic? A bitmap is just an array, and the third dimension has the color channels [red, green, blue]. And you can mute a color channel (i.e. remove a color) by setting it to 0.

    Now say that you have an image file in the file pool called original.png. Then the following would create a filtered image file in the file pool called blue.png:

    color_filter('original.png', 'blue.png', blue=True)
    

    You can just do this on every trial, and the use the filtered image in a sketchpad, canvas, or what have you.

    Cheers!
    Sebastiaan

Sign In or Register to comment.