goimagehash

package module
v0.0.0-...-e91c39c Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2025 License: BSD-2-Clause Imports: 15 Imported by: 3

README

GitHub Action GoDoc Go Report Card

goimagehash

Inspired by imagehash

A image hashing library written in Go. ImageHash supports:

Installation

go get gitea.narnian.us/lordwelch/goimagehash

Special thanks to

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, _ := 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)
        fmt.Printf("Distance between images: %v\n", distance)
        width, height := 8, 8
        hash3, _ := goimagehash.ExtAverageHash(img1, width, height)
        hash4, _ := goimagehash.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, _ := goimagehash.LoadExtImageHash(bar)
}

Release Note

v1.1.0
  • The performance of Perceptionhash is enhanced.
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
v1.0.1
  • Perception/ExtPerception hash creation times are reduced
v1.0.0

IMPORTANT goimagehash v1.0.0 does not have compatible with the before version for future features

v0.3.0
  • Support DifferenceHashExtend.
  • Support AverageHashExtend.
  • Support PerceptionHashExtend by @TokyoWolFrog.
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

Documentation

Index

Constants

View Source
const (
	YUV_FIX  = 16 // fixed-point precision for RGB->YUV
	YUV_HALF = 1 << (YUV_FIX - 1)

	YUV_FIX2  = 6 // fixed-point precision for YUV->RGB
	YUV_MASK2 = (256 << YUV_FIX2) - 1
)
View Source
const SCALE = 6

Variables

View Source
var (
	Y_R [256]int16 = [256]int16{}/* 256 elements not displayed */

	Y_G [256]int16 = [256]int16{}/* 256 elements not displayed */

	Y_B [256]int16 = [256]int16{}/* 256 elements not displayed */

	Cb_R [256]int16 = [256]int16{}/* 256 elements not displayed */

	Cb_G [256]int16 = [256]int16{}/* 256 elements not displayed */

	Cb_B [256]int16 = [256]int16{}/* 256 elements not displayed */

	Cr_R            = Cb_B
	Cr_G [256]int16 = [256]int16{}/* 256 elements not displayed */

	Cr_B [256]int16 = [256]int16{}/* 256 elements not displayed */

	R_Cr [256]int16 = [256]int16{}/* 256 elements not displayed */

	G_Cb [256]int16 = [256]int16{}/* 256 elements not displayed */

	G_Cr [256]int16 = [256]int16{}/* 256 elements not displayed */

	B_Cb [256]int16 = [256]int16{}/* 256 elements not displayed */

)
View Source
var P_YCbCrModel color.Model = color.ModelFunc(p_yCbCrModel)

YCbCrModel is the Model for Y'CbCr colors.

View Source
var YCbCrModel color.Model = color.ModelFunc(yCbCrModel)

YCbCrModel is the Model for Y'CbCr colors.

Functions

func FancyUpscale

func FancyUpscale(yuv *image.YCbCr) *image.RGBA

func FlattenPixels

func FlattenPixels(pixels [][]float64, x int, y int) []float64

FlattenPixels function flattens 2d array into 1d array.

func MultHi

func MultHi(v int32, coeff int32) int32

func P_ImagingConvertRGB2YCbCr

func P_ImagingConvertRGB2YCbCr(r, g, b, a uint8) (y, cb, cr, al uint8)

func P_ImagingConvertYCbCr2RGB

func P_ImagingConvertYCbCr2RGB(y, cb, cr, a uint8) (r, g, b, al uint8)

func Resize

func Resize(img image.Image, w, h int, gray *image.Gray) *image.Gray

func ToGray

func ToGray(img image.Image, pix []uint8) *image.Gray

func UpsampleRgbaLinePair

func UpsampleRgbaLinePair(topY []uint8, bottomY []uint8,
	topU []uint8, topV []uint8,
	bottomU []uint8, bottomV []uint8,
	topDst []uint8, bottomDst []uint8, rowLength int,
)

