Adding Color Hues to Greyscale Image

조회 수: 4 (최근 30일)
Matthew Peoples
Matthew Peoples 2021년 6월 16일
편집: Walter Roberson 2021년 6월 16일
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!

채택된 답변

Walter Roberson
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
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
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 CenterFile Exchange에서 Orange에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by