Increase Yellow Saturation only in RGB or HSV Image (Matlab)

老子叫甜甜 提交于 2019-12-23 05:26:06

问题


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



来源:https://stackoverflow.com/questions/32795660/increase-yellow-saturation-only-in-rgb-or-hsv-image-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!