image

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2019 License: MIT Imports: 12 Imported by: 0

README

image

this is a simple go wrapper on TensorFlow image utils.

installation

install Go API for TensorFlow https://www.tensorflow.org/install/lang_go

$ go get github.com/sdeoras/comp/...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsSameSize

func IsSameSize(im1, im2 Image) bool

IsSameSize returns of two input images are of the same size.

Types

type Batch

type Batch [][]float32

A batch represents a batch of images, one per line, flattened.

func (Batch) ToCSV

func (batch Batch) ToCSV(fileName string) error

func (Batch) ToImages

func (batch Batch) ToImages(height, width int, path, nameTag string) error

type Color

type Color int

Color is one of three color values

const (
	Red Color = iota
	Green
	Blue
)

type EdgeType

type EdgeType int

EdgeType defines the edge detection direction.

const (
	Y EdgeType = iota
	X
)

type Image

type Image [][][]uint8

Image defines format of data returned by TensorFlow after image decoding

func Add

func Add(im1, im2 Image) (Image, error)

Add adds two images and creates a new one.

func Copy

func Copy(im Image) Image

Copy copies an image.

func NewBlack

func NewBlack(height, width int) Image

NewBlack creates a new image with zeros in all channels.

func NewConst

func NewConst(height, width int, r, g, b uint8) Image

NewConst creates a image with different channels offset with constants.

func NewRand

func NewRand(height, width int) Image

NewRand creates a new image with random noise.

func NewWhite

func NewWhite(height, width int) Image

NewWhite creates a new image with all values set to 255.

func (Image) AdaptiveToneShift

func (image Image) AdaptiveToneShift(n uint8, shiftLeft bool) Image

AdaptiveToneShift shifts the exposure by n counts either towards highlights of towards shadows (shiftLeft = true), but maintains the relative dynamic range by squeezing the histogram.

func (Image) ApplyMask

func (image Image) ApplyMask(mask Mask) (Image, error)

ApplyMask creates a new image copying only those pixels from input image that have a corresponding mask value of true.

func (Image) Box

func (image Image) Box(x, y, halfWidth int) Image

Box draws partially filled box.

func (Image) Circle

func (image Image) Circle(x, y, r int) Image

Circle draws partially filled circle.

func (Image) Copy

func (image Image) Copy() Image

Copy copies an image.

func (Image) RandBox

func (image Image) RandBox() Image

RandBox draws random partially filled box.

func (Image) RandCircle

func (image Image) RandCircle() Image

RandCircle draws random partially filled circle.

func (Image) RandScribe

func (image Image) RandScribe() Image

RandScribe draws a random scribe (line) on receiver image and modifies it before returning it.

func (Image) RandTriangle

func (image Image) RandTriangle() Image

RandTriangle draws a random triangle on receiver image and modifies it before returning it.

func (Image) RawScaled

func (image Image) RawScaled() ImageRaw

RawScaled rescales byte based input image into a float32 based data and rescales it in the range [0, 1]

func (Image) RawUnscaled

func (image Image) RawUnscaled() ImageRaw

RawUnscaled rescales byte based input image into a float32 based data

func (Image) Size

func (image Image) Size() (int, int, int)

Size returns height, width and number of color channels.

func (Image) Slice

func (image Image) Slice(c Color) (Slice, error)

type ImageProcessor

type ImageProcessor interface {
	Size() (int, int, int)
	Slice(c Color) (Slice, error)
	Flatten(image Image, flattenFunc func(r, g, b uint8) uint8) Slice
}

ImageProcessor works on an image producing various transformations

type ImageRaw

type ImageRaw [][][]float32

func (ImageRaw) Normalize

func (raw ImageRaw) Normalize(mean, variance float32) error

func (ImageRaw) Size

func (raw ImageRaw) Size() (int, int, int)

func (ImageRaw) ToImageScaled

func (raw ImageRaw) ToImageScaled() Image

func (ImageRaw) ToImageUnscaled

func (raw ImageRaw) ToImageUnscaled() Image

type Mask

type Mask [][]bool

Mask for an image.

func NewMask

func NewMask(height, width int) Mask

NewMask returns a new mask with all values set to false.

func (Mask) InheritEdges

