convolution

package
v0.0.0-...-d61e921 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvolveGray

func ConvolveGray(img *image.Gray, kernel *Kernel, anchor image.Point, border padding.Border) (*image.Gray, error)

ConvolveGray applies a convolution matrix (kernel) to a grayscale image. Example of usage:

res, err := convolution.ConvolveGray(img, kernel, {1, 1}, BorderReflect)

Note: the anchor represents a point inside the area of the kernel. After every step of the convolution the position specified by the anchor point gets updated on the result image.

func ConvolveRGBA

func ConvolveRGBA(img *image.RGBA, kernel *Kernel, anchor image.Point, border padding.Border) (*image.RGBA, error)

ConvolveRGBA applies a convolution matrix (kernel) to an RGBA image. Example of usage:

res, err := convolution.ConvolveRGBA(img, kernel, {1, 1}, BorderReflect)

Note: the anchor represents a point inside the area of the kernel. After every step of the convolution the position specified by the anchor point gets updated on the result image.

Types

type Kernel

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

Kernel is a 2 dimensional matrix used mainly for convolution.

func NewKernel

func NewKernel(width int, height int) (*Kernel, error)

NewKernel creates a new Kernel with the given width and height. The value for every position of the kernel is 0.

func (*Kernel) AbSum

func (k *Kernel) AbSum() float64

AbSum returns the sum of every absolute value from a kernel.

func (*Kernel) At

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

At returns a value from the position of {x, y} of a kernel.

func (*Kernel) Normalize

func (k *Kernel) Normalize() *Kernel

Normalize returns a normalized kernel where each value is divided by the absolute sum of the kernel.

func (*Kernel) Set

func (k *Kernel) Set(x int, y int, value float64)

Set sets a value at a given {x, y} position

func (*Kernel) Size

func (k *Kernel) Size() image.Point

Size returns the size of the kernel. The size is a type of image.Point containing the width and height of the kernel.

type Matrix

type Matrix interface {
	At(x, y int) float64
}

Matrix interface for the Kernel

Jump to

Keyboard shortcuts

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