Increase Yellow Saturation only in RGB or HSV Imag

2019-06-09 20:52发布

问题:

I have an image. I want to selectively increase the saturation of yellow in the image to max. How is this done in the RGB or HSV image space? Thanks.

回答1:

This needs to be done in HSV (Hue Saturation Value) color space.

If you have the image in HSV, it is very easy (else convert it to HSV). The H is the only variable that gives color information, and if you check the wikipedia page of Shades of Yellow, you'll notice they are all are between 45 to 60 deg. So take you HSV image, select the H in that range and increase the S (saturation) of those values.

In Matlab:

%Read image
imghsv=imread('http://7-themes.com/data_images/out/34/6884934-yellow-flowers.jpg');
imghsv=rgb2hsv(im2double(imghsv));

%pick yellow
yellowIndex=repmat((imghsv(:,:,1)>45/360)&(imghsv(:,:,1)<60/360),[1 1 3]);   
yellow=imghsv.*yellowIndex;

%Saturate it
moreSaturation=2;
yellowsaturated=yellow(:,:,2)*moreSaturation;
yellow(:,:,2)=yellowsaturated;

%put it back
newHsv=imghsv; 
newHsv(yellowIndex)=yellow(yellowIndex);

result:

Original

Yellow pixels

Saturated