MATLAB Answers

Adding Color Hues to Greyscale Image

1 view (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
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)

Community Treasure Hunt

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

Start Hunting!