How to change the color intensity of an image?
16 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Image Analyst
2022-12-20
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.
0 个评论
更多回答(1 个)
DGM
2023-11-16
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)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1541607/image.png)
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.
outpict = imtweak(inpict,'rgb',[1.1 1 0.7]);
imshow(outpict)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1541612/image.png)
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)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1541617/image.png)
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)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1541622/image.png)
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)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1541627/image.png)
... 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');
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1541632/image.png)
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!