contrast

package
v0.7.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LinearContrastStretching

func LinearContrastStretching(img image.Image) image.Image

LinearContrastStretching applies Linear Contrast Stretching to enhance an image's contrast.

This function improves the visual quality of an image by expanding its intensity range to utilize the full dynamic range (0-255) for each color channel independently. It first identifies the minimum and maximum values for each RGB channel across the entire image, then applies a linear transformation to stretch these values across the full available range. The alpha channel remains unchanged.

Parameters:

  • img: The input image to be enhanced

Returns:

  • image.Image: A new image with enhanced contrast while preserving the original colors

func LinearContrastStretchingGrayscale

func LinearContrastStretchingGrayscale(img image.Image) image.Image

LinearContrastStretchingGrayscale applies Linear Contrast Stretching to an image and converts it to grayscale.

This function enhances the contrast of the image by stretching the intensity values to cover the full range (0-255). It first finds the minimum and maximum intensity values in the image, then linearly scales all pixel values between these extremes to fill the entire available range. The image is converted to grayscale during this process by averaging the RGB channels.

Parameters:

  • img: The input image to be enhanced and converted to grayscale

Returns:

  • image.Image

func LogarithmicTransformation

func LogarithmicTransformation(img image.Image, variation float64) image.Image

LogarithmicTransformation applies logarithmic transformation to an image, which can enhance details in darker regions while compressing higher intensity values.

The transformation follows the formula: output = log(1 + variation*pixel) / log(1 + variation) where pixel values are normalized to the range [0,1].

Parameters:

  • img: The input image to be transformed
  • variation: Controls the strength and direction of the transformation Range: [-1,1]. Positive values enhance dark regions, negative values enhance bright regions. Values 0 and -1 are automatically adjusted to 0.1 and -0.99 respectively to avoid mathematical issues.

Returns:

  • image.Image

func UnsharpMasking

func UnsharpMasking(img image.Image, variation float64, blurLevel int) image.Image

UnsharpMasking applies the Unsharp Masking algorithm to sharpen an image by subtracting a blurred version from the original, enhancing fine details and edge definition.

Unsharp masking works by creating a blurred copy of the image, then amplifying the difference between the original and blurred version to enhance image details.

Parameters:

  • img: The input image to be sharpened
  • variation: A value between 0.0 and 1.0 that controls sharpening intensity. At 0.0, no sharpening occurs, while 1.0 applies maximum sharpening effect.
  • blurLevel: An integer from 1 to 20 (clamped internally) that determines the radius of the Gaussian blur applied. Lower values produce finer detail enhancement, while higher values affect larger features.

Returns:

  • image.Image

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL