how to enhance the red, green and blue color within an image

27 次查看(过去 30 天)
how can i enhance the red, green and blue color of an object inside an image in order to make the colour look more vivid for easy detection.

采纳的回答

Image Analyst
Image Analyst 2013-5-9
Convert to hsv colorspace with rgb2hsv. Then multiply the S channel by some factor, then go back to rgb color space with hsv2rgb().
  4 个评论
Guillaume
Guillaume 2018-4-26
Or don't bother splitting into 3 different variables to then recombine:
rgbVivid = hsv2rgb(rgb2hsv(rgbImage) .* cat(3, 1, 2, 1)); %multiply saturation channel by 2, others by 1 == unchanged
%requires R2016b or later for implicit expansion. earlier versions use bsxfun instead
DGM
DGM 2022-4-27
Well if you wanted succinctness or convenience, you could do it with MIMT without the version dependency:
rgbVivid = imtweak(rgbImage,'hsv',[0 2 1]); % or any other color model
... and your result will be returned in the same class that it was before.

请先登录,再进行评论。

更多回答(2 个)

kamal bindal
kamal bindal 2018-4-26
编辑:DGM 2023-6-29
img = imread('peppers.png'); % firstly read the image
a = img; % storing the image in temporary variable
a(:,:,3) = 2*a(:,:,3); % inc the intensity of blue colour
imshow(a);

DGM
DGM 2023-8-16
编辑:DGM 2023-8-17
This question's been nailed down for a decade, but I've been bored lately. Nothing is stopping me from adding extraneous answers.
I think that OP's question is probably answered sufficiently with HSV adjustment -- specifically because it's about just stretching chroma for the purposes of making some undisclosed segmentation task more robust. I don't know that it actually does, but there's really no reason to waste cpu time on anything more complicated when appearances don't matter.
That said, I doubt other readers are looking for "color enhancement" for the same reasons. As an answer to the more common interpretation of the question, I posit that HSV is not the best answer. In fact, there really aren't answers which are both good and convenient within what's available in IPT and base MATLAB. As a basis of comparison, let's start with an example of what can be done in IPT and base MATLAB. We start with this image:
% do it the hard way with the available tools
inpict = imread('peppers.png');
inpict = imresize(inpict,0.5); % don't need full size for a demo
amount = 2; % adjustment factor
% adjust in HSV using basic tools
hsvpict = rgb2hsv(inpict);
hsvpict(:,:,2) = amount*hsvpict(:,:,2); % adjust
hsvpict(:,:,2) = min(max(hsvpict(:,:,2),0),1);
op1 = hsv2rgb(hsvpict);
op1 = im2uint8(op1);
% adjust in LCHab using basic tools
[L A B] = imsplit(rgb2lab(inpict));
C = sqrt(A.^2 + B.^2);
Hrad = mod(atan2(B,A),2*pi);
C = amount*C; % adjust
A = C.*cos(Hrad);
B = C.*sin(Hrad);
op2 = lab2rgb(cat(3,L,A,B));
op2 = im2uint8(op2);
% adjust in polar YCbCr
yccpict = im2double(rgb2ycbcr(inpict));
[Y Cb Cr] = splitchans(yccpict);
Cb = Cb-0.5;
Cr = Cr-0.5;
C = sqrt(Cb.^2 + Cr.^2);
Hrad = mod(atan2(Cr,Cb),2*pi);
C = amount*C; % adjust
Cb = C.*cos(Hrad)+0.5;
Cr = C.*sin(Hrad)+0.5;
op3 = ycbcr2rgb(im2uint8(cat(3,Y,Cb,Cr)));
outpict = [op1 op2 op3]; % concatenate for easy viewing
imshow(outpict,'border','tight')
None of these work very well. All the methods shown result in fairly gross loss of local contrast. They're also not very convenient to use. Would the LCHab or LCHbr sections be something you could write from memory based only on the recollection of the basic concept? Even if you could, would you want to do it every time?
As mentioned in my old comment, MIMT does have simple-to-use tools for this sort of basic adjustment. There are more available models and options to work with, all in a single line. Let's recreate the prior three adjustments, each with a better alternative.
% do it the easy way
inpict = imread('peppers.png');
inpict = imresize(inpict,0.5); % don't need full size for a demo
amount = 2; % adjustment factor
op1 = imtweak(inpict,'hsv',[0 amount 1]); % HSV's saturation space is asymmetrical
op2 = imtweak(inpict,'hsl',[0 amount 1]); % HSL is usually better than HSV for this
op3 = imtweak(inpict,'lchab',[1 amount 0],'notruncate'); % truncation occurs in RGB, distorting L,H
op4 = imtweak(inpict,'lchab',[1 amount 0]); % use chroma constraint to avoid L compression
op5 = imtweak(inpict,'lchbr',[1 amount 0],'notruncate'); % truncation occurs in RGB, distorting Y,H
op6 = imtweak(inpict,'lchbr',[1 amount 0]); % use chroma constraint to avoid Y compression
outpict = [op1 op2; op3 op4; op5 op6]; % concatenate for easy viewing
imshow(outpict,'border','tight')
As before, everything on the LHS looks blown out or devoid of highlights. The RHS has better highlight and local contrast retention, all without any extra work or complexity from the user's perspective.
MIMT does include a graphical tool immodify(), which allows these adjustments to be made interactively.
See also:

类别

Help CenterFile Exchange 中查找有关 Image Processing and Computer Vision 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by