func (mask Mask) InheritEdges(sobelRaw SobelRaw,
	edgeType EdgeType, f func(float32) bool, colors ...Color) error

InheritEdges updates mask with new edge data extracted from raw sobel data and a threshold.

func (Mask) Invert

func (mask Mask) Invert() Mask

Invert inverts a mask modying the original mask and returning the same

func (Mask) Size

func (mask Mask) Size() (int, int)

Size returns size of the mask.

func (Mask) ToSliceRaw

func (mask Mask) ToSliceRaw() SliceRaw

ToSliceRaw converts a mask into a floating point equivalent image frame.

type Op

type Op struct {
	// It embeds common op
	common.Op
}

Op is the operator for TF interface.

func NewOperator

func NewOperator(options *tf.SessionOptions) (*Op, error)

NewOperator provides an operator that implements Operator interface for jpg images.

func (*Op) Decode

func (op *Op) Decode(r io.Reader) (Image, error)

Decode decodes bytes from input reader into an Image.

func (*Op) Encode

func (op *Op) Encode(image Image) ([]byte, error)

Encode encodes input image into byte buffer suitable for writing file.

func (*Op) GetStats

func (op *Op) GetStats(images ...ImageRaw) ([]Stats, error)

GetStats gets image stats for normalization.

func (*Op) MakeBatch

func (op *Op) MakeBatch(height, width int, images ...Image) (Batch, error)

GetBatch performs batch grayscale, resize and normalization, producing a 2D matrix of float32.

func (*Op) RGB2GrayScale

func (op *Op) RGB2GrayScale(images ...Image) ([]Image, error)

RGB2GrayScale reduces color image into a grayscale.

func (*Op) Read

func (op *Op) Read(fileName string) (Image, error)

Read reads an Image from a file.

func (*Op) Resize

func (op *Op) Resize(height, width int, images ...Image) ([]ImageRaw, error)

Resize resized input image using bilinear algorithm.

func (*Op) ResizeNormalize

func (op *Op) ResizeNormalize(height, width int, mean, std float32, images ...Image) ([]ImageRaw, error)

ResizeNormalize resize and normalize input image using bilinear algorithm.

func (*Op) Sobel

func (op *Op) Sobel(images ...ImageRaw) ([]SobelRaw, error)

Sobel returns the Y edges, X edges and raw sobel data as output.

func (*Op) Write

func (op *Op) Write(image Image, fileName string) error

Write writes an image to a file.

type Operator

type Operator interface {
	// Read decodes input jpg file into an Image
	Read(fileName string) (Image, error)

	// Write writes image back to disk as a jpg file.
	Write(image Image, fileName string) error

	// Decode decodes byte buffer from reader into an Image
	Decode(r io.Reader) (Image, error)

	// Encode encodes image into byte buffer suitable for writing jpg file.
	Encode(image Image) ([]byte, error)

	// RGB2GrayScale converts input image into gray scale
	RGB2GrayScale(images ...Image) ([]Image, error)

	// Resize uses bilinear algorithm with alignCorners = true to resize an image.
	// height and width, when non positive, autoscale will decide the values.
	Resize(height, width int, images ...Image) ([]ImageRaw, error)

	// ResizeNormalize will resize and normalize images. It subtracts mean and then
	// divides by std.
	ResizeNormalize(height, width int, mean, std float32, images ...Image) ([]ImageRaw, error)

	// Sobel returns raw sobel output from sobel filter.
	Sobel(images ...ImageRaw) ([]SobelRaw, error)

	// Stats returns mean and variance for a raw image
	GetStats(images ...ImageRaw) ([]Stats, error)

	// Batch does following to each image:
	// * Convert to grayscale
	// * Resize
	// * Extract slide
	// * Normalize
	MakeBatch(height, width int, images ...Image) (Batch, error)
}

Operator defines operations for working with images

type Slice

type Slice [][]uint8

Slice is a color slice of an Image

type SliceRaw

type SliceRaw [][]float32

type SobelRaw

type SobelRaw [][][][]float32

SobelRaw is the raw output from sobel filter

func (SobelRaw) Size

func (sobelRaw SobelRaw) Size() (int, int, int)

type Stats

type Stats struct {
	Mean     float32
	Variance float32
}

Jump to

Keyboard shortcuts

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