func VP8Clip8

func VP8Clip8(v int32) uint8

func VP8YUVToB

func VP8YUVToB(y uint8, u uint8) uint8

func VP8YUVToG

func VP8YUVToG(y uint8, u uint8, v uint8) uint8

func VP8YUVToR

func VP8YUVToR(y uint8, v uint8) uint8

func VP8YuvToArgb

func VP8YuvToArgb(y uint8, u uint8, v uint8) (argb [4]uint8)

func VP8YuvToBgr

func VP8YuvToBgr(y uint8, u uint8, v uint8) (bgr [3]uint8)

func VP8YuvToBgra

func VP8YuvToBgra(y uint8, u uint8, v uint8) (bgra [4]uint8)

func VP8YuvToRgb

func VP8YuvToRgb(y uint8, u uint8, v uint8) (rgb [3]uint8)

func VP8YuvToRgb565

func VP8YuvToRgb565(y uint8, u uint8, v uint8) (rgb [2]uint8)

func VP8YuvToRgba

func VP8YuvToRgba(y uint8, u uint8, v uint8) (rgba [4]uint8)

func VP8YuvToRgba4444

func VP8YuvToRgba4444(y uint8, u uint8, v uint8) (argb [2]uint8)

Types

type ExtImageHash

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

ExtImageHash is a struct of big hash computation.

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, hash_size, freq int) (*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 a 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 the 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) String

func (h *ExtImageHash) String() string

String 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 function returns a hash computation of average hash. Implementation follows http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html

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

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 ImageHash 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

func (*ImageHash) BinString

func (h *ImageHash) BinString() string

String returns a binary representation of the hash

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) String

func (h *ImageHash) String() string

String 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
	// DHash is a enum value of the difference hash.
	DHash
	// PHash is a enum value of the perceptual hash.
	PHash
	// WHash is a enum value of the wavelet hash.
	WHash
)

func (*Kind) MarshalJSON

func (k *Kind) MarshalJSON() ([]byte, error)

func (Kind) String

func (k Kind) String() string

func (*Kind) UnmarshalJSON

func (k *Kind) UnmarshalJSON(b []byte) error

type P_YCbCr

type P_YCbCr struct {
	*image.YCbCr
}

func (*P_YCbCr) At

func (p *P_YCbCr) At(x, y int) color.Color

func (*P_YCbCr) ColorModel

func (p *P_YCbCr) ColorModel() color.Model

func (*P_YCbCr) RGBA64At

func (p *P_YCbCr) RGBA64At(x, y int) color.RGBA64

func (*P_YCbCr) YCbCrAt

func (p *P_YCbCr) YCbCrAt(x, y int) P_YCbCr_color

type P_YCbCr_color

type P_YCbCr_color struct {
	color.YCbCr
}

func (P_YCbCr_color) RGBA

func (c P_YCbCr_color) RGBA() (uint32, uint32, uint32, uint32)

type WebPUpsampleLinePairFunc

type WebPUpsampleLinePairFunc func(topY []uint8, bottomY []uint8,
	topU []uint8, topV []uint8,
	bottomU []uint8, bottomV []uint8,
	topDst []uint8, bottomDst []uint8, len int)

type YCbCr

type YCbCr struct {
	*image.YCbCr
}

func (*YCbCr) At

func (p *YCbCr) At(x, y int) color.Color

func (*YCbCr) ColorModel

func (p *YCbCr) ColorModel() color.Model

func (*YCbCr) RGBA64At

func (p *YCbCr) RGBA64At(x, y int) color.RGBA64

func (*YCbCr) YCbCrAt

func (p *YCbCr) YCbCrAt(x, y int) YCbCr_color

type YCbCr_color

type YCbCr_color struct {
	color.YCbCr
}

func (YCbCr_color) RGBA

func (c YCbCr_color) RGBA() (uint32, uint32, uint32, uint32)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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