imgutil

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package imgutil implements a set of image processing utilities. Funcs in this package perform modifications in-place, except where otherwise noted.

Index

Constants

This section is empty.

Variables

View Source
var (
	// CatmullRom is the Catmull-Rom kernel. It is very slow, but usually gives
	// very high quality results.
	//
	// It is an instance of the more general cubic BC-spline kernel with parameters
	// B=0 and C=0.5. See Mitchell and Netravali, "Reconstruction Filters in
	// Computer Graphics", Computer Graphics, Vol. 22, No. 4, pp. 221-228.
	CatmullRom = &Kernel{2, func(t float64) float64 {
		if t < 1 {
			return (1.5*t-2.5)*t*t + 1
		}
		return ((-0.5*t+2.5)*t-4)*t + 2
	}}
)

Functions

func AdjustGamma

func AdjustGamma(img *image.Gray, gamma float64)

AdjustGamma applies gamma adjustments.

Gamma value of 1 doesn't change the image, < 1 darkens and >1 brightens it.

func AutoContrast

func AutoContrast(img *image.Gray, cutoff float64)

AutoContrast applies histogram normalization to the image, ignoring specified cutoff % highest and lowest values.

This implementation is taken from Pillow's ImageOps.autocontrast method. See: https://pillow.readthedocs.io/en/stable/_modules/PIL/ImageOps.html#autocontrast

func FitRect added in v0.1.1

func FitRect(rect image.Rectangle, x, y int) image.Rectangle

FitRect scales an image.Rectangle to fit into a bounding box of x by y without changing the aspect ratio.

func Grayscale

func Grayscale(img image.Image) *image.Gray

Grayscale returns an image converted to grayscale. It always returns a copy.

func Histogram

func Histogram(img *image.Gray) [256]uint

Histogram returns a histogram of a grayscale image.

Resulting histogram is represented as a fixed length array of 256 unsigned integers, where histogram[i] is the amount of pixels of value i present in the image.

Types

type ImagePool added in v0.1.2

type ImagePool struct {
	// contains filtered or unexported fields
}

ImagePool maintains a sync.Pool of pixel arrays for each image resolution gotten from it.

func NewImagePool added in v0.1.2

func NewImagePool() *ImagePool

NewImagePool creates an ImagePool.

func (*ImagePool) Get added in v0.1.2

func (p *ImagePool) Get(width, height int) *image.Gray

Get gets a grayscale image of specified width and height with pixel slice taken from the pool.

func (*ImagePool) GetFromImage added in v0.1.2

func (p *ImagePool) GetFromImage(img image.Image) *image.Gray

GetFromImage converts an image into a grayscale image with pixel slice taken from the pool.

func (*ImagePool) Put added in v0.1.2

func (p *ImagePool) Put(img *image.Gray)

Put puts an images pixel slice back into the pool.

type Kernel added in v0.1.1

type Kernel struct {
	// Support is the kernel support and must be >= 0. At(t) is assumed to be
	// zero when t >= Support.
	Support float64
	// At is the kernel function. It will only be called with t in the
	// range [0, Support).
	At func(t float64) float64
}

Kernel is an interpolator that blends source pixels weighted by a symmetric kernel function.

func (*Kernel) NewScaler added in v0.1.1

func (q *Kernel) NewScaler(dw, dh, sw, sh int) Scaler

NewScaler returns a Scaler that is optimized for scaling multiple times with the same fixed destination and source width and height.

func (*Kernel) Scale added in v0.1.1

func (q *Kernel) Scale(dst, src *image.Gray)

Scale implements the Scaler interface.

type Scaler added in v0.1.1

type Scaler interface {
	Scale(dst, src *image.Gray)
}

Scaler scales the source image to the destination image.

func NewCacheScaler added in v0.1.2

func NewCacheScaler(k *Kernel) Scaler

NewCacheScaler creates, caches and reuses kernel scalers optimized for each unique combination of destination and source width and height. It is mostly useful when scaling a large quantity of images in a few fixed sizes.

Jump to

Keyboard shortcuts

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