phash

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2020 License: MIT Imports: 4 Imported by: 2

README

phash

A simple Go package to calculate a phash of an image.

Documentation

Overview

Package phash computes a perceptual hash of an image.

Hash values are highly dependent on the scaling function used.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Distance

func Distance(h1, h2 uint64) int

Distance distance between two hashes (number of bits that differ)

func Get

func Get(img image.Image, scalefunc ScaleFunc) (uint64, error)

Get calculates perceptual hash for an image. It uses scalefunc to scale image to 32×32 size if needed.

Types

type ScaleFunc

type ScaleFunc func(img image.Image, width, height int) image.Image

ScaleFunc is a function Get uses to scale image to a 32×32 if needed.

An example of a ScaleFunc, using github.com/disintegration/imaging package:

scalefunc := func(img image.Image, w, h int) image.Image {
    return imaging.Resize(img, w, h, imaging.Lanczos)
}

Note that hash value depends highly on a scaling algorithm, smoother scaling algorithms usually work better.

Function must return a 32×32 image with its top left point having 0, 0 coordinates.

Jump to

Keyboard shortcuts

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