Documentation ¶
Index ¶
- Constants
- Variables
- func Asset(name string) ([]byte, error)
- func AssetDir(name string) ([]string, error)
- func AssetInfo(name string) (os.FileInfo, error)
- func AssetNames() []string
- func Compare(img1, img2 image.Image) (int64, error)
- func ConvertToRGBA(img image.Image) (result *image.RGBA)
- func DeriveCheckpointFile(sourceFile, cpArg string, polyCount int) string
- func FastCompare(img1, img2 *image.RGBA) (uint64, error)
- func MustAsset(name string) []byte
- func MustReadImage(file string) image.Image
- func RandomBool() bool
- func RandomInt(min, max int) int
- func RestoreAsset(dir, name string) error
- func RestoreAssets(dir, name string) error
- func Serve(hostPort string, refImg image.Image, previews []*SafeImage)
- func SplitPath(path string) []string
- type ByFitness
- type Candidate
- type Checkpoint
- type Evolver
- type Page
- type Point
- type Polygon
- type SafeImage
- type Stats
Constants ¶
const ( MutationAlpha = iota MutationColor = iota MutationPoint = iota MutationZOrder = iota MutationAddOrDeletePoint = iota )
const ( PopulationCount = 10 MaxPolygonPoints = 6 MinPolygonPoints = 3 PointMutationMaxDistance = 5 MutationsPerIteration = 1 // originally had 3, but 1 seems to work best here )
Variables ¶
var (
Mutations = []int{MutationColor, MutationPoint, MutationAlpha, MutationZOrder, MutationAddOrDeletePoint}
)
Functions ¶
func Asset ¶
Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.
func AssetDir ¶
AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:
data/ foo.txt img/ a.png b.png
then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.
func AssetInfo ¶
AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.
func Compare ¶
Compare compares images by computing the square root of the total sum of individual squared pixel differences.
func ConvertToRGBA ¶
from http://blog.golang.org/go-imagedraw-package ("Converting an Image to RGBA"), modified slightly to be a no-op if the src image is already RGBA
func DeriveCheckpointFile ¶
try to make it painless for users to automatically get a checkpoint file. We want the file to be tied both the source file name and the polygon count. If an explicit cpArg is given, we just use that.
func FastCompare ¶
FastCompare compares images by diffing the underlying byte arrays directly. This is more than 10x faster than Compare(), but requires a concrete instance of image.RGBA.
func MustAsset ¶
MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.
func MustReadImage ¶
func RandomBool ¶
func RandomBool() bool
RandomBool uses the default random Source to return either true or false.
func RandomInt ¶
RandomInt uses the default random Source to return a random integer that is >= min, but < max
func RestoreAsset ¶
RestoreAsset restores an asset under the given directory
func RestoreAssets ¶
RestoreAssets restores an asset under the given directory recursively
Types ¶
type Candidate ¶
type Candidate struct {
W, H int
Polygons []*Polygon
Fitness uint64
// contains filtered or unexported fields
}
Candidate is a potential solution (set of polygons) to the problem of how to best represent the reference image.
type Checkpoint ¶
Checkpoint is used for serializing the current best candidate and corresponding generation count to a checkpoint file.
type Evolver ¶
type Evolver struct {
// contains filtered or unexported fields
}
Evolver uses a genetic algorithm to evolve a set of polygons to approximate an image.
func NewEvolver ¶
type SafeImage ¶
type SafeImage struct {
// contains filtered or unexported fields
}
SafeImage is an image protected by a RWMutex. All access should be via the Update() and Value() methods. This allows us to update the candidate images from a goroutine in the Evolver, and display them in the Server.