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!

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 16 Jun. 2021

1 Stimme

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 Kommentare

Or perhaps you just need something like
img = imread('cameraman.tif'); %uint8 grayscale
rgb = repmat(img, [1 1 3]); %now it is rgb
mask = bwareafilt(~imbinarize(img), 1); %1 largest dark area
mask2 = bwareafilt(imbinarize(img), 1); %1 largest bright area
t = rgb(:,:,1);
t(mask) = 128;
rgb(:,:,1) = t;
t = rgb(:,:,3);
t(mask2) = 128;
rgb(:,:,3) = t;
imshow(rgb)
Matthew Peoples
Matthew Peoples am 16 Jun. 2021
The first example is perfect - thank you! Just a quick question - what is the purpose of rand(size(img))/10 and rand(size(img)?
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.
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)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Modify Image Colors finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by