image

package
v0.0.0-...-716269e Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2024 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Overview

Package image contains functions that mostly operate on image.Gray.

Logical Operations

And
Or
Xor
Not
Sub
Equal
Copy

Morphological Operations

Dilate
Erode
Open
Close
TopHat
BotHat
HitOrMiss
Thin
Skeleton
LJSkeleton
LJReconstitute

Remap Operations

ColorConvert
RemapGray
RemapRGBA

Channel Operations

ExtractChannel
ReplaceChannel
SwitchChannels
CombineChannels

Various metrics

Histogram
CDF
Variance

Image types:

Patch - replicates a patch of colors across the plane like Uniform does for a single color
Tile - replicates an image across the plane

Index

Constants

This section is empty.

Variables

View Source
var (

	// Z0 the point itself
	Z0 = [][]bool{
		{true},
	}

	// Z4 3x3 Von Neumann 4-way
	Z4 = [][]bool{
		{false, true, false},
		{true, true, true},
		{false, true, false},
	}

	// X4 3x3 X
	X4 = [][]bool{
		{true, false, true},
		{false, true, false},
		{true, false, true},
	}

	// Z8 3x3 Moore 8-way
	Z8 = [][]bool{
		{true, true, true},
		{true, true, true},
		{true, true, true},
	}

	// Cross5x5 5x5 cross
	Cross5x5 = [][]bool{
		{false, false, true, false, false},
		{false, false, true, false, false},
		{true, true, true, true, true},
		{false, false, true, false, false},
		{false, false, true, false, false},
	}

	// X5 5x5 X
	X5 = [][]bool{
		{true, false, false, false, true},
		{false, true, false, true, false},
		{false, false, true, false, false},
		{false, true, false, true, false},
		{true, false, false, false, true},
	}

	// Star5x5 5x5 star
	Star5x5 = [][]bool{
		{true, false, true, false, true},
		{false, true, true, true, false},
		{true, true, true, true, true},
		{false, true, true, true, false},
		{true, false, true, false, true},
	}

	// Diamond5x5 5x5 diamond
	Diamond5x5 = [][]bool{
		{false, false, true, false, false},
		{false, true, true, true, false},
		{true, true, true, true, true},
		{false, true, true, true, false},
		{false, false, true, false, false},
	}

	// Ball5x5 5x5 ball
	Ball5x5 = [][]bool{
		{false, true, true, true, false},
		{true, true, true, true, true},
		{true, true, true, true, true},
		{true, true, true, true, true},
		{false, true, true, true, false},
	}

	// All5x5 5x5 block
	All5x5 = [][]bool{
		{true, true, true, true, true},
		{true, true, true, true, true},
		{true, true, true, true, true},
		{true, true, true, true, true},
		{true, true, true, true, true},
	}

	C11 = [][]bool{
		{false, false, false},
		{false, true, false},
		{true, true, true},
	}
	D11 = [][]bool{
		{true, true, true},
		{false, false, false},
		{false, false, false},
	}

	C12 = [][]bool{
		{true, false, false},
		{true, true, false},
		{true, false, false},
	}
	D12 = [][]bool{
		{false, false, true},
		{false, false, true},
		{false, false, true},
	}

	C13 = [][]bool{
		{true, true, true},
		{false, true, false},
		{false, false, false},
	}
	D13 = [][]bool{
		{false, false, false},
		{false, false, false},
		{true, true, true},
	}

	C14 = [][]bool{
		{false, false, true},
		{false, true, true},
		{false, false, true},
	}
	D14 = [][]bool{
		{true, false, false},
		{true, false, false},
		{true, false, false},
	}

	C21 = [][]bool{
		{false, false, false},
		{true, true, false},
		{true, true, false},
	}
	D21 = [][]bool{
		{false, true, true},
		{false, false, true},
		{false, false, false},
	}

	C22 = [][]bool{
		{true, true, false},
		{true, true, false},
		{false, false, false},
	}
	D22 = [][]bool{
		{false, false, false},
		{false, false, true},
		{false, true, true},
	}

	C23 = [][]bool{
		{false, true, true},
		{false, true, true},
		{false, false, false},
	}
	D23 = [][]bool{
		{false, false, false},
		{true, false, false},
		{true, true, false},
	}

	C24 = [][]bool{
		{false, false, false},
		{false, true, true},
		{false, true, true},
	}
	D24 = [][]bool{
		{true, true, false},
		{true, false, false},
		{false, false, false},
	}
)

