From 2b9c664be83e939a9856f9d1e725d41b471cbd55 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Mon, 31 Jul 2017 23:24:04 +0900 Subject: [PATCH] Update docs. --- README.md | 1 + etcs/utils.go | 6 +++--- hashcompute.go | 7 +++---- imagehash.go | 21 +++++++++++---------- transforms/dct.go | 4 ++-- transforms/pixels.go | 3 ++- 6 files changed, 22 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 00662cc..bbb810c 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/etcs/utils.go b/etcs/utils.go index 1c9249d..c75133d 100644 --- a/etcs/utils.go +++ b/etcs/utils.go @@ -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) diff --git a/hashcompute.go b/hashcompute.go index a528908..490a6bc 100644 --- a/hashcompute.go +++ b/hashcompute.go @@ -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) { diff --git a/imagehash.go b/imagehash.go index 1b02809..0db84c0 100644 --- a/imagehash.go +++ b/imagehash.go @@ -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) } diff --git a/transforms/dct.go b/transforms/dct.go index b7a00e6..e3de089 100644 --- a/transforms/dct.go +++ b/transforms/dct.go @@ -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 { diff --git a/transforms/pixels.go b/transforms/pixels.go index 1b93b60..744c4ac 100644 --- a/transforms/pixels.go +++ b/transforms/pixels.go @@ -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++ {