Update docs.

This commit is contained in:
Dong-hee Na 2017-07-31 23:24:04 +09:00
parent 7aba8954cd
commit 2b9c664be8
6 changed files with 22 additions and 20 deletions

View File

@ -1,5 +1,6 @@
[![Build Status](https://travis-ci.org/corona10/goimagehash.svg?branch=master)](https://travis-ci.org/corona10/goimagehash)
[![GoDoc](https://godoc.org/github.com/corona10/goimagehash?status.svg)](https://godoc.org/github.com/corona10/goimagehash)
[![Go Report Card](https://goreportcard.com/badge/github.com/corona10/goimagehash)](https://goreportcard.com/report/github.com/corona10/goimagehash)
# goimagehash
> Inspired by [imagehash](https://github.com/JohannesBuchner/imagehash)

View File

@ -4,7 +4,7 @@
package etcs
// Calculate mean of pixels.
// MeanOfPixels function returns a mean of pixels.
func MeanOfPixels(pixels []float64) float64 {
m := 0.0
lens := len(pixels)
@ -19,8 +19,8 @@ func MeanOfPixels(pixels []float64) float64 {
return m / float64(lens)
}
// Get a median value of pixels.
// Use quick selection algorithm.
// MedianOfPixels function returns a median value of pixels.
// It uses quick selection algorithm.
func MedianOfPixels(pixels []float64) float64 {
tmp := make([]float64, len(pixels))
copy(tmp, pixels)

View File

@ -13,8 +13,7 @@ import (
"github.com/nfnt/resize"
)
// Average Hash computation.
// Return 64bits hash.
// AverageHash fuction returns a hash computation of average hash.
// Implementation follows
// http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html
func AverageHash(img image.Image) (*ImageHash, error) {
@ -38,7 +37,7 @@ func AverageHash(img image.Image) (*ImageHash, error) {
return ahash, nil
}
// Difference Hash computation.
// DifferenceHash function returns a hash computation of difference hash.
// Implementation follows
// http://www.hackerfactor.com/blog/?/archives/529-Kind-of-Like-That.html
func DifferenceHash(img image.Image) (*ImageHash, error) {
@ -62,7 +61,7 @@ func DifferenceHash(img image.Image) (*ImageHash, error) {
return dhash, nil
}
// Perceptual Hash computation.
// PerceptionHash function returns a hash computation of phash.
// Implementation follows
// http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html
func PerceptionHash(img image.Image) (*ImageHash, error) {

View File

@ -11,25 +11,26 @@ import (
// hashKind describes the kinds of hash.
type hashKind int
// ImageHash is a struct of hash computation.
type ImageHash struct {
hash uint64
kind hashKind
}
const (
Unknown hashKind = iota
AHash // Average Hash
PHash // Perceptual Hash
DHash // Difference Hash
WHash // Wavlet Hash
Unknown hashKind = iota // Unknown Hash
AHash // Average Hash
PHash // Perceptual Hash
DHash // Difference Hash
WHash // Wavlet Hash
)
// Create a new image hash.
// NewImageHash function creates a new image hash.
func NewImageHash(hash uint64, kind hashKind) *ImageHash {
return &ImageHash{hash: hash, kind: kind}
}
// Return distance between hashes.
// Distance method returns a distance between two hashes.
func (h *ImageHash) Distance(other *ImageHash) (int, error) {
if h.GetKind() != other.GetKind() {
return -1, errors.New("Image hashes's kind should be identical.")
@ -48,17 +49,17 @@ func (h *ImageHash) Distance(other *ImageHash) (int, error) {
return diff, nil
}
// Return hash values.
// GetHash method returns a 64bits hash value.
func (h *ImageHash) GetHash() uint64 {
return h.hash
}
// Get kind of a hash.
// GetKind method returns a kind of image hash.
func (h *ImageHash) GetKind() hashKind {
return h.kind
}
// Set index of bits.
// Set method sets a bit of index.
func (h *ImageHash) Set(idx int) {
h.hash |= 1 << uint(idx)
}

View File

@ -8,7 +8,7 @@ import (
"math"
)
// Get result of DCT-II.
// DCT1D function returns result of DCT-II.
// Follows Matlab dct().
// Implementation reference:
// https://unix4lyfe.org/dct-1d/
@ -30,7 +30,7 @@ func DCT1D(input []float64) []float64 {
return out
}
// Get result of DCT2D by using the seperable property.
// DCT2D function returns a result of DCT2D by using the seperable property.
func DCT2D(input [][]float64, w int, h int) [][]float64 {
output := make([][]float64, h)
for i := range output {

View File

@ -8,7 +8,7 @@ import (
"image"
)
// Convert RGB to a gray scale flatten array.
// Rgb2Gray function converts RGB to a gray scale array.
func Rgb2Gray(colorImg image.Image) [][]float64 {
bounds := colorImg.Bounds()
w, h := bounds.Max.X, bounds.Max.Y
@ -27,6 +27,7 @@ func Rgb2Gray(colorImg image.Image) [][]float64 {
return pixels
}
// FlattenPixels function flattens 2d array into 1d array.
func FlattenPixels(pixels [][]float64, x int, y int) []float64 {
flattens := make([]float64, x*y)
for i := 0; i < y; i++ {