strange behavior of images when they have an alpha channel

Example script attached (PIL required). Basically, if I impose a specific value into an image’s alpha channel and use any interpolation scheme other than ‘nearest’, there appears gray all where the figure didn’t have any color to begin with. I’ve also attached a screenshot of the output of the script on my machine.

Hopefully I’m doing something wrongly?

I chased the problem and managed to hack in a solution that fixes the problem, but it’s extremely inefficient…basically, in matplotlib’s, routine BboxImage.make_image, you can create two images there…one with no alpha channel (call it imRGB) and one with (call it imRGBA). Go through all of the routine, doing exactly the same things to both of the images except for the interpolation, which is set to ‘nearest’ for imRGBA. Then, rip the colors out of imRGB, the alpha channel off of imRGBA, and put them together…go through all of the routine again with this composited image, and it works. I know…I told you it was bad :wink:

The problem seems to be in the “resize” call in that routine…resize, which calls into C code, does not appear to handle things correctly when the alpha is anything other than 255’s across the board. It might be a problem in the agg routines, but hopefully it is just maybe a misuse of the agg routines.

The behavior seems to be backend independent as far as I could test (I tried with wxagg and tk backends). I am using mpl 1.0.0 on Windows if it matters. (1.79 KB)




Daniel Hyams