imgutils

package
v0.0.0-...-18831ba Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxPixelValue = (1 << 8) - 1
	MinPixelValue = 0
)

Variables

This section is empty.

Functions

func CropBox

func CropBox(img image.Image, colorConverter ColorConverter, opts BoxOptions) image.Rectangle

CropBox calculates a bounding box for the given image by analyzing transparent pixels or minimum color values.

func CropImage

func CropImage(img image.Image, rect image.Rectangle) image.Image

func DominantColorInRegion

func DominantColorInRegion(
	img image.Image,
	region image.Rectangle,
	optTakeAvg ...bool,
) color.Color

DominantColorInRegion computes the average color in a region and returns the nearest color from the palette of that region.

func FillImageRegionWithColor

func FillImageRegionWithColor(img draw.Image, region image.Rectangle, col color.Color)

func IsImageEqual

func IsImageEqual(a, b image.Image) bool

IsImageEqual returns true if two images a and b are equal.

func Iterator

func Iterator(input image.Image) iter.Seq2[int, int]

func MarginBox

func MarginBox(bounds image.Rectangle, percentage float64) image.Rectangle

func NewDrawFromImgColorModel

func NewDrawFromImgColorModel(colorModel color.Model, bounds image.Rectangle) draw.Image

func NormalizePixel

func NormalizePixel[T Number](value T) uint8

func RegionIterator

func RegionIterator(region image.Rectangle) iter.Seq2[int, int]

func RotateImage

func RotateImage(img image.Image, degrees RotationDegrees) image.Image

RotateImage rotates the given image 90 degrees clockwise.

Types

type BoxOptions

type BoxOptions uint8
const (
	BoxEliminateTransparent BoxOptions = 1 << iota
	BoxEliminateMinimumColor
)

func (BoxOptions) Has

func (bo BoxOptions) Has(opt BoxOptions) bool

type ChannelHistogram

type ChannelHistogram [MaxPixelValue + 1]uint32

func ApplyCutoff

func ApplyCutoff(histogram ChannelHistogram, cutoffLow, cutoffHigh float64) ChannelHistogram

ApplyCutoff modifies the histogram by cutting off a percentage of pixels at both low and high ends.

type ColorConverter

type ColorConverter interface {
	Convert(c color.Color) color.Color
}

type DrawImageFactory

type DrawImageFactory interface {
	CreateDrawImage(colorModel color.Model, bounds image.Rectangle) draw.Image
}

func NewImageFactory

func NewImageFactory(palette color.Palette) DrawImageFactory

type ImageHistogram

type ImageHistogram struct {
	// contains filtered or unexported fields
}

func CalculateHistogram

func CalculateHistogram(img image.Image) ImageHistogram

CalculateHistogram calculates the histogram for each color channel in an image.

func (*ImageHistogram) Channel

func (histogram *ImageHistogram) Channel(index uint8) ChannelHistogram

func (ImageHistogram) HiloHistogram

func (histogram ImageHistogram) HiloHistogram() (minVal [3]uint8, maxVal [3]uint8)

func (*ImageHistogram) Set

func (histogram *ImageHistogram) Set(index uint8, channel ChannelHistogram) bool

type ImageOrientation

type ImageOrientation uint8
const (
	OrientationPortrait ImageOrientation = iota
	OrientationLandscape
)

func NewOrientation

func NewOrientation(imgBounds image.Rectangle) ImageOrientation

type ImagePaletteDrawer

type ImagePaletteDrawer struct {
	draw.Image
	// contains filtered or unexported fields
}

func (ImagePaletteDrawer) Set

func (i ImagePaletteDrawer) Set(x, y int, c color.Color)

type Margins

type Margins[T comparable] struct {
	Top, Bottom, Left, Right T
}

func HalfSplit

func HalfSplit(
	inputBonds image.Rectangle, imgOrientation ImageOrientation,
) (halfBounds Margins[image.Rectangle])

func ImageMarginDominantColor

func ImageMarginDominantColor(
	inputImg image.Image, xMargin, yMargin uint32, percentage uint8,
) (dominantColors Margins[color.Color])

func (*Margins[T]) UpdateNonEmpty

func (c *Margins[T]) UpdateNonEmpty(other Margins[T])

type Number

type Number interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |
		~float32 | ~float64
}

type RotationDegrees

type RotationDegrees uint8
const (
	Rotation90Degrees RotationDegrees = iota
	Rotation180Degrees
	Rotation270Degrees
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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