HUGO
Menu
GitHub 90529 stars Mastodon

images.UnsharpMask

Returns an image filter that sharpens an image.
Syntax
images.UnsharpMask SIGMA AMOUNT THRESHOLD
Returns
images.filter

Usage

The images.UnsharpMask function returns an image filter that sharpens an image. The filter compares each pixel with a blurred copy of the image, then increases the difference between them. This makes the light side of each edge lighter and the dark side darker.

Arguments

SIGMA
(float) The size of the detail to sharpen, in pixels. The filter creates the blurred copy by blending each pixel with neighboring pixels up to three times this distance away. Use a small value, such as 1, to sharpen fine detail, and a larger value to sharpen broader edges. A value of 0 or less has no effect.
AMOUNT
(float) The strength of the sharpening, as a multiple of the difference between each pixel and the blurred copy. A value of 1 doubles the difference, and a value of 0 has no effect. Typical values are in the range [0.5, 1.5].
THRESHOLD
(float) The minimum difference in brightness between a pixel and the blurred copy that the filter sharpens, on a scale from 0 to 1. Use a value greater than 0 to avoid sharpening noise in smooth areas, such as the sky. A value of 0 sharpens every pixel. Typical values are in the range [0, 0.05].

Examples

{{ $filter := images.UnsharpMask 1 1 0.03 }}

Applying the filter with the images.Filter function:

{{ with resources.Get "images/original.jpg" }}
  {{ with . | images.Filter $filter }}
    <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
  {{ end }}
{{ end }}

Applying the filter with the Filter method on a Resource object:

{{ with resources.Get "images/original.jpg" }}
  {{ with .Filter $filter }}
    <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
  {{ end }}
{{ end }}

This is the original image:

Zion National Park

This is the processed image:

Zion National Park