convolution

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: MIT Imports: 5 Imported by: 20

Documentation

Overview

Package convolution provides the functionality to create and apply a kernel to an image.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convolve

func Convolve(img image.Image, k Matrix, o *Options) *image.RGBA

Convolve applies a convolution matrix (kernel) to an image with the supplied options.

Usage example:

result := Convolve(img, kernel, &Options{Bias: 0, Wrap: false})

Types

type Kernel

type Kernel struct {
	Matrix []float64
	Width  int
	Height int
}

Kernel to be used as a convolution matrix.

func NewKernel

func NewKernel(width, height int) *Kernel

NewKernel returns a kernel of the provided length.

func (*Kernel) Absum

func (k *Kernel) Absum() float64

Absum returns the absolute cumulative value of the kernel.

func (*Kernel) At

func (k *Kernel) At(x, y int) float64

At returns the matrix value at position x, y.

func (*Kernel) MaxX

func (k *Kernel) MaxX() int

MaxX returns the horizontal length.

func (*Kernel) MaxY

func (k *Kernel) MaxY() int

MaxY returns the vertical length.

func (*Kernel) Normalized

func (k *Kernel) Normalized() Matrix

Normalized returns a new Kernel with normalized values.

func (*Kernel) String

func (k *Kernel) String() string

String returns the string representation of the matrix.

func (*Kernel) Transposed added in v0.11.1

func (k *Kernel) Transposed() Matrix

Transposed returns a new Kernel that has the columns as rows and vice versa

type Matrix

type Matrix interface {
	At(x, y int) float64
	Normalized() Matrix
	MaxX() int
	MaxY() int
	Transposed() Matrix
}

Matrix interface. At returns the matrix value at position x, y. Normalized returns a new matrix with normalized values. MaxX returns the horizontal length. MaxY returns the vertical length.

type Options

type Options struct {
	Bias      float64
	Wrap      bool
	KeepAlpha bool
}

Options are the Convolve function parameters. Bias is added to each RGB channel after convoluting. Range is -255 to 255. Wrap sets if indices outside of image dimensions should be taken from the opposite side. KeepAlpha sets if alpha should be convolved or kept from the source image.

Jump to

Keyboard shortcuts

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