# Create an image showing max intensities in a set of images?

I would like to use a set of two images with the same color scheme (img1 and img2) to produce a new image (img3) in which each pixel corresponds to the "higher pixel color value" of img1 and img2.

Imagine objects (e.g. disks) in img1 have the color col1:

col1= ColorData["TemperatureMap"][0.5]


In img2 the disks are at different positions (partly overlapping with img1), they should have the color col2:

col2= ColorData["TemperatureMap"][0.2]


For the resulting image img3 we should check if objects in img1 and img2 overlap there. If so, then the pixel gets the color col1 (because 0.5 > 0.2).

If at a pixel only one of the images has an object, then color remains the same. A scheme with only three colors might look like this:

• blue AND red --> red
• blue AND background --> blue
• background AND red --> red
• Higher color picture? On what color space? Dec 11, 2014 at 22:53
• I was nor precise, see above ..
– mrz
Dec 11, 2014 at 22:59
• Let me ask more clearly: If img1 is RGB[.5,.1,.3] and img2 is RGB[.4,.2,.4]... what do you want as result? Dec 11, 2014 at 23:05
• @MilenkoRubin-Zuzic What you want is in general not possible, because the mapping value -> {r,g,b} which you use to create img1 and img2 has (in general) no inverse. What you can do is to calculate the max before you turned your gray values into colors, but this is what bill has already shown you in his answer. Dec 12, 2014 at 4:32
• @halirutan Have you seen my answer? I think it still has some problem, but looks good overall Dec 12, 2014 at 18:46

Nice Problem.

Perhaps something like:

f[x_] := List @@ (ColorData["TemperatureMap"][x]);
s = Table[(f@x) -> x, {x, 0, 1, .001}];
k = Nearest@s;


Usage:

c = DensityPlot[#, {x, 0, 1}, {y, 0, 1}, ColorFunction -> "TemperatureMap", Frame -> None,
PlotRangePadding -> 0, PlotPoints -> 100] & /@ {x, y};
m = Map[k, (List @@@ ImageData@#), {2}] & /@ c;
GraphicsRow[Join[c, {Image@Map[f, MapThread[Max, m, 2], {2}]}]] Although I think there is still a small problem in the interpolation in the middle of the max zones.

Yes, you can use ImageApply. For example, if img1 and img2 are two images of the same size, then

ImageApply[Max, {img1, img2}]


takes the max of each channel.

• see changes above ...
– mrz
Dec 11, 2014 at 23:29
• Define the map/function you want to use and place it in ImageApply instead of Max. Dec 11, 2014 at 23:56
• I'm not sure. Is it so easy? Dec 16, 2014 at 13:01