Gamma correction using wx.Image?

I need to make a widget that allows the user to adjust the gamma on a bitmap. The problem is that the bitmap is using bytes for each of it’s color channels. Therefore some sort of gamma correction table is needed to adjust the unsigned int values in the image. How do I adjust the rgb components of the image by piping them through a gamma correction table without copying the pixel data and iterating through each rgb component and making a new data table and recreating the Image (which would be slow)?

-M

···

Give to a good cause with every e-mail. [Join the i’m Initiative from Microsoft.](http://im.live.com/Messenger/IM/Join/Default.aspx?souce=EML_WL_ GoodCause)

Gre7g Luterman wrote:

···

On 5/17/08, *Marlin Rowley* <marlin_rowley@hotmail.com > <mailto:marlin_rowley@hotmail.com>> wrote:

    I need to make a widget that allows the user to adjust the gamma on
    a bitmap. The problem is that the bitmap is using bytes for each of
    it's color channels.

Look into python image library (PiL) or ImageMagick.

or numpy arrays.

-Chris

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Not to pull this conversation off topic, but has anyone ever written a wxPython-specific wrapper for PiL or ImageMagic to allow you to move bitmaps in and out of these modules? I tried messing with PiL recently but the only way I could make PiL & wxPython “play” was to save a wxPython bitmap to file, manipulate the file with PiL, and then bring the file back in. I couldn’t find a good way to fake a file since wxPython wanted a filename instead of a file handle.

If no (if no one has written one), then this would be a damned fine project for someone to tackle. I bet lots of people would find that useful.

Gre7g

···

On 5/17/08, Gre7g Luterman gre7g.luterman@gmail.com wrote:

Look into python image library (PiL) or ImageMagick. They don’t interface as nicely as I would want with wxPython, but it will beat the heck out of doing it yourself pixel-by-pixel!

Gre7g Luterman wrote:

···

On 5/17/08, *Gre7g Luterman* <gre7g.luterman@gmail.com > <mailto:gre7g.luterman@gmail.com>> wrote:

    Look into python image library (PiL) or ImageMagick. They don't
    interface as nicely as I would want with wxPython, but it will beat
    the heck out of doing it yourself pixel-by-pixel!

Not to pull this conversation off topic, but has anyone ever written a wxPython-specific wrapper for PiL or ImageMagic to allow you to move bitmaps in and out of these modules? I tried messing with PiL recently but the only way I could make PiL & wxPython "play" was to save a wxPython bitmap to file, manipulate the file with PiL, and then bring the file back in. I couldn't find a good way to fake a file since wxPython wanted a filename instead of a file handle.

You can create a wx.Image from a Python file-like object using wx.ImageFromStream and then convert that to a wx.Bitmap. Having a more direct way to do it would certainly be nice though.

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Gre7g Luterman wrote:

···

On 5/19/08, *Christopher Barker* <Chris.Barker@noaa.gov > <mailto:Chris.Barker@noaa.gov>> wrote:

    You can also pass the data from a PIL image into a wxImage with
    python strings (and buffers?).

    Anyway, one way to improve this is to have wx understand the "array
    protocol" introduced by numpy -- it can be used to pass data between
    a numpy array and a PIL image now, and if wx implements it, then the
    same thing could be done with wxImages (and other wx types).

    I believe is this on the list for a Google Summer of Code project,
    so we may get in a couple months.

Oh that would be sweet! I did a quick search and didn't find it. Don't suppose you have a link?

These are the assigned projects: Google Summer of Code 2008  |  Google for Developers

Since the Exceptions project is not a large amount of work Christopher Davis agreed to take on a few other things as well, one of which is the optimization of transferring image data to wxImage/wxBitmap.

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!