# Combine two color channels in a plot / heatmap / image?

**URL:** <https://discourse.julialang.org/t/combine-two-color-channels-in-a-plot-heatmap-image/71008>\
**Category:** General Usage\
**Tags:** images, plotting\
**Created:** [November 5, 2021, 2:31pm UTC](https://discourse.julialang.org/t/combine-two-color-channels-in-a-plot-heatmap-image/71008 "2021-11-05T14:31:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![thompsonmj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thompsonmj/32/25172_2.png) [@thompsonmj](https://discourse.julialang.org/u/thompsonmj)\
**Post date:** [November 5, 2021, 2:31pm UTC](https://discourse.julialang.org/t/combine-two-color-channels-in-a-plot-heatmap-image/71008/1 "2021-11-05T14:31:34Z")

</div>

I have an image with two grayscale color channels I would like to visualize in the same plot.

How can I combine them?

I think I would need to add an alpha or something that scales with the gray value …  
Or instead of `ch1_grad = cgrad([:black, pal[1]])` for the gradient, I would use something like:  
`ch1_grad = cgrad([:clear, pal[1]])` or  
`ch1_grad = cgrad([:empty, pal[1]])` if it existed.

```julia
using Plots, Images

# Set up color palette
pal = palette(:batlow,2)
# The blue selected is too dark; let's lighten it and use it.
pal_light = pal .+ 0.5*ones(RGB{Float32},2,1)
pal = [pal_light[1],pal[2]]

# Make a gradient from black for each channel.
ch1_grad = cgrad([:black, pal[1]])
ch2_grad = cgrad([:black, pal[2]])

# Test images with gradients.
ch1 = Gray.(rand(1000,1000).*range(0.0,stop=1.0,length=1000))
ch2 = Gray.(rand(1000,1000).*range(1.0,stop=0.0,length=1000))

fig_test = plot(
    legend = false,
    colorbar = false)

heatmap!(fig_test,
    reverse(Float64.(ch1),dims=1),
    color = ch1_grad,
    colorbar = false,
    axis = nothing,
    xaxis = false,
    yaxis = false,
    aspect_ratio = :equal)

heatmap!(fig_test,
    reverse(Float64.(ch2),dims=1),
    color = ch2_grad,
    colorbar = false,
    axis = nothing,
    xaxis = false,
    yaxis = false,
    aspect_ratio = :equal)

```

![image](https://global.discourse-cdn.com/julialang/original/3X/a/0/a0c82db1bef7f4b0a2ad661e72a4ac8f94304269.jpeg)  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/a/0/a0178b9d3ee610bf2ab560f133f59422a8afc8b9.jpeg)

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [November 5, 2021, 2:50pm UTC](https://discourse.julialang.org/t/combine-two-color-channels-in-a-plot-heatmap-image/71008/2 "2021-11-05T14:50:43Z")

</div>

If you don’t need axes on the plot, try [Conversions vs. views · JuliaImages](https://juliaimages.org/latest/tutorials/conversions_views/#Using-colorview-to-make-color-overlays).

---

<div class="post-metadata">

**Author:** ![thompsonmj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thompsonmj/32/25172_2.png) [@thompsonmj](https://discourse.julialang.org/u/thompsonmj)\
**Post date:** [November 5, 2021, 3:27pm UTC](https://discourse.julialang.org/t/combine-two-color-channels-in-a-plot-heatmap-image/71008/3 "2021-11-05T15:27:48Z")

</div>

Thanks for the hint, Tim. I’m still not clear what to write though to apply these ideas to produce an image with two channels that range from black for 0 to the specified colors for each channel.

It seems like I need to use `channelview` or `colorview`, but how do I apply the palette to the grayscale images? I guess I would need something like the `color_me` function from [this post](https://discourse.julialang.org/t/how-to-convert-a-matrix-to-an-rgb-image-using-images-jl/7265)? But it doesn’t accept my `ch1_grad` as a second argument, so I still can’t tell how to get my colors applied.