Functions

func AlphaAnd

func AlphaAnd(img1, img2 *image.Alpha, offs image.Point) *image.Alpha

AlphaAnd returns img1 & img2 (intersection). For a pair of pixels, p1 & p2 returns min(p1, p2).

func AlphaCopy

func AlphaCopy(img *image.Alpha) *image.Alpha

AlphaCopy returns a deep copy of img.

func AlphaEqual

func AlphaEqual(img1, img2 *image.Alpha, offs image.Point) bool

AlphaEqual returns true if two images are the same.

func AlphaNot

func AlphaNot(img *image.Alpha) *image.Alpha

AlphaNot returns 1 - img.

func AlphaOr

func AlphaOr(img1, img2 *image.Alpha, offs image.Point) *image.Alpha

AlphaOr returns img1 | img2 (union). For a pair of pixels, p1 | p2 returns max(p1, p2).

func AlphaSub

func AlphaSub(img1, img2 *image.Alpha, offs image.Point) *image.Alpha

AlphaSub returns img1 - img2 (img1 minus the intersection of img1 and img2). For a pair of pixels, p1 - p2 returns min(p1, 1-p2).

func AlphaToGray

func AlphaToGray(a *image.Alpha) *image.Gray

AlphaToGray does a shallow copy (vs going through the ColorModel).

func AlphaXor

func AlphaXor(img1, img2 *image.Alpha, offs image.Point) *image.Alpha

AlphaXor returns img1 ^ img2 (union - intersection). For a pair of pixels, p1 ^ p2 returns min(max(p1, p2), 1-min(p1, p2)).

func And

func And(img1, img2 image.Image, offs image.Point) *image.Gray

And returns the result of ANDing img1 with img2, offset by offs (intersection). The images are converted to image.Gray if not already so. For a pair of pixels, p1 & p2 returns min(p1, p2).

func AvgOp

func AvgOp(values [][]uint8, support [][]bool) uint8

AvgOp finds the average value (rounded down) of all the values that have the support set.

func BotHat

func BotHat(img image.Image, support [][]bool) *image.Gray

BotHat is the subtraction of the original from a close.

func CDF

func CDF(hist []int) []float64

CDF computes the normalized cummulative distribution function of the histogram.

func Close

func Close(img image.Image, support [][]bool) *image.Gray

Close applies an erosion to a prior dilation.

func ColorConvert

func ColorConvert(img *image.NRGBA, xfm *Aff5) *image.NRGBA

ColorConvert runs NRGBA through the supplied affine transform.

func CombineChannels

func CombineChannels(chR, chG, chB, chA *image.Gray, scale bool) *image.RGBA

CombineChannels combines mono-channel images into a single image. The R, G, B channels will be scaled by alpha if scale is true.

func Copy

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

Copy creates a grayscale copy of img

func CopyAlpha

func CopyAlpha(in *image.Alpha) *image.Alpha

CopyAlpha clones an Alpha image.

func CopyGray

func CopyGray(in *image.Gray) *image.Gray

CopyGray clones a Gray image.

func CopyGray16

func CopyGray16(in *image.Gray16) *image.Gray16

CopyGray16 clones a Gray16 image.

func CopyRGBA

func CopyRGBA(in *image.RGBA) *image.RGBA

CopyRGBA clones an RGBA image.

func CreateLutFromValues

func CreateLutFromValues(values []float64) []uint8

CreateLutFromValues maps a series of values in [0,1] to [0,255] Note - no checking on values range

func Dilate

func Dilate(img image.Image, support [][]bool) *image.Gray

Dilate replaces each pixel with the max of the pixels in its support.

func Displace

func Displace(img draw.Image, r image.Rectangle, xchan image.Image, xoffs image.Point, xscale float64,
	ychan image.Image, yoffs image.Point, yscale float64)

Displace displaces the image within the rectangle by the amounts referenced in the other two images (one each for X and Y) scaled. If the displaced location exceeds the bounds of the rectangle, it is wrapped. Black maps to scale * -0.5 and white to scale * 0.5.

