How can assign a color channel to an image series?
27 views (last 30 days)
Show older comments
Samuel Salinas on 13 Feb 2020
Commented: Samuel Salinas on 16 Feb 2020
My question is two-fold:
I'm using Bio-Formats to import an image series (or stack) from multiphoton into Matlab.
No problem there. I have two series that I want to assign a color (such as blue for DAPI and red for Collagen) similar to what can be done in ImageJ, where you assign an image series a channel and ultimately merge stacks.
1) As a preliminary step I tried isolating a single frame out, which was a grayscale image (uint16). I attempted the following (based on https://www.mathworks.com/matlabcentral/answers/46698-how-to-convert-gray-image-to-color-image):
imshow(RGBimage) or imshow(RGBimage,)
I get a black window, where I expected some structures to be red. However, imshow(grayimage,) works fine. How can I add color to a single frame?
2) Scaling this up: Is there a way to apply a color to the whole image series that I import from Bio-Formats?
This may be something very basic. I tried looking elsewhere and have attempted to apply suggestions but have had no luck thus far. Many thanks!
Walter Roberson on 14 Feb 2020
The classic reason to get out a black window when you use imshow() but imshow() with  looks okay, is to start with image data that is you start with single or double precision data values that are in the range 0 to 1, and you cat() those together with zeros that are uint8.
gi = rand(5, 7);
rgb = cat(3,gi,zeros(size(gi),'uint8'),zeros(size(gi),'uint8'));
imshow(rgb) %will be pretty much all black
class(rgb) %will be uint8
There is another related even more common problem, where you get out an image that is completely saturated in the color with possibly a couple of scattered black spots, but no shades of color. With rgb images, this is commonly a completely white image except for a couple of black locations. This related problem is caused by having converted uint8 values to double precision in the range 0. to 255., and then put together with other double precision values such that the end result is double precision but with a value range of 0. to 255. Example,
ri = randi([0 255], 5, 7, 3, 'uint8'); %an rgb image with lots of shades
di = double(ri); %an array with values ranging 0. to 255., but not a standard image
imshow(di) %will be mostly white
imshow looks at the data type to decide what to do, instead of looking at the data range. Data type double() expects shades according to values in the range 0 to 1. Any value less than 0 is treated the same as 0 when showing an image; any value greater than 1 is treated as 1 (full brightness) when showing the image. Double precision 0. to 255. is mostly values greater than 1, so all positions are to be maximum brightness except for the few that are 0 (black.)
You need to carefully check the datatype and value range of what you are concatenating together.
If you want to use double precision for images, do not use double() to convert it: use im2double(), which will rescale by the appropriate constant so that the maximum expected value for the data type is mapped to 1. It is really common for people to think that double(IMAGE) converts the representation of IMAGE from uint8 to something that will display the same way but be double precision, and that is just not the case.
More Answers (1)
Spencer Chen on 13 Feb 2020
1) What you want to achieve get is probably something like this:
or you can do:
RGBimage = repmat(grayimage,[1 1 3]);
RGBimage(:,:,2:3) = 0;
Anyway, I gave you 2 examples because it will benefit your Matlab skills if you can understand what's happening in both.
2) You can simply pseudo color your plots in red-scale using the colormap() function after you plot.
Find more on Biomedical Imaging 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!