Increase RGB image saturation.
Show older comments
How would I go about increasing the saturation of an RGB image?
Accepted Answer
More Answers (1)
Out of boredom and self-interest, I'll add the convenient but nonstandard way of doing this with MIMT. Base MATLAB/IPT doesn't have any convenient tools to do color adjustment of images, but MIMT has imtweak():
As in the above example, you could use HSV if you wanted:
inpict = imread('peppers.png');
amount = 2; % a rather significant saturation/chroma alteration
A = imtweak(inpict,'hsv',[0 amount 1]);
imshow([inpict A]) % show original and modified image side by side

or you could use HSL
B = imtweak(inpict,'hsl',[0 amount 1]);
imshow([inpict B])

or whatever color model you want
C = imtweak(inpict,'lchab',[1 amount 0]);
imshow([inpict C])

even esoteric things that nobody uses
D = imtweak(inpict,'huslok',[0 amount 1]);
imshow([inpict D])

I can never find good example images for demonstrating these things, but you get the drift. Generally, the LCH methods are going to have the least risk of causing brightness distortions due to large saturation/chroma increases or hue rotations. Note the loss of highlight contrast in the HSV image. HSL tends to do a better job due to its symmetry, but note how it still exaggerates the yellowish regions on the green peppers.
It's worth noting that increasing chroma (in LCH) pushes color points radially toward the gamut extents (and beyond). How that is handled can make a significant difference in the apparent quality of the result. Consider the third example. Increasing the chroma 50% pushes roughly 15% of color points out of gamut. By default, imtweak() internally clamps those color points at the gamut extent prior to converting back to RGB. When using simple methods (e.g. using rgb2lab() and editing the chroma directly) truncation typically will happen at some point after conversion to RGB. If you were to let the truncation occur in RGB, this is what you'd get instead.

Truncation in LCH merely limits the allowed chroma increase in saturated regions. Truncation in RGB pushes color points toward the primary-secondary corners of the RGB cube and can cause noticeable hue/brightness shifts in regions where clipping occurs. Keep that in mind if you're trying to manually edit channels in the often-suggested manner.
The HuSLok example is only included for sake of demonstrating flexibility, not to suggest that this is a particularly good application for HuSL.
imtweak() is part of MIMT:
2 Comments
Dinesh
on 28 Jun 2023
But is it possible increase the Saturation from RGB itself? without changing the color space?
Yes, you can. To increase the saturation of a given pixel in RGB, simply move it radially away from the neutral diagonal of the RGB cube in proportion to its position between the neutral diagonal and the surface of the cube. While that's easy to visualize, the math required to effect such a geometric transformation is equivalent to converting to HSL, HSV, HSI, or HSY (depending on which assumptions and simplifications are made).
Is there a quick and dirty trick that you can do that kind of works strictly in RGB? Yes. Kind of.
kc = 1.5; % chroma scale factor
inpict = imread('peppers.png');
inpict = im2double(inpict);
V = max(inpict,[],3);
outpict = V + kc*(inpict - V);
imshow(outpict,'border','tight')
... but it's essentially an ugly, worse version of boosting saturation in HSV -- which is already the worst option to begin with.
To be more accurate, this is manipulating the HSV concept of chroma, which is simply the spread of the values within an RGB tuple. Since the brightness metric in HSV is the maximum value in an RGB tuple, we can manipulate C independent of V by stretching the value range while keeping the maximum value fixed. While it works, it's still pretty terrible. V is a terrible brightness metric, and the asymmetry of HSV (even this pseudo HSV) makes it a poor choice for HS adjustment.
You could do similar using I instead of V, to preserve the mean. While I is a better brightness metric than V, stretching C this way is still going to be fairly poor but for very small adjustments.
I = mean(inpict,3);
outpict = I + kc*(inpict - I);
Since we're working with C, which is a denormalized quantity, there's nothing stopping us from pushing colors out of gamut with this trick. Depending on what you do next, you might want to clamp the output values.
In short, you could reinvent the wheel if you really wanted to, but it's questionable whether there is a clear benefit to doing so. Bear in mind that HSV was developed for computers in 1974. It's hard to find a scenario today where HSx models are too expensive to use, but it's inarguable that the above trick can certainly be faster than a round-trip HSV conversion. It's up to you to decide what compromises you're willing to make.
Categories
Find more on Contrast Adjustment in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




