2024-05-01 18:06:48 -07:00
![GitHub Action ](https://gitea.narnian.us/lordwelch/goimagehash/workflows/goimagehash%20workflow/badge.svg )
[![GoDoc ](https://godoc.org/gitea.narnian.us/lordwelch/goimagehash?status.svg )](https://godoc.org/gitea.narnian.us/lordwelch/goimagehash)
[![Go Report Card ](https://goreportcard.com/badge/gitea.narnian.us/lordwelch/goimagehash )](https://goreportcard.com/report/gitea.narnian.us/lordwelch/goimagehash)
2017-07-28 10:18:24 -07:00
2017-07-28 10:15:59 -07:00
# goimagehash
2017-07-28 10:18:24 -07:00
> Inspired by [imagehash](https://github.com/JohannesBuchner/imagehash)
A image hashing library written in Go. ImageHash supports:
* [Average hashing ](http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html )
* [Difference hashing ](http://www.hackerfactor.com/blog/index.php?/archives/529-Kind-of-Like-That.html )
* [Perception hashing ](http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html )
2017-08-03 06:35:50 -07:00
* [Wavelet hashing ](https://fullstackml.com/wavelet-image-hash-in-python-3504fdd282b5 ) [TODO]
2017-07-28 10:18:24 -07:00
## Installation
```
2024-05-01 18:06:48 -07:00
go get gitea.narnian.us/lordwelch/goimagehash
2017-07-28 10:18:24 -07:00
```
## Special thanks to
* [Haeun Kim ](https://github.com/haeungun/ )
## Usage
``` Go
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, _ := goimagehash.AverageHash(img1)
hash2, _ := goimagehash.AverageHash(img2)
distance, _ := hash1.Distance(hash2)
fmt.Printf("Distance between images: %v\n", distance)
hash1, _ = goimagehash.DifferenceHash(img1)
hash2, _ = goimagehash.DifferenceHash(img2)
distance, _ = hash1.Distance(hash2)
2019-09-07 09:03:41 -07:00
fmt.Printf("Distance between images: %v\n", distance)
2019-03-18 05:40:16 -07:00
width, height := 8, 8
2022-10-09 04:42:03 -07:00
hash3, _ := goimagehash.ExtAverageHash(img1, width, height)
hash4, _ := goimagehash.ExtAverageHash(img2, width, height)
2019-03-16 23:42:07 -07:00
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)
2019-03-18 07:53:09 -07:00
hash5, _ := goimagehash.LoadExtImageHash(bar)
2017-07-28 10:18:24 -07:00
}
```
2018-05-08 17:37:49 -07:00
## Release Note
2022-05-26 02:37:45 -07:00
### v1.1.0
- The performance of Perceptionhash is enhanced.
2020-10-02 23:33:01 -07:00
### v1.0.3
- Add workflow for GithubAction
- Fix typo on the GoDoc for LoadImageHash
### v1.0.2
- go.mod is now used for install goimagehash
2018-05-08 17:37:49 -07:00
2019-03-19 07:10:52 -07:00
### v1.0.1
- Perception/ExtPerception hash creation times are reduced
2019-03-18 08:06:12 -07:00
### v1.0.0
2020-10-02 23:33:01 -07:00
**IMPORTANT**
2019-03-18 08:06:12 -07:00
goimagehash v1.0.0 does not have compatible with the before version for future features
2024-05-01 18:06:48 -07:00
- More flexible extended hash APIs are provided ([ExtAverageHash](https://godoc.org/gitea.narnian.us/lordwelch/goimagehash#ExtAverageHash), [ExtPerceptionHash ](https://godoc.org/gitea.narnian.us/lordwelch/goimagehash#ExtPerceptionHash ), [ExtDifferenceHash ](https://godoc.org/gitea.narnian.us/lordwelch/goimagehash#ExtDifferenceHash ))
- New serialization APIs are provided([ImageHash.Dump](https://godoc.org/gitea.narnian.us/lordwelch/goimagehash#ImageHash.Dump), [ExtImageHash.Dump ](https://godoc.org/gitea.narnian.us/lordwelch/goimagehash#ExtImageHash.Dump ))
- [ExtImageHashFromString ](https://godoc.org/gitea.narnian.us/lordwelch/goimagehash#ExtImageHashFromString ), [ImageHashFromString ](https://godoc.org/gitea.narnian.us/lordwelch/goimagehash#ImageHashFromString ) is deprecated and will be removed
- New deserialization APIs are provided([LoadImageHash](https://godoc.org/gitea.narnian.us/lordwelch/goimagehash#LoadImageHash), [LoadExtImageHash ](https://godoc.org/gitea.narnian.us/lordwelch/goimagehash#LoadExtImageHash ))
2019-03-18 08:06:12 -07:00
- Bits APIs are provided to measure actual bit size of hash
2019-03-16 07:22:05 -07:00
2019-03-15 08:54:05 -07:00
### v0.3.0
- Support DifferenceHashExtend.
- Support AverageHashExtend.
- Support PerceptionHashExtend by @TokyoWolFrog .
2018-05-08 17:37:49 -07:00
### v0.2.0
- Perception Hash is updated.
- Fix a critical bug of finding median value.
### v0.1.0
- Support Average hashing
- Support Difference hashing
- Support Perception hashing
- Use bits.OnesCount64 for computing Hamming distance by @dominikh
- Support hex serialization methods to ImageHash by @brunoro