engine

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BlockSize is the size of a block when splitting the image plane.
	BlockSize = 128
	// Overlap is the size of the pixels that the image overlaps.
	Overlap = 14
)

Variables

This section is empty.

Functions

func Blocking

func Blocking(initialPlanes [3]ImagePlane) ([][]ImagePlane, int, int)

Blocking divides a given image into blocks.

Types

type ChannelImage

type ChannelImage struct {
	Width  int
	Height int
	Buffer []uint8
}

ChannelImage represents a discrete image.

func ChannelCompose

func ChannelCompose(r, g, b, a ChannelImage) ChannelImage

ChannelCompose composes R, G, B and Alpha channels to the one channel image.

func ChannelDecompose

func ChannelDecompose(img ChannelImage) (r, g, b, a ChannelImage)

ChannelDecompose decomposes a channel image to R, G, B and Alpha channels.

func NewChannelImage

func NewChannelImage(img image.Image) (ChannelImage, bool, error)

NewChannelImage returns a channel image corresponding to the specified image.

func NewChannelImageWidthHeight

func NewChannelImageWidthHeight(width, height int) ChannelImage

NewChannelImageWidthHeight returns a channel image of specific width and height.

func NewDenormalizedChannelImage

func NewDenormalizedChannelImage(p ImagePlane) ChannelImage

NewDenormalizedChannelImage returns a channel image corresponding to the image plane.

func (ChannelImage) Extrapolation

func (c ChannelImage) Extrapolation(px int) ChannelImage

Extrapolation calculates an extrapolation algorithm.

func (ChannelImage) ImagePaletted added in v1.2.0

func (c ChannelImage) ImagePaletted(p color.Palette) *image.Paletted

ImagePaletted converts the chanel image to an image.Paletted and return it.

func (ChannelImage) ImageRGBA

func (c ChannelImage) ImageRGBA() image.RGBA

ImageRGBA converts the channel image to an image.RGBA and return it.

func (ChannelImage) Resize

func (c ChannelImage) Resize(scale float64) ChannelImage

Resize returns a resized image.

type ImagePlane

type ImagePlane struct {
	Width  int
	Height int
	Buffer []float32
}

ImagePlane represents an image in which each pixel has a continuous value.

func Deblocking

func Deblocking(outputBlocks [][]ImagePlane, blocksW, blocksH int) [3]ImagePlane

Deblocking combines blocks for each of the R, G, and B channels.

func NewImagePlaneWidthHeight

func NewImagePlaneWidthHeight(width, height int) ImagePlane

NewImagePlaneWidthHeight returns an image plane of specific width and height.

func NewNormalizedImagePlane

func NewNormalizedImagePlane(img ChannelImage) (ImagePlane, error)

NewNormalizedImagePlane create a normalized image plane from a channel image.

func (ImagePlane) Index

func (p ImagePlane) Index(width, height int) int

Index returns the buffer position corresponding to the specified width and height of the image.

func (ImagePlane) SegmentAt

func (p ImagePlane) SegmentAt(x, y int) (a0, a1, a2, b0, b1, b2, c0, c1, c2 float32)

SegmentAt returns the 3x3 pixels at the specified position. [a0][a1][a2] [b0][b1][b2] [c0][c1][c2] where (x, y) is b1.

func (*ImagePlane) SetAt

func (p *ImagePlane) SetAt(width, height int, v float32)

SetAt sets the value to the buffer corresponding to the specified width and height of the image.

func (ImagePlane) Value

func (p ImagePlane) Value(width, height int) float32

Value returns the value corresponding to the specified width and height of the image.

type Mode

type Mode int

Mode is the type of trained models.

const (
	// Anime model type.
	Anime Mode = iota + 1
	// Photo model type.
	Photo
)

func (Mode) String

func (t Mode) String() string

String returns string representation of a mode.

type Model

type Model []Param

Model represents a trained model.

func LoadModel

func LoadModel(r io.Reader) (Model, error)

LoadModel loads a trained model from the io.Reader.

func LoadModelAssets

func LoadModelAssets(path string) (Model, error)

LoadModelAssets loads a trained model from assets.

func LoadModelFile

func LoadModelFile(path string) (Model, error)

LoadModelFile loads a trained model from the specified file.

type ModelSet

type ModelSet struct {
	Scale2xModel Model
	NoiseModel   Model
}

ModelSet is a set of trained models.

func NewAssetModelSet

func NewAssetModelSet(t Mode, noiseLevel int) (*ModelSet, error)

NewAssetModelSet returns a set of trained models loaded from assets.

type Option

type Option func(w *Waifu2x) error

Option represents an option of waifu2x.

func LogOutput added in v1.1.0

func LogOutput(w io.Writer) Option

LogOutput sets the log output destination.

func Parallel

func Parallel(p int) Option

Parallel sets the option that specifies the limit number of concurrency.

func Verbose

func Verbose(v bool) Option

Verbose sets the verbose option.

type Param

type Param struct {
	Bias         []float32       `json:"bias"`         // バイアス
	KW           int             `json:"kW"`           // フィルタの幅
	KH           int             `json:"kH"`           // フィルタの高さ
	Weight       [][][][]float32 `json:"weight"`       // 重み
	NInputPlane  int             `json:"nInputPlane"`  // 入力平面数
	NOutputPlane int             `json:"nOutputPlane"` // 出力平面数
	WeightVec    []float32
}

Param represents a parameter of the model.

type Waifu2x

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

Waifu2x is the main structure for executing the waifu2x algorithm.

func NewWaifu2x

func NewWaifu2x(mode Mode, noise int, opts ...Option) (*Waifu2x, error)

NewWaifu2x creates a Waifu2x structure.

func (Waifu2x) ScaleUp

func (w Waifu2x) ScaleUp(ctx context.Context, img image.Image, scale float64) (ChannelImage, error)

ScaleUp scales up the image.

func (Waifu2x) ScaleUpGIF added in v1.2.0

func (w Waifu2x) ScaleUpGIF(ctx context.Context, img *gif.GIF, scale float64) (*gif.GIF, error)

ScaleUpGIF scales up the GIF image.

Jump to

Keyboard shortcuts

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