From: Teemu R. <Tee...@he...> - 2005-02-07 21:43:29
|
Hi, I recently got matplotlib working on OSX (only agg so far) and am now trying to create a picture with two overlayed images so that only a certain range of values of the top-most figure are blended with the bottom one. The first image would be plotted with the gray palette: im_bottom=figimage(bottom_data,xo=0, yo=0,cmap=cm.gray) The second image would be in colors: im_top=figimage(top_data,xo=0, yo=0,cmap=cm.hot) I would like to 'threshold' the top figure so that only values, say, greater than 30 are plotted with 'hot' colors and elsewhere the gray im_bottom is shown (without blending it with the colors of im_top). I was hoping that I could do something easy like this: im_top=figimage(where(less(data_top,30),do_not_plot_this_value,data_top),xo=0,yo=0,cmap=cm.hot,alpha=0.5) How to do this? Do I have to combine the RGB values of the two images 'manually'? Cheers, -- Teemu Rinne |
From: John H. <jdh...@ac...> - 2005-02-08 13:42:09
|
>>>>> "Teemu" == Teemu Rinne <Tee...@he...> writes: Teemu> How to do this? Do I have to combine the RGB values of the Teemu> two images 'manually'? Basically what you are talking about is adding an alpha channel to the color map, and setting it to be transparent for image values less than a certain value. Perry Greenfield is the colormap implementer and resident expert. Perry -- how hard would it be to either subclass or extend the current framework to include an alpha channel? I think it could be done in just a few lines of code actually. Eg, something like self._alpha_lut = makeMappingArray(self.N, self._segmentdata.get('blue', [1.0, 1.0]) and then modifying def __call__(self, X, alpha=1.0): to deal with it. Perry do you have time to take a crack at this? I think this would be very useful. Thanks, JDH |
From: Perry G. <pe...@st...> - 2005-02-09 23:05:52
|
John Hunter wrote: > >>>>> "Teemu" == Teemu Rinne <Tee...@he...> writes: > > > Teemu> How to do this? Do I have to combine the RGB values of the > Teemu> two images 'manually'? > > Basically what you are talking about is adding an alpha channel to the > color map, and setting it to be transparent for image values less than > a certain value. Perry Greenfield is the colormap implementer and > resident expert. > > Perry -- how hard would it be to either subclass or extend the current > framework to include an alpha channel? I think it could be done in > just a few lines of code actually. Eg, something like > > self._alpha_lut = makeMappingArray(self.N, > self._segmentdata.get('blue', [1.0, 1.0]) > > and then modifying > > def __call__(self, X, alpha=1.0): > > to deal with it. > > Perry do you have time to take a crack at this? I think this would be > very useful. > Offhand it doesn't look like it should be a problem, but I need to clarify some things about your suggestion and the user interface. Should self._alpha_lut always copy the blue segment data (or are you showing what the user would have to do?) I would have guessed that it would default to being always 1 (I think that's the intent above but how does one then define it independently outside of the class definition. Secondly, this example asks for a threshold based on prenormalized data values (i.e., image value of 30). To get what the user wants, the user must either define the alpha map to match the normalized value of 30 or normalize the data to match 30 to the alpha map threshold. It's not so obvious to me how this is best handled. A fancier normalization function that uses data-based thresholds to map to color map thresholds? Otherwise, it may be fairly painful to apply in practice. A convenient way to define a color map based on data values and how the data will be normalized? But maybe I'm suffering from flu-induced confusion. Perry |
From: John H. <jdh...@ac...> - 2005-02-10 00:10:50
|
>>>>> "Perry" == Perry Greenfield <pe...@st...> writes: Perry> Should self._alpha_lut always copy the blue segment data Perry> (or are you showing what the user would have to do?) I Perry> would have guessed that it would default to being always 1 Perry> (I think that's the intent above but how does one then Perry> define it independently outside of the class definition. Uh, maybe I have the flu. I meant self._alpha_lut = makeMappingArray(self.N, self._segmentdata.get('alpha', [1.0, 1.0]) I'm not sure about the [1.0, 1.0] -- that's your job :-) What I'm trying to say is that we can use the dict get method to default to the current behavior if the alpha channel is not defined in the segmentdata.... Perry> Secondly, this example asks for a threshold based on Perry> prenormalized data values (i.e., image value of 30). To get Perry> what the user wants, the user must either define the alpha Perry> map to match the normalized value of 30 or normalize the Perry> data to match 30 to the alpha map threshold. It's not so Perry> obvious to me how this is best handled. A fancier Perry> normalization function that uses data-based thresholds to Perry> map to color map thresholds? Otherwise, it may be fairly Perry> painful to apply in practice. A convenient way to define a Perry> color map based on data values and how the data will be Perry> normalized? I'll think about these issues -- gotta run now. But they are orthogonal to having an alpha channel in the colormap, no? Cheers -- hope you're feeling better! JDH |
From: Perry G. <pe...@st...> - 2005-02-10 01:21:12
|
John Hunter wrote: > > Perry> Secondly, this example asks for a threshold based on > Perry> prenormalized data values (i.e., image value of 30). To get > Perry> what the user wants, the user must either define the alpha > Perry> map to match the normalized value of 30 or normalize the > Perry> data to match 30 to the alpha map threshold. It's not so > Perry> obvious to me how this is best handled. A fancier > Perry> normalization function that uses data-based thresholds to > Perry> map to color map thresholds? Otherwise, it may be fairly > Perry> painful to apply in practice. A convenient way to define a > Perry> color map based on data values and how the data will be > Perry> normalized? > > I'll think about these issues -- gotta run now. But they are > orthogonal to having an alpha channel in the colormap, no? > Well, yes and no. Yes in that this can be implemented without dealing with the issue, no in that it may not be easily used by just dealing with that. This has come up before and it makes me think that some tool (I'm thinking about an optional argument to normalize or something defining a correspondence between a data value and a normalized value) is needed to address that, and there are a number of different approaches that could be taken. I was just wondering if you had any thoughts about the best way to do that. Perry |