Skip to content

Brightness, saturation, and hue adjustment

Copy page

These operations all change pixel appearance, but they are not interchangeable: brightness changes lightness, saturation changes colour intensity, and hue rotates a colour around the wheel. Each section covers one variant and pairs its image with the corresponding code.

Gate of the Orient night photograph used for colour adjustments
Input: JPEG1938 × 1292, a maintainer-owned photograph with embedded sRGB ICC

Reference outputs were generated with govips v2.20.0 / libvips 8.17.3 in the locked Docker Runner. pyvips and the CLI do not provide a single-call saturation/hue modulation helper and are marked not-supported for those two variants. Image 0.72.0 calls Image.modulate/2 and has only had its metadata checked.

govips.Modulate(1.25, 1, 0) raises brightness in LCh; sharp uses HSL semantics. The pyvips and CLI snippets use RGB linear multiplication as an approximation, not a pixel-equivalent implementation.

Gate of the Orient night photograph used for colour adjustments
Original · JPEG
Gate of the Orient night photograph with increased brightness
Brightness adjustment · WEBP1938 × 1292, 493,936 bytes, 3 bands

Generated with govips v2.20.0 / libvips 8.17.3.

image, err := vips.NewImageFromFile("input.jpg")
if err != nil { return err }
defer image.Close()
if err := image.Modulate(1.25, 1, 0); err != nil { return err }
data, _, err := image.ExportWebp(vips.NewWebpExportParams())
if err != nil { return err }
return os.WriteFile("brightness.webp", data, 0o644)

govips and sharp expose a direct Modulate / modulate entry point. Because pyvips and the CLI do not ship a single-step modulation helper, they are marked not-supported below rather than presenting an unmodified copy as a saturation transform.

Gate of the Orient night photograph used for colour adjustments
Original · JPEG
Gate of the Orient night photograph with reduced saturation
Saturation adjustment · WEBP1938 × 1292, 377,568 bytes, 3 bands

Generated with govips v2.20.0 / libvips 8.17.3.

if err := image.Modulate(1, 0.35, 0); err != nil { return err }

Hue is an angular offset; 60 means a 60-degree rotation. govips performs Modulate in LCh, while sharp uses HSL/LCh modulation semantics, so equal numbers do not guarantee equal pixels.

Gate of the Orient night photograph used for colour adjustments
Original · JPEG
Gate of the Orient night photograph with rotated hue
Hue adjustment · WEBP1938 × 1292, 396,680 bytes, 3 bands

Generated with govips v2.20.0 / libvips 8.17.3.

if err := image.Modulate(1, 1, 60); err != nil { return err }

Colour recombination (Recomb), inversion (Invert), and lookup tables (Maplut)

Section titled “Colour recombination (Recomb), inversion (Invert), and lookup tables (Maplut)”

Beyond brightness, saturation, and hue, the four interfaces support three additional colour transforms:

  • 3×3 colour recombination matrix (Recomb / recomb): mixes R, G, and B channels through a 3×3 matrix for sepia toning, channel swapping, or colour-vision deficiency simulation.
  • Colour inversion (Invert / negate / invert): maps 8-bit channels to 255 - x (sharp.negate({ alpha: false }) inverts RGB channels while leaving alpha untouched).
  • HSV modulation and 1D lookup tables (ModulateHSV / Maplut): govips also provides image.ModulateHSV(b, s, h) in HSV colour space and image.Maplut(lut) (paired with vips.Identity(false)) for custom tone curves.
// 1. 3×3 sepia colour recombination matrix
sepia := [][]float64{
{0.3588, 0.7044, 0.1368},
{0.2990, 0.5870, 0.1140},
{0.2392, 0.4696, 0.0912},
}
if err := image.Recomb(sepia); err != nil {
return err
}
// 2. Invert colour channels
if err := image.Invert(); err != nil {
return err
}