MATLAB: Change the black of grayscale image into color

burn colored overlay into imagecolorImage Processing Toolbox

Hallo I gernerated with "bwperim" borders around my particles and switched them to black instead of white with a black background.
I would like to visualize the difference between multiple images by diffrent colors. Right now all the images are black and white.
how can I change the black sourrounding into a diffrent color for each picture?

Best Answer

Threshold or somehow segment your images to get a mask of the "black" parts, then use
rgbImage = imoverlay(grayImage, mask, yourColor);
where yourColor is a 3 element array where each number of the fraction from black to bright for red, green, and blue, like [0.3, 0.6, 0.9] or whatever.