Skip to content

Advanced enhancement, local contrast, and edge detection

Copy page

Enhancement is not a single “make it better” switch. Each variant shows the generated output first, followed by the corresponding binding code.

sigma: 2 reduces high-frequency detail. The reference output was generated with govips v2.19.0 / libvips 8.17.3.

Night architecture photo softened with Gaussian blur (Sigma 4.0)
WEBP1938 × 1292, 92,650 bytes, 3 bands

Generated with govips v2.19.0 / libvips 8.17.3.

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

The example uses sigma: 2 and explicit mask parameters. Sharpening can also amplify noise and compression artefacts.

Night architecture photo sharpened on the LAB lightness channel
WEBP1938 × 1292, 618,758 bytes, 3 bands

Generated with govips v2.19.0 / libvips 8.17.3.

if err := image.Sharpen(2, 2, 3); err != nil { return err }
data, _, err := image.ExportWebp(vips.NewWebpExportParams())
if err != nil { return err }
return os.WriteFile("sharpen.webp", data, 0o644)

1.5 is this example’s exponent, not a universal default.

Night architecture photo after gamma and linear contrast adjustment
WEBP1938 × 1292, 490,284 bytes, 3 bands

Generated with govips v2.19.0 / libvips 8.17.3.

if err := image.Gamma(1.5); err != nil { return err }
data, _, err := image.ExportWebp(vips.NewWebpExportParams())
if err != nil { return err }
return os.WriteFile("gamma.webp", data, 0o644)

govips and the CLI use Sobel directly; sharp and pyvips execute the same Sobel kernel with convolve() / conv(). All four outputs were generated, but convolution borders and encoding differences still need comparison in the target use case.

Single-band grayscale Sobel edge detection output of the night architecture photo
WEBP1938 × 1292, 943,036 bytes, 3 bands

Generated with govips v2.19.0 / libvips 8.17.3.

if err := image.Sobel(); err != nil { return err }
data, _, err := image.ExportWebp(vips.NewWebpExportParams())
if err != nil { return err }
return os.WriteFile("edge.webp", data, 0o644)

sharp also exposes normalise(), clahe(), and arbitrary convolve(). Only the actually executed Sobel edge detection has a cross-binding output on this page. normalise() and clahe() have no matching govips v2.19.0 high-level public entry point, so no invented govips implementation is shown. That gap does not mean libvips lacks the operation, and internal vipsGen* functions are not a stable application API.