Documentation ¶
Index ¶
- Variables
- func CentralHash(icon IconT, hyperPoints []Point, epsPercent float64, numBuckets int) uint64
- func CustomPoints(n int) map[Point]bool
- func EucMetric(iconA, iconB IconT) (m1, m2, m3 float32)
- func HashSet(icon IconT, hyperPoints []Point, epsPercent float64, numBuckets int) []uint64
- func Open(path string) (img image.Image, err error)
- func PropMetric(iconA, iconB IconT) (m float64)
- func ResizeByNearest(src image.Image, dstX, dstY int) (dst image.RGBA, srcX, srcY int)
- func SaveToJPG(img *image.RGBA, path string, quality int)
- func SaveToPNG(img *image.RGBA, path string)
- func Similar(iconA, iconB IconT) bool
- type IconT
- type Point
Constants ¶
This section is empty.
Variables ¶
var HyperPoints10 = []Point{
{2, 5}, {3, 3}, {3, 8}, {4, 6}, {5, 2},
{6, 4}, {6, 7}, {8, 2}, {8, 5}, {8, 8}}
HyperPoints10 is a convenience 10-point predefined set with coordinates of icon values to become 10 dimensions needed for hash generation with package "hyper". The 10 points are the only pixels from an icon to be used for hash generation (unless you define your own set of hyper points with CustomPoints function, or manually. The 10 points have been modified manually a little to avoid texture-like symmetries.
Functions ¶
func CentralHash ¶
CentralHash generates a central hash for a given icon by sampling luma values at well-distributed icon points (hyperPoints, HyperPoints10) and later using package "hyper". This hash can then be used for a record or a query. When used for a record, you will need a hash set made with func HashSet for a query. And vice versa. To better understand CentralHash, read the following doc: https://vitali-fedulov.github.io/algorithm-for-hashing-high-dimensional-float-vectors.html
func CustomPoints ¶
CustomPoints is a utility function to create hyper points similar to HyperPoints10. It is needed if you are planning to use the package with billions of images, and might need higher number of sample points (more dimensions). You may also decide to reduce number of dimensions in order to reduce number of hashes per image. In both cases CustomPoints will help generate point sets similar to HyperPoints10. The function chooses a set of points (pixels from Icon) placed apart as far as possible from each other to increase variable independence. Number of chosen points corresponds to the number of dimensions n. Brightness values at those points represent one coordinate each in n-dimensional space for hash generation with package "hyper". Final point patterns are somewhat irregular, which is good to avoid occasional mutual pixel dependence of textures in images. For cases of low n, to avoid texture-like symmetries and visible patterns, it is recommended to slightly modify point positions manually, and with that distribute points irregularly across the Icon.
func EucMetric ¶
EucMetric returns Euclidean distances between 2 icons. These are 3 metrics corresponding to each color channel. The distances are squared to avoid square root calculations. Note that the channels are not RGB, but YCbCr, thus their importance for similarity might be not the same.
func HashSet ¶
HashSet generates a hash set for a given icon by sampling luma values of well-distributed icon points (hyperPoints, HyperPoints10) and later using package "hyper". This hash set can then be used for records or a query. When used for a query, you will need a hash made with func CentralHash as a record. And vice versa. To better understand HashSet, read the following doc: https://vitali-fedulov.github.io/algorithm-for-hashing-high-dimensional-float-vectors.html
func PropMetric ¶
PropMetric gives image proportion similarity metric for image A and B. The smaller the metric the more similar are images by their x-y size.
func ResizeByNearest ¶ added in v1.0.7
ResizeByNearest resizes an image by the nearest neighbour method to the output size outX, outY. It also returns the size inX, inY of the input image.
Types ¶
type IconT ¶
type IconT struct { Pixels []float32 ImgSize Point // Original image size. Path string // Original image path. }
Icon has square shape. Its pixels are float32 values for 3 channels. Float32 is intentional to preserve color relationships from the full-size image.
func EmptyIcon ¶
func EmptyIcon() (icon IconT)
EmptyIcon is an icon constructor in case you need an icon with nil values, for example for convenient error handling. Then you can use icon.Pixels == nil condition.