Operator index > By section > Colour [src]
These operators let you transform coordinates and images between colour spaces, calculate colour differences, and move to and from device spaces.
All operations process colour from the first few bands and pass other bands through unaltered. This means you can operate on images with alpha channels safely. If you move to or from 16-bit RGB, any alpha channels are rescaled for you.
Radiance images have four 8-bits bands and store 8 bits of R, G and B and another 8 bits of exponent, common to all channels. They are widely used in the HDR imaging community.
The colour functions can be divided into three main groups. First,
functions to transform images between the different colour spaces supported
by libvips:
VIPS_INTERPRETATION_sRGB, VIPS_INTERPRETATION_scRGB,
VIPS_INTERPRETATION_B_W, VIPS_INTERPRETATION_XYZ,
VIPS_INTERPRETATION_YXY, VIPS_INTERPRETATION_LAB,
VIPS_INTERPRETATION_LCH, and VIPS_INTERPRETATION_CMC.
There are also a set of minor colourspaces which are one of the above in a
slightly different format:
VIPS_INTERPRETATION_LAB, VIPS_INTERPRETATION_LABQ,
VIPS_INTERPRETATION_LABS, VIPS_INTERPRETATION_LCH,
VIPS_INTERPRETATION_RGB16, and VIPS_INTERPRETATION_GREY16.
Use vips_colourspace() to move an image to a target colourspace
using the best sequence of colour transform operations.
Secondly, there are a set of operations for calculating colour difference metrics. Finally, libvips wraps LittleCMS and uses it to provide a set of operations for reading and writing images with ICC profiles.
This figure shows how the libvips colour spaces interconvert:

The colour spaces supported by libvips are:
-
VIPS_INTERPRETATION_LAB: CIELAB ‘76 colourspace with a D65 white. This uses three floats for each band, and bands have the obvious range.
There are two variants,VIPS_INTERPRETATION_LABQandVIPS_INTERPRETATION_LABS, which use ints to store values. These are less precise, but can be quicker to store and process.
VIPS_INTERPRETATION_LCHis the same, but with a*b* as polar coordinates. Hue is expressed in degrees. -
VIPS_INTERPRETATION_XYZ: CIE XYZ. This uses three floats. SeeVIPS_D75_X0and friends for values for the ranges under various illuminants.
VIPS_INTERPRETATION_YXYis the same, but with little x and y. -
VIPS_INTERPRETATION_scRGB: a linear colourspace with the sRGB primaries. This is useful if you need linear light and don’t care much what the primaries are.
Linearization is performed with the usual sRGB equations, see below. -
VIPS_INTERPRETATION_sRGB: the standard sRGB colourspace, see: wikipedia sRGB.
This uses three 8-bit values for each of RGB.
VIPS_INTERPRETATION_RGB16is the same, but using three 16-bit values for RGB.
VIPS_INTERPRETATION_HSVis sRGB, but in polar coordinates.VIPS_INTERPRETATION_LCHis much better, only use HSV if you have to. -
VIPS_INTERPRETATION_B_W: a monochrome image, roughly G from sRGB. The grey value is calculated in linearVIPS_INTERPRETATION_scRGBspace with RGB ratios 0.2126, 0.7152, 0.0722 as defined by CIE 1931 linear luminance.
VIPS_INTERPRETATION_GREY16is the same, but using 16 bits. -
VIPS_INTERPRETATION_CMC: a colour space based on the CMC(1:1) colour difference measurement. This is a highly uniform colour space, and much better than CIELAB for expressing small differences.
The CMC colourspace is described in “Uniform Colour Space Based on the CMC(l:c) Colour-difference Formula”, M R Luo and B Rigg, Journal of the Society of Dyers and Colourists, vol 102, 1986. Distances in this colourspace approximate, within 10% or so, differences in the CMC(l:c) colour difference formula.
You can calculate metrics like CMC(2:1) by scaling the spaces before finding differences.
Functions
vips_colourspace_issupported()vips_colourspace()vips_LabQ2sRGB()vips_rad2float()vips_float2rad()vips_LabS2LabQ()vips_LabQ2LabS()vips_LabQ2Lab()vips_Lab2LabQ()vips_LCh2Lab()vips_Lab2LCh()vips_Lab2XYZ()vips_XYZ2Lab()vips_XYZ2scRGB()vips_scRGB2sRGB()vips_scRGB2BW()vips_sRGB2scRGB()vips_scRGB2XYZ()vips_HSV2sRGB()vips_sRGB2HSV()vips_LCh2CMC()vips_CMC2LCh()vips_XYZ2Yxy()vips_Yxy2XYZ()vips_LabS2Lab()vips_Lab2LabS()vips_CMYK2XYZ()vips_XYZ2CMYK()vips_profile_load()vips_icc_present()vips_icc_transform()vips_icc_import()vips_icc_export()vips_icc_ac2rc()vips_icc_is_compatible_profile()vips_dE76()vips_dE00()vips_dECMC()vips_col_Lab2XYZ()vips_col_XYZ2Lab()vips_col_ab2h()vips_col_ab2Ch()vips_col_Ch2ab()vips_col_L2Lcmc()vips_col_C2Ccmc()vips_col_Ch2hcmc()vips_col_make_tables_CMC()vips_col_Lcmc2L()vips_col_Ccmc2C()vips_col_Chcmc2h()vips_col_sRGB2scRGB_8()vips_col_sRGB2scRGB_16()vips_col_sRGB2scRGB_8_noclip()vips_col_sRGB2scRGB_16_noclip()vips_col_scRGB2XYZ()vips_col_XYZ2scRGB()vips_col_scRGB2sRGB_8()vips_col_scRGB2sRGB_16()vips_col_scRGB2BW_16()vips_col_scRGB2BW_8()vips_pythagoras()vips_col_dE00()
Constants
VIPS_D93_X0VIPS_D93_Y0VIPS_D93_Z0VIPS_D75_X0VIPS_D75_Y0VIPS_D75_Z0VIPS_D65_X0VIPS_D65_Y0VIPS_D65_Z0VIPS_D55_X0VIPS_D55_Y0VIPS_D55_Z0VIPS_D50_X0VIPS_D50_Y0VIPS_D50_Z0VIPS_A_X0VIPS_A_Y0VIPS_A_Z0VIPS_B_X0VIPS_B_Y0VIPS_B_Z0VIPS_C_X0VIPS_C_Y0VIPS_C_Z0VIPS_E_X0VIPS_E_Y0VIPS_E_Z0VIPS_D3250_X0VIPS_D3250_Y0VIPS_D3250_Z0