img

package
v0.0.0-...-c5f678a Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2019 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package img contains routines for manipulating sets of images.

Index

Constants

View Source
const (
	ConvDefault = iota
	ConvAccel
	ConvBoxBlur
)

Variables

View Source
var (
	RGBModel  = color.ModelFunc(rgbModel)
	GrayModel = color.ModelFunc(grayModel)
)
View Source
var (
	GrayTrans = Scale | Rotate | Elastic
	RGBTrans  = HorizFlip | Pan
)
View Source
var (
	MaxScale     = 0.15
	MaxRotate    = 15.0
	ElasticScale = 0.5
	KernelSize   = 9
	KernelSigma  = 4.0
	PanPixels    = 4
)
View Source
var ErrDecodeImage = errors.New("error decoding image")

Functions

func GetStats

func GetStats(imgList ...[]*Image) (mean, std []float32)

Calculate mean and stddev from set of images

Types

type Color

type Color []float32

color is stored as a float for each channel with values in range 0-1

func (Color) RGBA

func (c Color) RGBA() (r, g, b, a uint32)

type ConvMode

type ConvMode int

type Convolution

type Convolution interface {
	Apply(in, out []float32)
}

Convolution to apply kernel to image

func NewConv

func NewConv(kernel []float32, ksize, width, height int) Convolution

Convolution implemented in go assuming 1d seperable kernel

func NewConvBox

func NewConvBox(sigma float64, width, height int) Convolution

Gaussian convolution using box blur

func NewConvMkl

func NewConvMkl(kernel []float32, ksize, width, height int) Convolution

Accelerated convolution using Intel MKL libraries

type Data

type Data struct {
	DataHead
	Images []*Image
}

Image data set which implements the nnet.Data interface

func NewData

func NewData(classes []string, labels []int32, images []*Image) *Data

Create a new image set

func NewDataLike

func NewDataLike(d *Data) *Data

func (*Data) ClassSize

func (d *Data) ClassSize() int

func (*Data) Classes

func (d *Data) Classes() []string

Classes functions number of differerent label values

func (*Data) Decode

func (d *Data) Decode(r io.Reader) error

Decode data from binary file

func (*Data) Encode

func (d *Data) Encode(w io.Writer) error

Encode data to binary file

func (*Data) Image

func (d *Data) Image(ix int, channel string) *Image

Image returns given image number, if channel is set then just show this colour channel

func (*Data) Input

func (d *Data) Input(index []int, buf []float32, t *Transformer)

Input returns scaled input data in buf array

func (*Data) Label

func (d *Data) Label(index []int, label []int32)

Label returns classification for given images

func (*Data) Len

func (d *Data) Len() int

Len function returns number of images

func (*Data) Shape

func (d *Data) Shape() []int

Shape returns height, width, channels

func (*Data) Slice

func (d *Data) Slice(start, end int) *Data

Slice returns images from start to end

type DataHead

type DataHead struct {
	Epochs int
	Class  []string
	Dims   []int
	Labels []int32
	Mean   []float32
	StdDev []float32
}

type Image

type Image struct {
	Pix      []float32
	Height   int
	Width    int
	Channels int
}

Image type stores the image data as float32 values in column major order with r, g and b color planes stored separately.

func Highlight

func Highlight(src *Image, on bool) *Image

apply highlighting to monochrome image

func NewImage

func NewImage(width, height, Channels int) *Image

func NewImageLike

func NewImageLike(src *Image) *Image

func (*Image) At

func (m *Image) At(x, y int) color.Color

func (*Image) Bounds

func (m *Image) Bounds() image.Rectangle

func (*Image) ColorModel

func (m *Image) ColorModel() color.Model

func (*Image) GrayAt

func (m *Image) GrayAt(x, y int) float32

func (*Image) MarshalBinary

func (m *Image) MarshalBinary() ([]byte, error)

func (*Image) Pixels

func (m *Image) Pixels(ch int) []float32

func (*Image) Set

func (m *Image) Set(x, y int, c color.Color)

func (*Image) SetColor

func (m *Image) SetColor(x, y int, c Color)

func (*Image) TransformType

func (m *Image) TransformType(normalise, distort bool) TransType

func (*Image) UnmarshalBinary

func (m *Image) UnmarshalBinary(data []byte) error

type TransType

type TransType int

Types of image transformations

const (
	Scale TransType = 1 << iota
	Rotate
	Elastic
	HorizFlip
	Pan
	Normalise
)
const NoTrans TransType = 0

func (TransType) String

func (t TransType) String() string

type Transformer

type Transformer struct {
	Amount float64
	Trans  TransType
	// contains filtered or unexported fields
}

func NewTransformer

func NewTransformer(data *Data, trans TransType, mode ConvMode, rng *rand.Rand) *Transformer

Create a new transformer object which applies a sequency of image transformations

func (*Transformer) Transform

func (t *Transformer) Transform(img *Image, thread int) (*Image, error)

Perform one or more image transforms

func (*Transformer) TransformBatch

func (t *Transformer) TransformBatch(index []int, dst []*Image) []*Image

Transform a batch of images in parallel

Jump to

Keyboard shortcuts

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