filter

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: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChromaticAberration added in v0.5.3

func ChromaticAberration(img image.Image, x_offset, y_offset int) image.Image

ChromaticAberration simulates the optical effect where different color channels appear misaligned, similar to lens distortion in photography.

This function shifts the red channel in one direction and the blue channel in the opposite direction, while keeping the green channel unchanged, creating a color fringing effect.

Parameters:

  • img: The source image to apply the effect to
  • x_offset: Horizontal offset for color channel shifting (range: 1-20, will be clamped)
  • y_offset: Vertical offset for color channel shifting (range: 1-20, will be clamped)

Returns:

  • A new image.Image

func GammaCorrection added in v0.5.3

func GammaCorrection(img image.Image, gamma float64) image.Image

GammaCorrection applies a non-linear adjustment to image luminance by raising each color channel to the power of gamma (output = input^gamma).

This transformation affects the brightness and contrast of an image non-uniformly:

  • Gamma > 1: Darkens the image, with more effect on midtones than shadows
  • Gamma < 0: Inverts the gamma effect (uses 1/-gamma), brightening the image
  • Gamma = 0: Defaults to gamma = 1 (no change)

The function clamps gamma values between -10 and 10 for predictable results. Alpha channel values remain unchanged during the transformation.

Parameters:

  • img: The source image to transform
  • gamma: Gamma correction factor (will be clamped to range [-10, 10])

Returns:

  • image.Image

func GrayScale

func GrayScale(img image.Image) image.Image

GrayScale converts the given image to grayscale using standard 8-bit color depth. This function transforms a color image to grayscale by applying the standard luminance conversion while preserving the original image dimensions.

Parameters:

  • img: The input image to be converted to grayscale

Returns:

  • image.Image: A new grayscale image with 8-bit color depth

func GrayScale16

func GrayScale16(img image.Image) image.Image

GrayScale16 converts the given image to grayscale using 16-bit color depth. This provides higher precision color conversion than the 8-bit version, maintaining more detail in images with subtle tonal variations.

Parameters:

  • img: The input image to be converted to grayscale

Returns:

  • image.Image: A new grayscale image with 16-bit color depth

func Invert added in v0.7.5

func Invert(img image.Image) image.Image

Invert creates a negative image by inverting all color channels of the input image. This function processes each pixel by subtracting its RGB values from the maximum possible value (65535 for 16-bit color depth), creating a photographic negative effect. The alpha channel remains unchanged to preserve the original transparency.

Parameters:

  • img: The source image to be inverted (can be any image.Image implementation)

Returns:

  • image.Image

func KuwaharaFilter added in v0.5.3

func KuwaharaFilter(img image.Image, size int) image.Image

KuwaharaFilter applies the Kuwahara filter to an image for edge-preserving smoothing. The filter works by dividing the area around each pixel into four quadrants, calculating the standard deviation for each, and replacing the pixel with the average color from the quadrant with the lowest standard deviation.

Parameters:

  • img: The input image to be filtered
  • size: Filter window size (1-30). Larger values create a stronger smoothing effect. Values are automatically clamped to the valid range.

Returns:

  • image.Image: The filtered image with edge-preserving noise reduction

The implementation uses parallel processing for improved performance.

func RGBToHSV added in v0.5.3

func RGBToHSV(c color.Color) float64

func SolarizeEffect added in v0.5.3

func SolarizeEffect(img image.Image, level int) image.Image

SolarizeEffect applies a solarization effect to an image, which simulates the effect of tone reversal observed in photographic film when it's extremely overexposed during development.

The effect inverts colors of pixels whose luminance exceeds a certain threshold determined by the level parameter. Higher level values will affect more pixels in the image, creating a more pronounced solarization effect.

Parameters:

  • img: The input image to apply the solarization effect to
  • level: Intensity of the effect, ranging from 1 (minimal) to 100 (maximum) This controls the luminance threshold above which colors will be inverted

Returns:

  • image.Image: A new image with the solarization effect applied

func VoronoiPixelation added in v0.5.3

func VoronoiPixelation(img image.Image, seed int) image.Image

VoronoiPixelation applies a Voronoi diagram-based pixelation effect to an image. This creates an abstract, mosaic-like pattern where the image is divided into irregular cell regions, each filled with a single color sampled from the original image.

The algorithm works by randomly placing seed points throughout the image and assigning each pixel to the closest seed point, inheriting its color. This creates organic, cell-like regions that form a distinctive artistic effect.

Parameters:

  • img: The input image to be processed
  • seed: Number of seed points to generate. Higher values (10-1000) create more detailed patterns with smaller cells, while lower values result in larger, more abstract shapes. Values are clamped between 1 and 100000. Increasing this value significantly will increase processing time.

Returns:

  • image.Image: The processed image with the Voronoi pixelation effect applied

The function uses parallel processing for improved performance on multi-core systems.

Types

type Point added in v0.5.3

type Point struct {
	X, Y  int
	Color color.Color
}

Jump to

Keyboard shortcuts

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