How to change the color intensity of an image?

24 views (last 30 days)
Let's say I have an RGB image and I want to change the intensity of the RGB channels, how would I do that?
For example, I want to make the red colors in the image for intense and the blue colors less intense.

Accepted Answer

Image Analyst
Image Analyst on 20 Dec 2022
That's somewhat ambiguous but I'll assume you want to make the image look more vivid by increasing the saturation of the colors. You can try
rgbImage = imread('flamingos.jpg');
subplot(2, 2, 1);
imshow(rgbImage);
hsvImage = rgb2hsv(rgbImage);
[h, s, v] = imsplit(hsvImage);
subplot(2, 2, 3);
histogram(s);
xlim([0,2]);
grid on;
title('Histogram of Original s');
scalingFactor = 2.1;
s = scalingFactor * s;
subplot(2, 2, 4);
histogram(s);
xlim([0,2]);
grid on;
title('Histogram of Final s');
hsvImage = cat(3, h, s, v);
rgbImage2 = hsv2rgb(hsvImage);
subplot(2, 2, 2);
imshow(rgbImage2);
If you want to alter the brightness instead, replace s with v in the computations.

More Answers (1)

DGM
DGM on 16 Nov 2023
If you want to adjust the red and blue components as the question asked, you can do that easily enough.
inpict = imread('peppers.png');
outpict = im2uint8(im2double(inpict).*permute([1.1 1 0.7],[1 3 2]));
imshow(outpict)
That said, it's not terribly common to need to do color adjustments strictly in RGB, and doing them this way is cumbersome and verbose.
You can do the same thing with MIMT imtweak() in a succinct, flexible, and class-agnostic way:
outpict = imtweak(inpict,'rgb',[1.1 1 0.7]);
imshow(outpict)
Even if you wanted to do S adjustment in HSV instead, it's still far easier than doing it the long way.
outpict = imtweak(inpict,'hsv',[0 2.1 1]);
imshow(outpict)
Of course, you aren't stuck with the overblown results caused by using HSV. Use whatever model you want.
outpict = imtweak(inpict,'lchab',[1 2.1 0]);
imshow(outpict)
Alternatively, if wou want to stick to doing color balancing in RGB, you can use MIMT colorbalance(), which replicates the GIMP tool of the same name. It's a little more complicated, but it's still similar to common image adjustment tools.
% K specifies the channel adjustment in the range [-1 1]
% columns are [R G B]; rows are [shadows; midtones; highlights]
K = [0.3 0 -0.2].*[0.2; 1; 0.8];
outpict = colorbalance(inpict,K,'preserve');
imshow(outpict)
... or you could just go off the deep end with GMIC tonergb(), though I find it cumbersome and terribly unintuitive. That's kind of what happens when you go from having 3 control parameters to having 32 control parameters.
% each T matrix specifies how a given channel should be adjusted for
% pixels with [little some much] amount of [red; green; blue]
Tr = [10,15,20; 10,05,00; 10,05,00]/255;
Tg = [00,00,00; 00,00,00; 00,00,00]/255;
Tb = -[10,20,40; 10,20,40; 20,30,60]/255;
% Tsat controls how much of the transformation is applied
% to pixels with [zero ... some ... full] saturation
Tsat = [0,0,128,255,255]/255;
outpict = tonergb(inpict,Tr,Tg,Tb,Tsat,'preserve');

Categories

Find more on Convert Image Type in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!