4
$\begingroup$

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
$\endgroup$
  • $\begingroup$ Higher color picture? On what color space? $\endgroup$ – Dr. belisarius Dec 11 '14 at 22:53
  • $\begingroup$ I was nor precise, see above .. $\endgroup$ – mrz Dec 11 '14 at 22:59
  • $\begingroup$ 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? $\endgroup$ – Dr. belisarius Dec 11 '14 at 23:05
  • 1
    $\begingroup$ @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. $\endgroup$ – halirutan Dec 12 '14 at 4:32
  • $\begingroup$ @halirutan Have you seen my answer? I think it still has some problem, but looks good overall $\endgroup$ – Dr. belisarius Dec 12 '14 at 18:46
7
$\begingroup$

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}]}]]

Mathematica graphics

Although I think there is still a small problem in the interpolation in the middle of the max zones.

$\endgroup$
5
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ see changes above ... $\endgroup$ – mrz Dec 11 '14 at 23:29
  • 2
    $\begingroup$ Define the map/function you want to use and place it in ImageApply instead of Max. $\endgroup$ – bill s Dec 11 '14 at 23:56
  • $\begingroup$ I'm not sure. Is it so easy? $\endgroup$ – Dr. belisarius Dec 16 '14 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.