Coloring a grayscale image to two colors
Show older comments
I have a grayscale image as shown below, I would like to color the dark layer to blue color and the white layer to red color and if possible I would like to change the background to any other color. Can anyone help me with this?
Thanks in advance.

Answers (1)
Image Analyst
on 26 Jun 2019
Determine the threshold between light and dark and have the colormap have one color up to that threshold and then the other color after that threshold. like
threshold = 128
cmap = repmat([0, 0, 1], 256, 1); % Initialize to blue
% Make red from 128 & brighter
for row = threshold : size(cmap, 1)
cmap(row, :) = [1,0,0];
end
Make the obvious adaptations for 3 or more color ranges.
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!