Coloring a grayscale image to two colors

3 次查看(过去 30 天)
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.

回答(1 个)

Image Analyst
Image Analyst 2019-6-26
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.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by