Composite image of multiple channels

You can associate images to heatmaps defined by a matrix and a ColorGradient,
as in your example, as follows:

If you have an arbitrary matrix A= -3 .+ 5*rand(100, 100) for your heatmap
and

Am, AM =extrema(A)

are its extrema, then the associated normalized matrix is:

nA =(A .- Am)/(AM-Am)

Hence I explain how to associate an image to a heatmap, working with normalized matrices:

nm1 = rand(100,100)
nm2 = rand(100,100)

Let us define img1, img2, the images representing the heatmaps associated to nm1, nm2 and respectively grad2, grad3 in your initial example.
Then:

img1 = (1.0 .- nm1) .*grad2[1] .+ nm1 .*grad2[2]
img2 = (1.0 .- nm2) .*grad3[1] .+nm2 .* grad3[2]

A convex combination of the two images is a blended image, i.e.

blended_img = a *img1 .+ b* img2

where a, b >=0, and a+b=1.
The simplest example is

blended_image = 0.5 *img1 .+ 0.5*img2

For α-blending (compositing) see https://en.wikipedia.org/wiki/Alpha_compositing, where
the coeefficients, a, b in the above convex combination of images are:
a= α₁(1- α₂)/ ( α₁(1- α₂) +α₂)
b = α₂/( α₁(1- α₂) +α₂)
and α₁ , α₂ are the α- parameters for img1, respectively img2.

1 Like