Howdy, Stranger!

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

Supported by

[solved] Bitmap color replacement a la EPrime

edited July 2013 in OpenSesame

Hi,

Great work with Open Sesame. I'm very happy to see that development is continuing!

I have a question about color replacement in bitmap-like images. EPrime has a function called ebColorSource (or something like that) with which you can specify a color to be replaced and a replacement color and it will do so at run time. Is there a feature like this already integrated into Open Sesame or any plans to do so in the future? If 'No' to both questions can you envisage a possibility with inline code?

The problem is that I want to program a search task that has different color backgrounds on different trials. The png files are black on white and I simply am looking for a way to match the white to the background color or make it transparent so the background color can show through. Any suggestions would be greatly appreciated.

Thanks,
John

Comments

  • edited 8:15AM

    I found a work around that uses the python image library to change the target colors to transparent on the RGBa color band. Which then saves the image that is transparent in the target area and which can then be used in Open Sesame. Here is the code that I used in python 2.7 to do this which I got from here.
    This code will set all white pixels to transparent. Changing other colors to transparent simply entails changing the RGB values in the if and newData.append statements to match your target color. The final zero is the alpha channel setting for transparent.

    code: I was going to post the code here but the forum formatting throws off the indentations. I used the code from the link above with only changing the image filename in the image.open and image.save commands.

  • edited 8:15AM

    Hi John,

    I found a work around that uses the python image library to change the target colors to transparent on the RGBa color band. Which then saves the image that is transparent in the target area and which can then be used in Open Sesame.

    Yes, that's what I would recommend as well, in your case. Another alternative would be to use scipy.ndimage, but that's more suitable for doing mathematical things with your images (such as getting the center of gravity, of doing edge detection).

    code: I was going to post the code here but the forum formatting throws off the indentations. I used the code from the link above with only changing the image filename in the image.open and image.save commands.

    You can indicate your code using Markdown syntax, like so:

    ~~~ .python
    My code
    ~~~

    See also:

    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

Sign In or Register to comment.