Documentation
¶
Index ¶
- func GlobalThreshold(img image.Image, level int) image.Image
- func GlobalThresholdColor(img image.Image, level int) image.Image
- func MultiThreshold(img image.Image, quantity int) image.Image
- func MultiThresholdColor(img image.Image, quantity int) image.Image
- func MultiThresholdRGB(img image.Image, c1, c2, c3 string) image.Image
- func ThresholdRGB(img image.Image) image.Image
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GlobalThreshold ¶
GlobalThreshold applies a global binary threshold to an image, converting it to a black and white image.
The function calculates the luminance of each pixel and compares it to the threshold level. Pixels with luminance above the threshold become white (255), while pixels below become black (0).
Parameters:
- img: The input image to be thresholded
- level: The threshold level, ranging from 1 to 100 (percentage of maximum pixel value) Lower values create more white pixels, higher values create more black pixels
Returns:
- image.Image: A new grayscale image with binary (black and white) pixels
func GlobalThresholdColor ¶ added in v0.7.5
GlobalThresholdColor applies a global binary threshold to an image, preserving color channels.
The function evaluates each color channel (R,G,B) independently against the threshold. For each channel, values above the threshold become maximum (65535), while values below become zero (0). The alpha channel remains unchanged, preserving transparency information.
Parameters:
- img: The input image to be thresholded
- level: The threshold level, ranging from 1 to 100 (percentage of maximum pixel value) Lower values create more bright colors, higher values create more dark areas
Returns:
- image.Image
func MultiThreshold ¶
MultiThreshold applies multiple thresholds to an image, creating a quantized grayscale effect.
The function converts the image to grayscale and then limits the pixel values to a specific set of thresholds, creating distinct visual bands.
Parameters:
- img: The input image to be processed
- quantity: The number of thresholds to apply, must be between 2-100 (will be clamped)
Returns:
- image.Image
func MultiThresholdColor ¶ added in v0.7.5
MultiThresholdColor applies multiple thresholds to an image while preserving color information.
Unlike MultiThreshold which produces a grayscale image, this function quantizes each RGB color channel separately, resulting in a color-banded effect with distinct color plateaus.
Parameters:
- img: The input image to be processed
- quantity: The number of thresholds to apply, must be between 2-10 (will be clamped)
Returns:
- image.Image
func MultiThresholdRGB ¶ added in v0.7.5
MultiThresholdRGB applies a multi-level thresholding effect to an image based on the luminance of each pixel. It divides pixels into five ranges based on their luminance (calculated using 16-bit precision) and assigns colors accordingly.
Pixels with luminance >= 53083 (approx. 81% of 65535) are set to white. Pixels with luminance >= 39976 (approx. 61%) are colored based on the c1 parameter. Pixels with luminance >= 26869 (approx. 41%) are colored based on the c2 parameter. Pixels with luminance >= 13762 (approx. 21%) are colored based on the c3 parameter. Pixels with luminance < 13762 are set to black.
The c1, c2, and c3 parameters specify the color channel to preserve for their respective luminance ranges. Valid values are "red", "green", or "blue". If a parameter is not one of these values, the original pixel color is used for that range. For "red", only the red channel is kept, green and blue are set to 0. For "green", only the green channel is kept, red and blue are set to 0. For "blue", only the blue channel is kept, red and green are set to 0. The alpha channel is always preserved from the original pixel.
Parameters:
- img: The input image (image.Image) to be thresholded.
- c1: The color ("red", "green", "blue", or other for original) for the luminance range [39976, 53083).
- c2: The color ("red", "green", "blue", or other for original) for the luminance range [26869, 39976).
- c3: The color ("red", "green", "blue", or other for original) for the luminance range [13762, 26869).
Returns:
- image.Image
func ThresholdRGB ¶ added in v0.7.5
ThresholdRGB processes an image pixel by pixel. For each pixel, it determines which color channel (Red, Green, or Blue) has the highest value. It then creates a new pixel where only the dominant color channel's value is retained, setting the other two color channels to zero. The alpha channel is preserved from the original pixel. If no single channel is dominant (e.g., multiple channels have the same highest value, or all are zero), the resulting pixel's RGB values are all set to zero.
Parameters:
- img: The input image (image.Image) to be thresholded.
Returns:
- image.Image
Types ¶
This section is empty.