package image
import "github.com/jphsd/graphics2d/image"
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 ¶
- Variables
- func Alpha16ToGray16(a *image.Alpha16) *image.Gray16
- func Alpha16ToGray16Deep(a *image.Alpha16) *image.Gray16
- func AlphaAnd(img1, img2 *image.Alpha, offs image.Point) *image.Alpha
- func AlphaEqual(img1, img2 *image.Alpha, offs image.Point) bool
- func AlphaNot(img *image.Alpha) *image.Alpha
- func AlphaOr(img1, img2 *image.Alpha, offs image.Point) *image.Alpha
- func AlphaSub(img1, img2 *image.Alpha, offs image.Point) *image.Alpha
- func AlphaToGray(a *image.Alpha) *image.Gray
- func AlphaToGrayDeep(a *image.Alpha) *image.Gray
- func AlphaXor(img1, img2 *image.Alpha, offs image.Point) *image.Alpha
- func And(img1, img2 image.Image, offs image.Point) *image.Gray
- func AvgOp(values [][]uint8, support [][]bool) uint8
- func BotHat(img image.Image, support [][]bool) *image.Gray
- func CDF(hist []int) []float64
- func Close(img image.Image, support [][]bool) *image.Gray
- func ColorConvert(img *image.NRGBA, xfm *Aff5) *image.NRGBA
- func CombineChannels(chR, chG, chB, chA *image.Gray, scale bool) *image.RGBA
- func CopyAlpha(in *image.Alpha) *image.Alpha
- func CopyAlpha16(in *image.Alpha16) *image.Alpha16
- func CopyGray(in *image.Gray) *image.Gray
- func CopyGray16(in *image.Gray16) *image.Gray16
- func CopyRGBA(in *image.RGBA) *image.RGBA
- func CopyRGBA64(in *image.RGBA64) *image.RGBA64
- func CreateLutFromValues(values []float64) []uint8
- func Dilate(img image.Image, support [][]bool) *image.Gray
- func Displace(img draw.Image, r image.Rectangle, xchan image.Image, xoffs image.Point, xscale float64, ychan image.Image, yoffs image.Point, yscale float64)
- func Equal(img1, img2 image.Image, offs image.Point) bool
- func Erode(img image.Image, support [][]bool) *image.Gray
- func ExtractChannel(img *image.RGBA, ch int) *image.Gray
- func Gray16ToAlpha16(a *image.Gray16) *image.Alpha16
- func Gray16ToAlpha16Deep(g *image.Gray16) *image.Alpha16
- func GrayToAlpha(a *image.Gray) *image.Alpha
- func GrayToAlphaDeep(g *image.Gray) *image.Alpha
- func GrayToSupport(img *image.Gray) [][]bool
- func Histogram(img *image.Gray) ([]int, int, int)
- func HitOrMiss(img image.Image, support1, support2 [][]bool) *image.Gray
- func LJReconstitute(skels []*image.Gray, b [][]bool) *image.Gray
- func LJSkeleton(img image.Image, b [][]bool, n int) []*image.Gray
- func MaxOp(values [][]uint8, support [][]bool) uint8
- func MedOp(values [][]uint8, support [][]bool) uint8
- func MinOp(values [][]uint8, support [][]bool) uint8
- func Morphological(img image.Image, op func([][]uint8, [][]bool) uint8, support [][]bool, def uint8) *image.Gray
- func NLExpansionLut(n, start, end int, f util.NonLinear) []uint8
- func NewAlpha(w, h int, col color.Color) *image.Alpha
- func NewAlpha16(w, h int, col color.Color) *image.Alpha16
- func NewGray(w, h int, col color.Color) *image.Gray
- func NewGray16(w, h int, col color.Color) *image.Gray16
- func NewRGBA(w, h int, col color.Color) *image.RGBA
- func NewRGBA64(w, h int, col color.Color) *image.RGBA64
- func Not(img image.Image) *image.Gray
- func Open(img image.Image, support [][]bool) *image.Gray
- func Or(img1, img2 image.Image, offs image.Point) *image.Gray
- func PremulLut(lut []uint8) [][]uint8
- func ReadImage(name string) (image.Image, error)
- func RemapGray(img *image.Gray, lut []uint8) *image.Gray
- func RemapGray2RGBA(img image.Image, lut []color.Color) *image.RGBA
- func RemapRGB(img *image.RGBA, lutR, lutG, lutB []uint8) *image.RGBA
- func RemapRGBSingle(img *image.RGBA, lut []uint8) *image.RGBA
- func ReplaceChannel(img *image.RGBA, ch int, rep *image.Gray) *image.RGBA
- func SaveImage(img image.Image, name string) error
- func Skeleton(img image.Image) *image.Gray
- func Sub(img1, img2 image.Image, offs image.Point) *image.Gray
- func SupportToGray(suppt [][]bool) *image.Gray
- func SwitchChannels(img *image.RGBA, ch1, ch2 int) *image.RGBA
- func Thin(img image.Image) *image.Gray
- func ThinStep(img image.Image, support1, support2 [][]bool) *image.Gray
- func ToGray(img image.Image) *image.Gray
- func ToGray16(img image.Image) *image.Gray16
- func TopHat(img image.Image, support [][]bool) *image.Gray
- func Variance(img1, img2 *image.Gray) (float64, int)
- func Xor(img1, img2 image.Image, offs image.Point) *image.Gray
- type Aff5
- func Grayscale(t float64) *Aff5
- func HueRotate(th float64) *Aff5
- func LuminanceToAlpha() *Aff5
- func NewAff5() *Aff5
- func Saturate(s float64) *Aff5
- func Sepia(t float64) *Aff5
- func (a *Aff5) Apply(pts ...[]float64) [][]float64
- func (a *Aff5) Identity() bool
- func (a *Aff5) Transform(tup []uint8) []uint8
- type Bit
- func NewBit(r image.Rectangle) *Bit
- func (b *Bit) At(x, y int) color.Color
- func (b *Bit) Bounds() image.Rectangle
- func (b *Bit) ColorModel() color.Model
- func (b *Bit) Set(x, y int, c color.Color)
- type Colorizer
- func NewColorizer(img image.Image, c1, c2 color.Color, stops []int, colors []color.Color, post bool) *Colorizer
- func (c *Colorizer) At(x, y int) color.Color
- func (c *Colorizer) Bounds() image.Rectangle
- func (c *Colorizer) ColorModel() color.Model
- type Gray
- type Gray16
- type Image
- type NRGBA
- type NRGBA64
- type Patch
- func NewPatch(colors [][]color.Color) (*Patch, error)
- func (p *Patch) At(x, y int) color.Color
- func (p *Patch) Bounds() image.Rectangle
- func (p *Patch) ColorModel() color.Model
- type Point
- type RGBA
- type RGBA64
- type Rectangle
- type Tile
Variables ¶
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 Alpha16ToGray16 ¶
Alpha16ToGray16 does a shallow copy (vs going through the ColorModel).
func Alpha16ToGray16Deep ¶
Alpha16ToGray16Deep does a deep copy (vs going through the ColorModel).
func AlphaAnd ¶
AlphaAnd returns img1 & img2 (intersection). For a pair of pixels, p1 & p2 returns min(p1, p2).
func AlphaEqual ¶
AlphaEqual returns true if two images are the same.
func AlphaNot ¶
AlphaNot returns 1 - img.
func AlphaOr ¶
AlphaOr returns img1 | img2 (union). For a pair of pixels, p1 | p2 returns max(p1, p2).
func AlphaSub ¶
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 ¶
AlphaToGray does a shallow copy (vs going through the ColorModel).
func AlphaToGrayDeep ¶
AlphaToGrayDeep does a deep copy (vs going through the ColorModel).
func AlphaXor ¶
AlphaXor returns img1 ^ img2 (union - intersection). For a pair of pixels, p1 ^ p2 returns min(max(p1, p2), 1-min(p1, p2)).
func And ¶
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 ¶
AvgOp finds the average value (rounded down) of all the values that have the support set.
func BotHat ¶
BotHat is the subtraction of the original from a close.
func CDF ¶
CDF computes the normalized cummulative distribution function of the histogram.
func Close ¶
Close applies an erosion to a prior dilation.
func ColorConvert ¶
ColorConvert runs NRGBA through the supplied affine transform.
func CombineChannels ¶
CombineChannels combines mono-channel images into a single image. The R, G, B channels will be scaled by alpha if scale is true.
func CopyAlpha ¶
CopyAlpha clones an Alpha image.
func CopyAlpha16 ¶
CopyAlpha16 clones an Alpha16 image.
func CopyGray ¶
CopyGray clones a Gray image.
func CopyGray16 ¶
CopyGray16 clones a Gray16 image.
func CopyRGBA ¶
CopyRGBA clones an RGBA image.
func CopyRGBA64 ¶
CopyRGBA64 clones an RGBA64 image.
func CreateLutFromValues ¶
CreateLutFromValues maps a series of values in [0,1] to [0,255] Note - no checking on values range
func Dilate ¶
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 ¶
Equal returns true if img1 within img2 at offset offs, matches.
func Erode ¶
Erode replaces each pixel with the min of the pixels in its support.
func ExtractChannel ¶
ExtractChannel returns an image with just the selected channel. The returned image is scaled by 1/alpha, if not the alpha channel.
func Gray16ToAlpha16 ¶
Gray16ToAlpha16 does a shallow copy (vs going through the ColorModel).
func Gray16ToAlpha16Deep ¶
Gray16ToAlpha16Deep does a deep copy (vs going through the ColorModel).
func GrayToAlpha ¶
GrayToAlpha does a shallow copy (vs going through the ColorModel).
func GrayToAlphaDeep ¶
GrayToAlphaDeep does a deep copy (vs going through the ColorModel).
func GrayToSupport ¶
GrayToSupport converts a gray scale image to a support.
func Histogram ¶
Histogram computes the histogram of the image and the first and last non-zero entry positions
func HitOrMiss ¶
HitOrMiss keeps support1 and not support2 in the image. It requires that the intersection of the two supports be empty.
func LJReconstitute ¶
LJReconstitute turns a set of skeletons back into the opened version of the original image using the support.
func LJSkeleton ¶
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 ¶
MaxOp finds the highest value in values that has the support set.
func MedOp ¶
MedOp finds the midway value of all the values, sorted, that have the support set.
func MinOp ¶
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 ¶
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 ¶
NewAlpha is a wrapper for image.Alpha which returns a new image of the desired size filled with color.
func NewAlpha16 ¶
NewAlpha16 is a wrapper for image.Alpha16 which returns a new image of the desired size filled with color.
func NewGray ¶
NewGray is a wrapper for image.Gray which returns a new image of the desired size filled with color.
func NewGray16 ¶
NewGray16 is a wrapper for image.Gray16 which returns a new image of the desired size filled with color.
func NewRGBA ¶
NewRGBA is a wrapper for image.RGBA which returns a new image of the desired size filled with color.
func NewRGBA64 ¶
NewRGBA64 is a wrapper for image.RGBA64 which returns a new image of the desired size filled with color.
func Not ¶
Not returns 1 - img.
func Open ¶
Open applies a dilation to a prior erosion.
func Or ¶
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 ¶
PremulLut creates a slice of luts from lut for every possible value of alpha
func ReadImage ¶
ReadImage is a utility function to read an image from a file.
func RemapGray ¶
RemapGray remaps a color map with a look up table. The lookup table must be 256 long.
func RemapGray2RGBA ¶
RemapGray2RGBA remaps a grayscale image to an RGBA one using a look up table. The lookup table must be 256 long.
func RemapRGB ¶
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 ¶
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 ¶
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 ¶
SaveImage is a utility function to save an image as a .png.
func Skeleton ¶
Skeleton repeatedly thins the image until it's no longer changing. This operation can take a while to converge.
func Sub ¶
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 ¶
SupportToGray converts a support to a gray scale image.
func SwitchChannels ¶
SwitchChannels in an image (not alpha)
func Thin ¶
Thin thins the image by repeatedly subtracting HitOrMiss with the selected support pairs.
func ThinStep ¶
ThinStep thins the image by subtracting HitOrMiss with a support pair.
func ToGray ¶
ToGray creates a grayscale copy of img
func ToGray16 ¶
ToGray16 creates a grayscale copy of img
func TopHat ¶
TopHat is the subtraction of an open from the original.
func Variance ¶
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 ¶
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 ¶
Grayscale returns a transform that will create a gray tinted image.
func HueRotate ¶
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 ¶
Saturate returns a transform that will modify the saturation of an image by s (0, 1)
func Sepia ¶
Sepia returns a transform that will create a sepia tinted image.
func (*Aff5) Apply ¶
Apply applies the transform to the set of supplied points.
func (*Aff5) Identity ¶
Identity returns true if the transform is the identity.
func (*Aff5) Transform ¶
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 ¶
NewTile creates a new image with the supplied bounds.
func (*Bit) At ¶
At implements the At function in the Image interface.
func (*Bit) Bounds ¶
Bounds implements the Bounds function in the Image interface.
func (*Bit) ColorModel ¶
ColorModel implements the ColorModel function in the Image interface.
func (*Bit) Set ¶
Set implements the Set function in the draw.Image interface.
type Colorizer ¶
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 ¶
At implements the At function in the Image interface.
func (*Colorizer) Bounds ¶
Bounds implements the Bounds function in the Image interface.
func (*Colorizer) ColorModel ¶
ColorModel implements the ColorModel function in the Image interface.
type Gray ¶
type Gray16 ¶
type Image ¶
type NRGBA ¶
type NRGBA64 ¶
type Patch ¶
Patch is an infinite image covered with a patch of colors.
func NewPatch ¶
NewPatch creates a new image with the supplied patch.
func (*Patch) At ¶
At implements the At function in the Image interface.
func (*Patch) Bounds ¶
Bounds implements the Bounds function in the Image interface.
func (*Patch) ColorModel ¶
ColorModel implements the ColorModel function in the Image interface.
type Point ¶
type RGBA ¶
type RGBA64 ¶
type Rectangle ¶
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 ¶
NewTile creates a new image with the supplied image tile.
func (*Tile) At ¶
At implements the At function in the Image interface.
func (*Tile) Bounds ¶
Bounds implements the Bounds function in the Image interface.
func (*Tile) ColorModel ¶
ColorModel implements the ColorModel function in the Image interface.
Source Files ¶
affine.go aliases.go bit.go channel.go colmat.go color.go diff.go displace.go doc.go hist.go lantuejoul.go logical.go lut.go morphological.go patch.go remap.go support.go tile.go util.go
Directories ¶
Path | Synopsis |
---|---|
image/texture | Package texture contains functions that populate images with texture. |
- Version
- v0.0.0-20250122000530-812f7f8c78f2 (latest)
- Published
- Jan 22, 2025
- Platform
- linux/amd64
- Imports
- 16 packages
- Last checked
- 3 weeks ago –
Tools for package owners.