func Equal

func Equal(img1, img2 image.Image, offs image.Point) bool

Equal returns true if img1 within img2 at offset offs, matches.

func Erode

func Erode(img image.Image, support [][]bool) *image.Gray

Erode replaces each pixel with the min of the pixels in its support.

func ExtractChannel

func ExtractChannel(img *image.RGBA, ch int) *image.Gray

ExtractChannel returns an image with just the selected channel. The returned image is scaled by 1/alpha, if not the alpha channel.

func GrayToAlpha

func GrayToAlpha(a *image.Gray) *image.Alpha

GrayToAlpha does a shallow copy (vs going through the ColorModel).

func GrayToSupport

func GrayToSupport(img *image.Gray) [][]bool

GrayToSupport converts a gray scale image to a support.

func Histogram

func Histogram(img *image.Gray) ([]int, int, int)

Histogram computes the histogram of the image and the first and last non-zero entry positions

func HitOrMiss

func HitOrMiss(img image.Image, support1, support2 [][]bool) *image.Gray

HitOrMiss keeps support1 and not support2 in the image. It requires that the intersection of the two supports be empty.

func LJReconstitute

func LJReconstitute(skels []*image.Gray, b [][]bool) *image.Gray

LJReconstitute turns a set of skeletons back into the opened version of the original image using the support.

func LJSkeleton

func LJSkeleton(img image.Image, b [][]bool, n int) []*image.Gray

LJSkeleton calculates the skeletons of the image using Lanuejoul's formula over n iterations with support b. Each skeleton is formed from the tophat of the image eroded by the support b dilated by itself n times. The last skeleton is the union of the previous skeletons. See https://en.wikipedia.org/wiki/Morphological_skeleton

func MaxOp

func MaxOp(values [][]uint8, support [][]bool) uint8

MaxOp finds the highest value in values that has the support set.

func MedOp

func MedOp(values [][]uint8, support [][]bool) uint8

MedOp finds the midway value of all the values, sorted, that have the support set.

func MinOp

func MinOp(values [][]uint8, support [][]bool) uint8

MinOp finds the lowest value in values that has the support set.

func Morphological

func Morphological(img image.Image, op func([][]uint8, [][]bool) uint8, support [][]bool, def uint8) *image.Gray

Morphological runs op over the image img using support and supplying def when a location falls outside of the image boundary. The support dimensions must be odd (not checked for).

func NLExpansionLut

func NLExpansionLut(n, start, end int, f util.NonLinear) []uint8

NLExpansionLut generates a lut [start,end), normalized and mapped through f. For example NLExpansionLut(256, 0, 256, &NLSin{}) will generate a Sin ramp.

func NewAlpha

func NewAlpha(w, h int, col color.Color) *image.Alpha

NewAlpha is a wrapper for image.Alpha which returns a new image of the desired size filled with color.

func NewAlphaVal

func NewAlphaVal(w, h int, a uint8) *image.Alpha

NewAlphaVal is a wrapper for image.Alpha which returns a new image of the desired size filled with color.

func NewGray

func NewGray(w, h int, col color.Color) *image.Gray

NewGray is a wrapper for image.Gray which returns a new image of the desired size filled with color.

func NewGray16

func NewGray16(w, h int, col color.Color) *image.Gray16

NewGray16 is a wrapper for image.Gray16 which returns a new image of the desired size filled with color.

func NewGray16Val

func NewGray16Val(w, h int, g uint16) *image.Gray16

NewGray16Val is a wrapper for image.Gray which returns a new image of the desired size filled with color.

func NewGrayVal

func NewGrayVal(w, h int, g uint8) *image.Gray

NewGrayVal is a wrapper for image.Gray which returns a new image of the desired size filled with color.

func NewRGBA

func NewRGBA(w, h int, col color.Color) *image.RGBA

NewRGBA is a wrapper for image.RGBA which returns a new image of the desired size filled with color.

func NewRGBAVal

func NewRGBAVal(w, h int, r, g, b, a uint8) *image.RGBA

NewRGBAVal is a wrapper for image.RGBA which returns a new image of the desired size filled with color.

func Not

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

Not returns 1 - img.

func Open

func Open(img image.Image, support [][]bool) *image.Gray

Open applies a dilation to a prior erosion.

