# adjust weight of red , green ,blue in color image

23 views (last 30 days)
chess on 23 Aug 2014
Commented: Image Analyst on 26 Aug 2014
I have three images and I use cat command to convert them from 2D to 3D. By default I am getting very dark image. I know if I multiply different channel (red,green and blue) by some different scalars I will get image with new color.I know what image I should expect to get. I would like to know is there any algorithm that according to my expected image finds the closes coefficient that I should multiply different channel by?
rgb=cat(3,red,green,blue) % this is too dark
I want to know how to find m,n,k that
rgb=cat(3,red*m,green*n,blue*k)
becomes close to expected image I have.

Image Analyst on 23 Aug 2014
What kind of images are red, green, and blue? Are they uint8 images in the range of 0-255? I'd bet not. They're either binary/logical images with values of 0 and 1 (false and true) or else floating point numbers instead of uint8.
Image Analyst on 23 Aug 2014
Hmmmm.... Maybe
randomRGB = uint8(rand(1)*double(red)+rand(1)*double(green)+rand(1)*double(blue));

oni on 25 Aug 2014
I wanted to do the same and ended up normalizing the images from the three channels with their maximum intensity value:
maxRGB(1) = max(max(red));
maxRGB(2) = max(max(green));
maxRGB(3) = max(max(blue));
maxRGB2 = max(maxRGB);
indR = maxRGB2/maxRGB(1);
indG = maxRGB2/maxRGB(2);
indB = maxRGB2/maxRGB(3);
sclRGB = cat(3,red.*indR,green.*indG,blue.*indB);
This may not be the most ideal solution (e.g., it weighs the three channels the same), but it made the RGB image more balanced (I was getting something super green too before this).
HTH!
Image Analyst on 25 Aug 2014
You're right - it's not ideal in the vast majority of cases. And it does not weight the color channels the same - it weights them by inverse of their respective max values. Unless the separate color channels all have the same max value, it will cause a color shift in the image. Now whether this color shift produces a better or worse image depends on the situation. It sounds like in your case it produced a better image - maybe your camera was not properly white balanced in advance. If I white balanced by camera and then took a photo of the lawn, or of the sky, and then applied your algorithm, it would make the scene more gray (less saturated) than it should be. So it just depends on why or if the image was messed up to start with.

oni on 26 Aug 2014
You are absolutely right, and thanks for pointing out that the weights are inverse of the max values. Please bear with me while I explain when this may be useful. I needed to merge/overlay three fluorescent channels (green, orange and red emissions) and wanted to use 'cat' (with false colors). This is something that people often do for imaging different fluorescent reporters in cells. Oftentimes, green fluorescent reporters are much stronger than others, while reds are often quite week. The max/inverse worked in my case because it allowed me to see the week signal by eye, while suppressing the dominant one. So, if someone is merging fluorescent channels, the inverse of 'max' may work to the advantage.
This should not work for images from a color camera. (Of course, I was not thinking about a color camera at all when I saw the original post- I must have a serious case of tunnel vision! Apologies.)
Image Analyst on 26 Aug 2014
I agree that there are some cases when that type of color enhancement might be desirable, and selectively enhancing colors in fluorescence microscopy, as you described, seems like it would be one of those situations.

### Categories

Find more on National Instruments Frame Grabbers 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!

Translated by