Adding Color Hues to Greyscale Image
2 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
采纳的回答
Walter Roberson
2021-6-16
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 个评论
Walter Roberson
2021-6-16
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
2021-6-16
编辑:Walter Roberson
2021-6-16
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)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Colormaps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!