func Or

func Or(img1, img2 image.Image, offs image.Point) *image.Gray

Or returns the result of ORing img1 with img2, offset by offs (union). The images are converted to image.Gray if not already so. For a pair of pixels, p1 & p2 returns max(p1, p2).

func PremulLut

func PremulLut(lut []uint8) [][]uint8

PremulLut creates a slice of luts from lut for every possible value of alpha

func ReadImage

func ReadImage(name string) (image.Image, error)

ReadImage is a utility function to read an image from a file.

func RemapGray

func RemapGray(img *image.Gray, lut []uint8) *image.Gray

RemapGray remaps a color map with a look up table. The lookup table must be 256 long.

func RemapGray2RGBA

func RemapGray2RGBA(img image.Image, lut []color.Color) *image.RGBA

RemapGray2RGBA remaps a grayscale image to an RGBA one using a look up table. The lookup table must be 256 long.

func RemapRGB

func RemapRGB(img *image.RGBA, lutR, lutG, lutB []uint8) *image.RGBA

RemapRGB remaps all the color maps with R, G, B look up tables. The lookup tables must all be 256 long. The maps are applied after alpha pre-multiplication.

func RemapRGBSingle

func RemapRGBSingle(img *image.RGBA, lut []uint8) *image.RGBA

RemapRGBSingle remaps all the color maps with a single look up table. The lookup table must be 256 long. The maps are applied after alpha pre-multiplication.

func ReplaceChannel

func ReplaceChannel(img *image.RGBA, ch int, rep *image.Gray) *image.RGBA

ReplaceChannel in an image with the one supplied. The supplied image is scaled by alpha, if one of R, G or B. If the alpha channel is replaced then RGB are first scaled by 1/alpha and then by alpha'

func SaveImage

func SaveImage(img image.Image, name string) error

SaveImage is a utility function to save an image as a .png.

func Skeleton

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

Skeleton repeatedly thins the image until it's no longer changing. This operation can take a while to converge.

func Sub

func Sub(img1, img2 image.Image, offs image.Point) *image.Gray

Sub returns the result of subtracting img2 from img1, offset by offs. The images are converted to image.Gray if not already so. For a pair of pixels, p1 & p2 returns max(0, p1-p2).

func SupportToGray

func SupportToGray(suppt [][]bool) *image.Gray

SupportToGray converts a support to a gray scale image.

func SwitchChannels

func SwitchChannels(img *image.RGBA, ch1, ch2 int) *image.RGBA

SwitchChannels in an image (not alpha)

func Thin

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

Thin thins the image by repeatedly subtracting HitOrMiss with the selected support pairs.

func ThinStep

func ThinStep(img image.Image, support1, support2 [][]bool) *image.Gray

ThinStep thins the image by subtracting HitOrMiss with a support pair.

func TopHat

func TopHat(img image.Image, support [][]bool) *image.Gray

TopHat is the subtraction of an open from the original.

func Variance

func Variance(img1, img2 *image.Gray) (float64, int)

Variance provides a normalized metric on how different two images are. It's not a strict statistical variance but the sum of the differences over the image size and number of differences.

func Xor

func Xor(img1, img2 image.Image, offs image.Point) *image.Gray

Xor returns of XORing img1 with img2, offset by offs (union - intersection). The images are converted to image.Gray if not already so. For a pair of pixels, p1 ^ p2 returns min(max(p1, p2), 1-min(p1, p2)).

Types

type Aff5

type Aff5 [20]float64

Aff5 is a 5x5 affine transformation matrix in row major order, where the bottom row is implicitly [0 0 0 0 1].

m[5*r+c] is the element in the r'th row and c'th column.

func Grayscale

func Grayscale(t float64) *Aff5

Grayscale returns a transform that will create a gray tinted image.

func HueRotate

func HueRotate(th float64) *Aff5

HueRotate returns a transform that will rotate the hue selection by th radians.

func LuminanceToAlpha

func LuminanceToAlpha() *Aff5

LuminanceToAlpha returns a transform that will write just the luminance to the alpha channel.

func NewAff5

func NewAff5() *Aff5

NewAff5 creates the identity transform.

func Saturate

func Saturate(s float64) *Aff5

Saturate returns a transform that will modify the saturation of an image by s (0, 1)

