From: John H. <jdh...@ac...> - 2004-04-29 18:08:42
|
>>>>> "Perry" == Perry Greenfield <pe...@st...> writes: Perry> An associated question is how one easily maps a Perry> monochromatic image that is displayed in matplotlib back Perry> into a monochromatic array. Normally it's going to be Perry> converted to rgba even if rgba is not really needed. Is Perry> there any simple way of mapping it back to intensity Perry> (histogram of the rgba values to determine if such a Perry> mapping exists?). Hmmm. Well, assuming you passed it to matplotlib with no colormap, then a default intensity grayscale would be used. In that case, just build the rgb array as above using string methods and then take the r, g, or b slice out of it since they are all identical. If you passed in a colormap, you would need to invert the colormap, which would be relatively easy to provide in the colors.Colormap interface but I'm having trouble imagining why someone would want to do this. Both of these would be lossy, of course, eg if you started with an array of floats you would get back an array of UInt8s. Note agg comes with several helpful pixel converters functions: gray8, rgb565, rgb555, bgr24, bgr24, bgra32, abgr32, argb32, rgba32. Perhaps the best general solution is to define these as module constants and provide a single tostring method that takes one of these constants and returns the appropriate string representation. I can image that this would be useful both for backend agg and the image module. JDH |