Giter VIP home page Giter VIP logo

images's Introduction

Comparing images in Go โž” LATEST version

Near duplicates and resized images can be found with the module.

Demo: similar image search and clustering (deployed from).

Semantic versions:

  • v1/v2 (/images) - this repository,
  • v3 (/images3),
  • v4 (/images4) - latest recommended.

All versions will be kept available indefinitely.

About this repo

There are no dependencies: only the Golang standard library is used. Supported image types: GIF, JPEG and PNG (golang.org/pkg/image/ as in October 2018).

Similar function gives a verdict whether 2 images are similar or not. The library also contains wrapper functions to open/save images and basic image resampling/resizing.

SimilarCustom function allows your own similarity metric thresholds.

Documentation: godoc.

Example of comparing 2 photos

To test this example go-file, you need to initialize modules from command line, because v2 uses them:

go mod init foo

Here foo can be anything for testing purposes. Then get the required import:

go get github.com/vitali-fedulov/images/v2

Now you are ready to run or build the example.

package main

import (
	"fmt"

	// v2 is module-based. v1 is not.
	"github.com/vitali-fedulov/images/v2"

	// Golang explanation on module versions:
	// https://go.dev/blog/v2-go-modules
)

func main() {
	
	// Open photos.
	imgA, err := images.Open("photoA.jpg")
	if err != nil {
		panic(err)
	}
	imgB, err := images.Open("photoB.jpg")
	if err != nil {
		panic(err)
	}
	
	// Calculate hashes and image sizes.
	hashA, imgSizeA := images.Hash(imgA)
	hashB, imgSizeB := images.Hash(imgB)
	
	// Image comparison.
	if images.Similar(hashA, hashB, imgSizeA, imgSizeB) {
		fmt.Println("Images are similar.")
	} else {
		fmt.Println("Images are distinct.")
	}
}

Algorithm for image comparison

Detailed explanation, also as a PDF.

Summary: In the algorithm images are resized to small squares of fixed size. A number of masks representing several sample pixels are run against the resized images to calculate average color values. Then the values are compared to give the similarity verdict. Also image proportions are used to avoid matching images of distinct shape.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.