-
Notifications
You must be signed in to change notification settings - Fork 0
04 Color conversion
Color conversions refer to the process of converting an image or video from one color space to another. Color spaces are mathematical representations of the way that colors are perceived by the human eye, and they differ from each other in terms of their color gamut (the range of colors that can be represented) and the way that colors are represented (e.g. using RGB, CMYK, or HSV values).
There are several reasons why color conversions might be necessary. For example, an image or video might be captured using one color space, but it needs to be displayed or edited using a different color space. Alternatively, an image or video might be edited or processed using a software tool that supports a particular color space, but it needs to be saved in a different color space.
There are several different techniques that can be used for color conversions, depending on the specific requirements of the conversion. One common technique is to use a color correction algorithm that adjusts the brightness, contrast, and hue of the image or video to achieve a desired color balance.
Another approach is to use a color space conversion algorithm that maps the colors in the source color space to the colors in the destination color space. This involves adjusting the RGB values or other color parameters to match the color gamut and other characteristics of the destination color space.
Overall, color conversions are an important tool for working with images and videos in a variety of different color spaces, and they are an essential part of many image and video editing and processing workflows.
Conversions for each model are handled through methods with syntax equivalent to to{Color_model_name}()
. As such:
use tei187\ColorTools\ColorModels\XYZ;
$measure = new XYZ([.2967, .3178, .2817]);
$measure->toxyY(); // returns xyY object
$measure->toXYZ(); // returns XYZ object (self, in this instance)
$measure->toLab(); // returns Lab object
$measure->toLuv(); // returns Luv object
$measure->toLCh(); // returns LCh(ab) object
$measure->toLCh_uv(); // returns LCH(uv) object
$measure->toRGB(); // returns RGB object
$measure->toHSL(); // returns HSL object
$measure->toHSV(); // returns HSV object
While translating from device independent to device dependent model, it is important to remember that defining the set of RGB primaries is required. By default, sRGB primaries are used. If you wish to use another, you have to specify it as an argument in method.
use tei187\ColorTools\ColorModels\XYZ;
$measure = new XYZ([.2967, .3178, .2817]);
# translating to qualified name based primaries
$measure->toRGB('RadianceRGB'); // returns RGB object, based on Radiance RGB primaries
# translating to custom based primaries
use tei187\ColorTools\Conversion\RGBPrimaries\Custom as CustomPrimaries;
$myPrimaries = new CustomPrimaries([
'R' => [ .648, .328, .212656 ],
'G' => [ .309, .598, .715158 ],
'B' => [ .157, .075, .072186 ]
], "My Primaries", "D65", 2.1);
$measure->toRGB($myPrimaries); // returns RGB object, based on custom-defined RGB primaries
Translating from device dependent to independent models will always use object-defined primaries, as such it is not required (and at this point, I believe, not possible) to pass different ones as an argument.