effects

package
v0.0.0-...-723f749 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CTOpts

type CTOpts struct {
	// BlurKernelSize is the gaussian blur kernel size. You might need to blur
	// the original input image to reduce the amount of noise you get in the edge
	// detection phase. Set to 0 to skip blur, otherwise the number must be an
	// odd number, the bigger the number the more blur
	BlurKernelSize int

	// EdgeThreshold is a number between 0 and 255 that specifies a cutoff point to
	// determine if an intensity change is an edge. Make smaller to include more details
	// as edges
	EdgeThreshold int

	// OilFilterSize specifies how bold the simulated strokes will be when turning the
	// style towards a painting, something around 5,10,15 should work well
	OilFilterSize int

	// OilLevels is the number of levels that the oil painting style will bucket colors in
	// to. Larger number to get more detail.
	OilLevels int

	// DebugPath is not empty is assumed to be a path where intermediate debug files can
	// be written to, such as the gaussian blured image and the sobel edge detection. This
	// can be useful for tweaking parameters
	DebugPath string
}

CTOpts options to pass to the Cartoon effect

type Effect

type Effect interface {
	// Apply applies the effect to the input image and returns an output image
	Apply(img *Image, numRoutines int) (*Image, error)
}

Effect interface for any effect type

func NewBrightness

func NewBrightness(offset int) Effect

NewBrightness returns an effect that can lighten of darken an image. To lighten an image set offset as a positive value between 0 and 255, to darken, set it as a negative number

func NewCartoon

func NewCartoon(opts CTOpts) Effect

NewCartoon returns an effect that renders images as if they are drawn like a cartoon. It works by rendering the input image using the OilPainting effect, then drawing lines ontop of the image based on the Sobel edge detection method. You will probably have to play with the opts values to get a good result. Some starting values are: BlurKernelSize: 21 EdgeThreshold: 40 OilFilterSize: 15 OilLevels: 15

func NewGaussian

func NewGaussian(kernelSize int, sigma float64) Effect

NewGaussian is an effect that applies a gaussian blur to the image

func NewGrayscale

func NewGrayscale(algo GSAlgo) Effect

NewGrayscale renders the input image as a grayscale image. numRoutines specifies how many goroutines should be used to process the image in parallel, use 0 to let the library decide

func NewOilPainting

func NewOilPainting(filterSize, levels int) Effect

NewOilPainting renders the input image as if it was painted like an oil painting. numRoutines specifies how many goroutines should be used to process the image in parallel, use 0 to let the library decide. filterSize specifies how bold the image should look, larger numbers equate to larger strokes, levels specifies how many buckets colors will be grouped in to, start with values 5,30 to see how that works.

func NewPencil

func NewPencil(blurFactor int) Effect

NewPencil renders the input image as if it was drawn in pencil. It is simply an inverted Sobel image. You can specify the blurFactor, a value that must be odd, to blur the input image to get rid of the noise. This is the gaussian kernel size, larger numbers blur more but can significantly increase processing time.

func NewPixelate

func NewPixelate(blockSize int) Effect

NewPixelate pixelates the imput image

func NewSobel

func NewSobel(threshold int, invert bool) Effect

NewSobel the input image should be a grayscale image, the output will be a version of the input image with the Sobel edge detector applied to it. A value of -1 for threshold will return an image whos rgb values are the sobel intensity values, if 0 <= threshold <= 255 then the rgb values will be 255 if the intensity is >= threshold and 0 if the intensity is < threshold

type GSAlgo

type GSAlgo int

GSAlgo the type of algorithm to use when converting an image to it's grayscale equivalent

const (
	// GSLIGHTNESS is the average of the min and max r,g,b value
	GSLIGHTNESS GSAlgo = iota

	// GSAVERAGE is the average of the r,g,b values of each pixel
	GSAVERAGE

	// GSLUMINOSITY used a weighting for r,g,b based on how the human eye perceives colors
	GSLUMINOSITY
)

type Image

type Image struct {
	Bounds Rect
	Width  int
	Height int
	// contains filtered or unexported fields
}

Image wrapper around internal pixels

func LoadImage

func LoadImage(path string) (*Image, error)

LoadImage loads the specified image from disk. Supported file types are png and jpg

func LoadObject

func LoadObject(img image.Image) (*Image, error)

LoadObject loads image interface

func (*Image) Raw

func (i *Image) Raw(clip bool) image.Image

Applay same as save but returns image interface

func (*Image) Save

func (i *Image) Save(outPath string, opts SaveOpts) error

Save saves the image as the file type defined by the extension in the path e.g. ,jpg or .png

type Pipeline

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

Pipeline allows multiple effects to be composed together easily

func (*Pipeline) Add

func (p *Pipeline) Add(e Effect, callback func(*Image))

Add adds an effect to the pipeline

func (*Pipeline) Run

func (p *Pipeline) Run(img *Image, numRoutines int) (*Image, error)

Run executes all of the effects in the order they were passed to the Add function on the input image and returns the results.

type Rect

type Rect struct {
	X      int
	Y      int
	Width  int
	Height int
}

Rect used for image bounds

func (Rect) Intersect

func (r Rect) Intersect(r2 Rect) Rect

Intersect returns the intersection between two rectangles

func (Rect) IsEmpty

func (r Rect) IsEmpty() bool

IsEmpty returns true if this is an empty rectangle

func (Rect) String

func (r Rect) String() string

String returns a debug string

func (Rect) ToImageRect

func (r Rect) ToImageRect() image.Rectangle

ToImageRect returns an image.Rectangle instance initialized from this Rect

type SaveOpts

type SaveOpts struct {
	// JPEGCompression a value between 1 and 100, if 0 specified, defaults to 95.
	// Higher values are better quality. Only applicable if the file ends with a
	// .jpg or .jpeg extension
	JPEGCompression int

	// ClipToBounds if true only the image inside the region specified by the bounds is
	// saved. Sometimes aftere running an image effect you may have outer bands that are
	// dead pixels, setting this to true crops them out.
	ClipToBounds bool
}

SaveOpts specifies some save parameters that can be specified when saving an image

Jump to

Keyboard shortcuts

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