I usually use OpenCV lot, which uses numpy as a backend, so images are just matrices.
To overlay a binary image on a background image, you basically do:
overlaycolour = [255,0,0]
Here alpha is the transparency of the overlay (if alpha is 1, the overlay is simply inserted into the image; if alpha is 0, the overlay is invisible, and if alpha is between them, the overlay is a transparent bit).
In addition, either: - the binary image (i.e., the image to be overlaid) is normalized to 1 s and 0 s, and the overlay color is from 0 to 255, OR the binary image is 255 and 0, and the overlay color - from 0 to 1.
Finally, if the background image is gray, turn it into a color image by simply replicating this single channel for each of the red, green, blue channels.
If you want to display a background image on a specific color map, you will need to do this first and apply it to the overlay function.
I am not sure how this code is executed in PIL, but it should not be too complicated.
source share