How to change the color intensity of an image?
조회 수: 25 (최근 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)
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)
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');
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!