pnn

package
v0.0.0-...-b8e17cf Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LinearCost

func LinearCost(a, b *Node) float64

Calculates the cost of merging two greyscale clusters, it represents the increase in MSE value caused by the merge

func QuantiseGreyscale

func QuantiseGreyscale(img image.Image, m int) color.Palette

Returns "m" greyscale colours to best recreate the colour palette of the original image

func Sqr

func Sqr(a float64) float64

Squares a float64 number

func VectorCost

func VectorCost(a, b *Node) float64

Calculates the cost of merging two colour clusters, it represents the increase in MSE value caused by the merge

Types

type Heap

type Heap []*Node

Implements a Heap of Nodes used for PNN

func (*Heap) Front

func (h *Heap) Front() interface{}

func (Heap) Len

func (h Heap) Len() int

func (Heap) Less

func (h Heap) Less(i, j int) bool

func (*Heap) Pop

func (h *Heap) Pop() interface{}

func (*Heap) Push

func (h *Heap) Push(x interface{})

func (Heap) Swap

func (h Heap) Swap(i, j int)

func (*Heap) Update

func (h *Heap) Update(node *Node, d float64)

type Histogram

type Histogram map[uint32]*Node

Histogram for PNN Nodes which are coloured

func CreatePNNHistogram

func CreatePNNHistogram(img image.Image) Histogram

Creates a PNN Histogram

type Node

type Node struct {
	Prev  *Node   // Pointer to the previous Node
	Next  *Node   // Pointer to the Next Node
	D     float64 // Merge cost value, indicating the increase in the MSE if the two classes are merged (this class and the one to the right)
	N     float64 // Number of pixels in the class
	Index int     // Index of the Node in the heap

	// Variables for greyscale quantisation
	C float64 // Mean grey level of the class
	T uint8   // Maximal grey value, also serves as threshold between the class and its neighbour class to the right

	// Variables for colour quantisation
	colours.RGB         // RGB Values of the node
	A           float64 // Alpha Value of the node (Used for non-LAB PNN)
	NN          *Node   // Pointers to the nearest neighbour
	MergeCount  int     // The iteration where the node was last merged with another
	UpdateCount int     // The iteration where the MSE was last calculated for the node
}

Node holding Colour data for PNN

type PNNMode

type PNNMode uint8

Used as a variable for each pnn operation to determine what type of distance calculation to use, this variable is available for the whole scope of the pnn operation

const (
	RGB PNNMode = iota
	LAB
)

Which colour mode to use when calculating the distances between colours

func (PNNMode) QuantiseColour

func (mode PNNMode) QuantiseColour(img image.Image, M int) color.Palette

Quantises a given into a palette of "m" colours to best represent it

Jump to

Keyboard shortcuts

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