Image gradation allows the adaption and optimization of images using color models and mathematical curves, the so-called gradation curves. HspGradator implements HSP, a new color model which incorporates the perceived brightness. The gradation curves are modelled with finite splines, also a new technique, which takes an intermediate position between line segments and cubic splines. Other color models like HSL or CIE-HCL and other types of gradation curves like cubic splines are also available. The result can be analyzed by the comparison of the modified image with the original image as well as by interpretation of histograms. HspGradator is open source software and the project is hosted on GitHub.
During the image gradation the following steps are performed for each pixel of the image:
HspGradator provides the following color models: RGB, HSV, HSL, HSG and HSP.
For more information about these color models see my project CmLibDemo.
Additionally, HspGradator provides CIE-HCL (Hue, Chroma, Lightness), this color model is based on CIE-L*a*b*, which itself is based on the CIE-XYZ color model. It's important to know, that the CIE-HCL color space contains more colors than the RGB color space. Therefore, the conversion from RGB to CIE-HCL always works fine. But in the case of the conversion from CIE-HCL to RGB, some RGB parameter values can lie outside of the valid range. In order to get a valid RGB color again, they have to be clamped.
The following calculations demonstrate the issues which can occur, if clamping is executed during the gradation. The first three steps show a typical gradation process. First the color is converted from RGB to CIE-HCL, then the gradation takes place by altering Chroma and Lightness. Finally, the color is converted back to RGB. The RGB parameters have to lie in the range from 0 to 255, but now two of them lie outside. In order to get a valid RGB color again, we have to set a parameter below 0 to 0, and a parameter above 255 to 255, this is the clamping. For testing purposes the clamped RGB color is converted to CIE-HCL, now all parameters, even the Hue, differ in comparison to the CIE-HCL color after gradation.
These calculations exemplify the gradation of the cyan tone of the sky in Figure 5 (before) and 8 (after).
To define the gradation curves usually interpolation curves are used, those are curves that pass through a set of given data points. The type of the gradation curve specifies the shape of the curve between the data points. In HspGradator the following curve types are available: line segments, cubic splines and finite splines.
For more information about these interpolation curves see my project IcLibDemo.
The guidance lines are created from the color parameter values of the original image by upward sorting. Guidance lines may give valuable hints for the useful course of the gradation curves. Tracing a guidance line with the gradation curve, leads to an even histogram for this certain parameter.
Figures 1 an 5 were optimized with the HspGradator using the color models HSL, HSP and CIE-HCL. The aim was to obtain an average perceived brightness of 50% and a higher saturation, while the Hue shouldn't be touched.
First I'd like to compare the application of the similarly constructed color models HSL and HSP. Unlike HSL, HSP considers the perceived brightness. Now let's see whether this feature is useful. After a series of experiments, it turned out that the results were usually similar or almost equal. But in some cases there were considerable differencies in the treatment of the colors blue and yellow (compare the Figures 2 with 3 or 6 with 7). Theoretically this is totally reasonable, because blue is the color with the lowest, and yellow is the color with the highest perceived brightness.
Now let's observe how CIE-HCL behaves: after the adjustment of the Lightness the image appears faded. If the Chroma is increased, the result is inconsistent. Some parts of the image seem oversaturated while other parts still appear slightly faded (Figures 4 and 8). The increased saturation also leads to RGB clamping, especially remarkable in the sky part of Figure 8.
The HspGradator project was created with Visual Studio Community 2022 using C++ and MFC.
The HspGradator project contains the C++ template libraries Color.h, ColorModels.h, Point.h and InterpolationCurve.h and introduces the C++ template library CieHcl.h.
All classes and functions use the namespace ama.
CieHcl.h contains the generic data structure ama::CieHcl and the respective conversion functions to and from ama::Rgb. The data structure can be instantiated with any data type, but if it's used together with the conversion functions, it must be a floating point type. The conversion functions always operate in the range from 0.0 to 1.0 for each parameter of the involved data structures. The algorithms in this library are based on the conversion formulas from EasyRGB.com.
In the HspGradator project the templates are instantiated with the data type float.
The main window provides the following menu commands:
If the Instant Mode is activated, the image calculation proceeds while the data point are moved by mouse, otherwise the image calculation takes place after the mouse move operation.
Allow Clamping is only effective if the CIE-HCL model is selected and if a color was clamped. If the option is activated, the clamped colors are displayed, otherwise the corresponding pixels are colored black.
There are three curve views, one for each color model parameter. The display of the individual views can be switched on or off in the View menu. The curve view enables the specification of a gradation curve, in the background the guidance line is displayed.
The image view displays the original or the modified image by choice. They can be switched with the respective commands in the View menu, the Left/Right keys or the Enter key. A double click on the image view opens the file dialog for the loading of an image.
The histogram view displays histograms of the red, green, blue and the perceived brightness values.
Download HspGradator (64-Bit executable file)
HspGradator is distributed under the GPL-3.0 software license. The libraries are distributed under the MIT software license.
Copyright © 2020-2024 Adrian Maurer. All Rights reserved.