func Sepia

func Sepia(t float64) *Aff5

Sepia returns a transform that will create a sepia tinted image.

func (*Aff5) Apply

func (a *Aff5) Apply(pts ...[]float64) [][]float64

Apply applies the transform to the set of supplied points.

func (*Aff5) Identity

func (a *Aff5) Identity() bool

Identity returns true if the transform is the identity.

func (*Aff5) Transform

func (a *Aff5) Transform(tup []uint8) []uint8

Transform transforms an r, g, b, a tuple into r', g', b', a' according to the values in a.

type Bit

type Bit struct {
	Bits   datastruct.Bits
	SetC   color.RGBA // color returned when bit is set
	ClearC color.RGBA // color returned when bit is clear
	Stride int
	Thresh uint32 // threshold above which a bit is set in the RGB conversion
	Rect   image.Rectangle
}

Bit image uses a bit array to store data. The default colors assigned to bit values are color.White for set and color.Black for clear. These can be modified.

func NewBit

func NewBit(r image.Rectangle) *Bit

NewTile creates a new image with the supplied bounds.

func (*Bit) At

func (b *Bit) At(x, y int) color.Color

At implements the At function in the Image interface.

func (*Bit) Bounds

func (b *Bit) Bounds() image.Rectangle

Bounds implements the Bounds function in the Image interface.

func (*Bit) ColorModel

func (b *Bit) ColorModel() color.Model

ColorModel implements the ColorModel function in the Image interface.

func (*Bit) Set

func (b *Bit) Set(x, y int, c color.Color)

Set implements the Set function in the draw.Image interface.

type Colorizer

type Colorizer struct {
	Img  image.Image
	Rect image.Rectangle
	Lut  []color.RGBA
	G16  bool
}

Colorizer uses the gray or red channel of an image to create an image tinted with a lerp'd gradient between two or more colors.

func NewColorizer

func NewColorizer(img image.Image, c1, c2 color.Color, stops []int, colors []color.Color, post bool) *Colorizer

NewColorizer creates a new Colorizer and creates the internal lut. c1 and c2 are the colors at the start and end of the colorizer. The stops (in range [1,254] and colors values determine any intermediate points and can be nil. The post flag turns off the lerping between colors and yields a posterized image.

func (*Colorizer) At

func (c *Colorizer) At(x, y int) color.Color

At implements the At function in the Image interface.

func (*Colorizer) Bounds

func (c *Colorizer) Bounds() image.Rectangle

Bounds implements the Bounds function in the Image interface.

func (*Colorizer) ColorModel

func (c *Colorizer) ColorModel() color.Model

ColorModel implements the ColorModel function in the Image interface.

type Patch

type Patch struct {
	Colors [][]color.RGBA
	Width  int
	Height int
	OffsX  int
	OffsY  int
}

Patch is an infinite image covered with a patch of colors.

func NewPatch

func NewPatch(colors [][]color.Color) (*Patch, error)

NewPatch creates a new image with the supplied patch.

func (*Patch) At

func (p *Patch) At(x, y int) color.Color

At implements the At function in the Image interface.

func (*Patch) Bounds

func (p *Patch) Bounds() image.Rectangle

Bounds implements the Bounds function in the Image interface.

func (*Patch) ColorModel

func (p *Patch) ColorModel() color.Model

ColorModel implements the ColorModel function in the Image interface.

type Tile

type Tile struct {
	TileImg *image.RGBA
	Width   int
	Height  int
	OffsX   int
	OffsY   int
	StagX   int
	StagY   int
}

Tile is an infinite image covered with a tile.

func NewTile

func NewTile(img image.Image) *Tile

NewTile creates a new image with the supplied image tile.

func (*Tile) At

func (t *Tile) At(x, y int) color.Color

At implements the At function in the Image interface.

func (*Tile) Bounds

func (t *Tile) Bounds() image.Rectangle

Bounds implements the Bounds function in the Image interface.

func (*Tile) ColorModel

func (t *Tile) ColorModel() color.Model

ColorModel implements the ColorModel function in the Image interface.

Directories

Path Synopsis
Package texture contains functions that populate images with texture.
Package texture contains functions that populate images with texture.

Jump to

Keyboard shortcuts

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