hash

package
v0.0.0-...-e9edd25 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2019 License: MIT, BSD-2-Clause Imports: 10 Imported by: 0

README

Image Hashing

License Godoc ReportCard

Installation

go get github.com/evanoberholster/imagecolor/phash

Usage

func main() {
        file1, _ := os.Open("sample1.jpg")
        file2, _ := os.Open("sample2.jpg")
        defer file1.Close()
        defer file2.Close()

        img1, _ := jpeg.Decode(file1)
        img2, _ := jpeg.Decode(file2)
        hash1, _ := hash.AverageHash(img1)
        hash2, _ := hash.AverageHash(img2)
        distance, _ := hash1.Distance(hash2)
        fmt.Printf("Distance between images: %v\n", distance)

        hash1, _ = hash.DifferenceHash(img1)
        hash2, _ = hash.DifferenceHash(img2)
        distance, _ = hash1.Distance(hash2)
        fmt.Printf("Distance between images: %v\n", distance)
        width, height := 8, 8
        hash3, _ = hash.ExtAverageHash(img1, width, height)
        hash4, _ = hash.ExtAverageHash(img2, width, height)
        distance, _ = hash3.Distance(hash4)
        fmt.Printf("Distance between images: %v\n", distance)
        fmt.Printf("hash3 bit size: %v\n", hash3.Bits())
        fmt.Printf("hash4 bit size: %v\n", hash4.Bits())

        var b bytes.Buffer
        foo := bufio.NewWriter(&b)
        _ = hash4.Dump(foo)
        foo.Flush()
        bar := bufio.NewReader(&b)
        hash5, _ := hash.LoadExtImageHash(bar)
}

Inspired By

Inspired by imagehash Inspired by goimagehash

A image hashing library written in Go. ImageHash supports:

Special thanks to

AUTHORS

LICENSE

BSD 2-Clause License

Copyright (c) 2019, Evan Oberholster & Contributors

Copyright (c) 2017, Dong-hee Na

Documentation

Index

Constants

View Source
const (
	ErrorImageToLarge    = "Image is wrong size"
	ErrorNoImage         = "Image object can not be nil"
	ErrorImageWrongSize  = "Image needs to support 64bit or 256bit Hashing"
	ErrorImageDimensions = "Width * Height should be the power of 2"
)

Errors

Variables

This section is empty.

Functions

func MeanOfPixels

func MeanOfPixels(pixels []float64) float64

MeanOfPixels function returns a mean of pixels.

func MedianOfPixels

func MedianOfPixels(pixels []float64) float64

MedianOfPixels function returns a median value of pixels. It uses quick selection algorithm.

Types

type ExtImageHash

type ExtImageHash struct {
	// contains filtered or unexported fields
}

ExtImageHash is a struct of big hash computation.

func ExtAverageHash

func ExtAverageHash(img image.Image) (*ExtImageHash, error)

ExtAverageHash function returns ahash of which the size can be set larger than uint64 Support 64bits ahash (width=8, height=8) and 256bits ahash (width=16, height=16)

func ExtDifferenceHash

func ExtDifferenceHash(img image.Image) (*ExtImageHash, error)

ExtDifferenceHash function returns dhash of which the size can be set larger than uint64 Support 64bits dhash (width=8, height=8) and 256bits dhash (width=16, height=16)

func ExtImageHashFromString deprecated

func ExtImageHashFromString(s string) (*ExtImageHash, error)

ExtImageHashFromString returns a big hash from a hex representation

Deprecated: Use goimagehash.LoadExtImageHash instead.

func ExtPerceptionHash

func ExtPerceptionHash(img image.Image) (*ExtImageHash, error)

ExtPerceptionHash function returns phash of which the size can be set larger than uint64 Some variable name refer to https://github.com/JohannesBuchner/imagehash/blob/master/imagehash/__init__.py Support 64bits phash (width=8, height=8) and 256bits phash (width=16, height=16) Important: width * height should be the power of 2

func LoadExtImageHash

func LoadExtImageHash(b io.Reader) (*ExtImageHash, error)

LoadExtImageHash method loads a ExtImageHash from io.Reader.

func NewExtImageHash

func NewExtImageHash(hash []uint64, kind Kind, bits int) *ExtImageHash

NewExtImageHash function creates a new big hash

func (*ExtImageHash) Bits

func (h *ExtImageHash) Bits() int

Bits method returns an actual hash bit size

func (*ExtImageHash) Distance

func (h *ExtImageHash) Distance(other *ExtImageHash) (int, error)

Distance method returns a distance between two big hashes

func (*ExtImageHash) Dump

func (h *ExtImageHash) Dump(w io.Writer) error

Dump method writes a binary serialization into w io.Writer.

func (*ExtImageHash) GetHash

func (h *ExtImageHash) GetHash() []uint64

GetHash method returns a big hash value

func (*ExtImageHash) GetKind

func (h *ExtImageHash) GetKind() Kind

GetKind method returns a kind of big hash

func (*ExtImageHash) ToString

func (h *ExtImageHash) ToString() string

ToString returns a hex representation of big hash

type ImageHash

type ImageHash struct {
	// contains filtered or unexported fields
}

ImageHash is a struct of hash computation.

func AverageHash

func AverageHash(img image.Image) (*ImageHash, error)

AverageHash fuction returns a hash computation of average hash. Implementation follows http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html Recommended Image size 8x8

func DifferenceHash

func DifferenceHash(img image.Image) (*ImageHash, error)

DifferenceHash function returns a hash computation of difference hash. Implementation follows http://www.hackerfactor.com/blog/?/archives/529-Kind-of-Like-That.html Recommended Image size 9x8

func ImageHashFromString deprecated

func ImageHashFromString(s string) (*ImageHash, error)

ImageHashFromString returns an image hash from a hex representation

Deprecated: Use goimagehash.LoadImageHash instead.

func LoadImageHash

func LoadImageHash(b io.Reader) (*ImageHash, error)

LoadImageHash method loads a ExtImageHash from io.Reader.

func NewImageHash

func NewImageHash(hash uint64, kind Kind) *ImageHash

NewImageHash function creates a new image hash.

func PerceptionHash

func PerceptionHash(img image.Image) (*ImageHash, error)

PerceptionHash function returns a hash computation of phash. Implementation follows http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html Recommended Image size 64x64

func (*ImageHash) Bits

func (h *ImageHash) Bits() int

Bits method returns an actual hash bit size

func (*ImageHash) Distance

func (h *ImageHash) Distance(other *ImageHash) (int, error)

Distance method returns a distance between two hashes.

func (*ImageHash) Dump

func (h *ImageHash) Dump(w io.Writer) error

Dump method writes a binary serialization into w io.Writer.

func (*ImageHash) GetHash

func (h *ImageHash) GetHash() uint64

GetHash method returns a 64bits hash value.

func (*ImageHash) GetKind

func (h *ImageHash) GetKind() Kind

GetKind method returns a kind of image hash.

func (*ImageHash) ToString

func (h *ImageHash) ToString() string

ToString returns a hex representation of the hash

type Kind

type Kind int

Kind describes the kinds of hash.

const (
	// Unknown is a enum value of the unknown hash.
	Unknown Kind = iota
	// AHash is a enum value of the average hash.
	AHash
	//PHash is a enum value of the perceptual hash.
	PHash
	// DHash is a enum value of the difference hash.
	DHash
	// WHash is a enum value of the wavelet hash.
	WHash
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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