MATLAB: Fill intensity grayscale with a colour channel

convert grayscale rob

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)

Best Answer

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);
Related Question