imgsim

package module
v0.0.0-...-5caa057 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2018 License: MIT Imports: 4 Imported by: 5

README

Imgsim GoDoc Go Report Card unstable

Imgsim is a library allows you to compute a fast perceptual hashes of an image. These hashes can then be used to compare images for similarity. Similar looking images will get similar perceptual hashes. Unlike cryptographic hashes that would be very different for images with slight differences. This makes them suitable to compare how similar images are.

Average hash

An average hash is an example of a perceptual hash.

For an introduction see: Average hash

Difference hash

Difference hashes are said to be more resillient to changes in the image then the Average hash.

For an introduction see: Difference hash

Installation

The package is go-gettable: go get -u github.com/Nr90/imgsim.

Example

package main

import (
	"fmt"
	"image/png"
	"os"

	"github.com/Nr90/imgsim"
)

func main() {
	imgfile, err := os.Open("assets/gopher.png")
	defer imgfile.Close()
	if err != nil {
		panic(err)
	}
	img, err := png.Decode(imgfile)
	if err != nil {
		panic(err)
	}
	ahash := imgsim.AverageHash(img)
	fmt.Println(ahash)
	dhash := imgsim.DifferenceHash(img)
	fmt.Println(dhash)
}

Documentation

Overview

Package imgsim is a library allows you to compute a fast perceptual hashes of an image. These hashes can then be used to compare images for similarity. Similar looking images will get similar perceptual hashes, unlike cryptographic hashes that would be very different for images with slight differences. This makes them suitable to measure how similar images are.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Distance

func Distance(a, b Hash) int

Distance calculates the number of different bits in the hash

Types

type Hash

type Hash uint64

Hash contains the perceptual hash stored as bits in a 64 bit unsigned integer.

func AverageHash

func AverageHash(img image.Image) Hash

AverageHash calculates the average hash of an image. First the image is resized to 8x8. Then it is converted to grayscale. Lastly the average hash is computed.

func DifferenceHash

func DifferenceHash(img image.Image) Hash

DifferenceHash calculates the average hash of an image. First the image is converted to grayscale Then it is resized to 9x8. Lastly the average hash is computed.

func (Hash) String

func (h Hash) String() string

Jump to

Keyboard shortcuts

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