Adding Color Hues to Greyscale Image

5 views (last 30 days)
Hi there! I have two 500x500 greyscale images loaded in using imread() and then I fuse them using imfuse(A,B 'blend'). So the resulting image is 500x500 uint8 greyscale superimposed image.
I need to be able to add color 'hues' to the new superimposed image - such as giving it a red overlay, blue overlay etc.
Any ideas on how to do this? Thank you so much!

Accepted Answer

Walter Roberson
Walter Roberson on 16 Jun 2021
one approach:
Take the 500x500 uint8 grayscale image, and use im2double() on it. This will give you floating point numbers. For uint8, the equation works out the same as dividing the uint8 by 255.
Now take those floating point values, and make them the third layer of an image, in which the first two layers are all zero.
img = imread('cameraman.tif');
imgd = im2double(img);
H(:,:,3) = imgd;
H is now the HSV representation of the grayscale image. You can write Hue information into H(:,:,1) and Saturation information into H(:,:,2); For example,
H(:,:,1) = rand(size(img))/10;
H(:,:,2) = rand(size(img));
imgrgb = hsv2rgb(H);
imshow(imgrgb)
  4 Comments
Walter Roberson
Walter Roberson on 16 Jun 2021
H(:,:,1) = rand(size(img))/10;
H(:,:,2) = rand(size(img));
The first one is assigning random Hue. Hue is in the range 0 to 1, with values close to 0 and also values close to one being red-ish; it is like a circle with 0 being one color pole, 1/3 being another color pole, and 2/3 being the third color pole. So rand()/10 is randomizing using a moderately low (redder) hue.
The second one is assigning random Saturation.. how much white light is being mixed in (the difference between Red and Pink for example.)
Neither one has specific reason for being what they are; I just needed something for demonstration.
Walter Roberson
Walter Roberson on 16 Jun 2021
Edited: Walter Roberson on 16 Jun 2021
img = imread('cameraman.tif');
imgd = im2double(img);
H(:,:,3) = imgd;
H(:,:,1) = sort(rand(size(imgd)), 1);
H(:,:,2) = sort(rand(size(imgd)), 2, 'descend');
imgrgb = hsv2rgb(H);
imshow(imgrgb)

Sign in to comment.

More Answers (0)

Categories

Find more on Colormaps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!