overlay of images

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

How to do this? Do I have to combine the RGB values of the

    > 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

John Hunter wrote:

    > How to do this? Do I have to combine the RGB values of the
    > 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