From: Perry G. <pe...@st...> - 2004-04-29 17:51:03
|
John Hunter wrote: > You can do this with string methods already. The question is: is it > worth adding a to_numerix and/or from_numerix method for performance > and convenience to directly access the agg pixel buffer representing > the entire figure canvas. The (smallish) downside of the latter is > that currently backend_agg does not depend on Numeric/numarray at all. > > There are a couple of ways to go here and I think it would be useful > to know how people would want to use this functionality. In the > example below, I show how to get the agg pixel buffer as an rgb string > and either convert it to an array or pass it to PIL. I need to add > the tostring_rgba equivalent - I added tostring_rgba this as a helper > for backend ps which doesn't need alpha. > > If all that is needed is a way to get at the contents as an array, > then it may be enough to wrap the example code below in a helper > function or appropriate class method. But if one wants to be able to > directly manipulate the contents of the agg rgba pixel array using > numeric and then pass this back to agg, more will be needed. > > So knowing what people need this for, and how critical performance > issues will be in these cases, is important in deciding which tack to > take. > It's not a strong driver for us at the moment, but I agree that it depends on how people see using this capability. For our part (and this is just limited to my knee-jerk reaction, there may be other uses that I can't think of but others may) I would guess the most common use would be to create some sort of image with overlays (contours, legends, etc) that one wants to write out to one of the scientific data formats that are used to store scientific images. Normally these would be array-aware and so arrays make a good intermediary. Perhaps the values would be manipulated as well as arrays but that seems less likely. I'll see if I can conceive of any other uses. Saving memory copying doesn't seem to be that important for these sorts of uses since they would not be frequent, nor involve gigantic images that couldn't stand to be copied. An associated question is how one easily maps a monochromatic image that is displayed in matplotlib back into a monochromatic array. Normally it's going to be converted to rgba even if rgba is not really needed. Is there any simple way of mapping it back to intensity (histogram of the rgba values to determine if such a mapping exists?). Hmmm. Perry |