フィルターのクリア

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

20 ビュー (過去 30 日間)
Pat
Pat 2013 年 5 月 9 日
編集済み: DGM 2023 年 8 月 17 日
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);
  1 件のコメント
DGM
DGM 2023 年 6 月 29 日
Editor's note:
Edited to fix comments and make the code run for demo purposes.

サインインしてコメントする。


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 Center および File ExchangeImage Filtering and Enhancement についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by