Fill intensity grayscale with a colour channel

3 views (last 30 days)
I have read most of the posted questions but could not find a suitable solution for my problem. I have a grayscale image (uint16) that I would like to convert to RGB. I know that this is only possible with a pseudocolour map. Therefore, I created a colourmap with:
colourArray = 0:255;
colourArray = colourMap';
colourMap = [AcolourArray zeros(size(AcolourArray,1),2)];
Then I converted the image from uint16 to uint8 and convert the grayscale to a pseudo RGB:
rgbImage = cat(3, image, image, image)
What I want is to colorise the grayscale image in blue (smooth gradient) based on their intensities.
Due to the problem, that Matlab can not import .lsm files in colour I thought about this way to at least imitate the colour channel. Here is an example image how matlab shows it after import and how I would like to have it:
(Please ignore that the position I took the screenshot varies)

Accepted Answer

Guillaume
Guillaume on 31 Mar 2017
Converting the grey image to pure blue with the same intensity is actually very easy, just use that image as the blue colour plane, and put 0 everywhere in the red and green planes:
rgbimage = cat(3, zeros(size(greyimage)), zeros(size(greyimage)), greyimage);
Converting the grey image to a colour that is not one of the primary is a bit more difficult. The easiest way is to do the conversion in the HSV colour space first. The grey image becomes the luminance (value), and you fix the hue plane to whatever constant you want. Then convert the HSV image to RGB:
hue = 29/256; %for example, some sort of orange. Has to be double
hsvimage = cat(3, repmat(hue, size(greyimage)), ones(size(greyimage)), im2double(greyimage));
rgbimage = hsv2rgb(hsvimage);
  2 Comments
Kamu
Kamu on 31 Mar 2017
that works like charm. Thanks a lot. I have one more question. Let's say I have 4 rgb images, how can I overlay them to 1 composite image?
Image Analyst
Image Analyst on 29 Apr 2017
See this paper for a variety of ways to composite (overlay) more than three images into one color image: http://my.ece.msstate.edu/faculty/du/JSTARS-VIS.pdf

Sign in to comment.

More Answers (0)

Categories

Find more on Modify Image Colors 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!