Home

Awesome

<p align="center"><img src="https://raw.githubusercontent.com/dsys/match/master/resources/logo.png" alt="logo" width="220" /></p> <p align="center"><strong>Scalable reverse image search</strong><br /><em>built on <a href="http://kubernetes.io/">Kubernetes</a> and <a href="https://www.elastic.co/">Elasticsearch</a></em></p> <p align="center"><a href="https://github.com/dsys/match/stargazers"><img src="https://img.shields.io/github/stars/dsys/match.svg?style=flat" alt="GitHub stars" /></a> <a href="https://hub.docker.com/r/dsys/match/"><img src="https://img.shields.io/docker/pulls/dsys/match.svg" alt="Docker Pulls" /></a> <a href="http://kubernetes.io"><img src="https://img.shields.io/badge/kubernetes-ready-brightgreen.svg?style=flat" alt="Kubernetes shield" /></a> <a href="https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fdsys%2Fmatch?ref=badge_shield" alt="FOSSA Status"><img src="https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fdsys%2Fmatch.svg?type=shield"/></a></p>

Match makes it easy to search for images that look similar to each other. Using a state-of-the-art perceptual hash, it is invariant to scaling and 90 degree rotations. Its HTTP API is quick to integrate and flexible for a number of reverse image search applications. Kubernetes and Elasticsearch allow Match to scale to billions of images with ease while giving you full control over where your data is stored. Match uses the awesome ascribe/image-match under the hood for most of the image search legwork.

  1. Getting Started
  2. API
  3. Development
  4. License and Acknowledgements

Getting Started

If you already have ElasticSearch running:

$ docker run -e ELASTICSEARCH_URL=https://daisy.us-west-1.es.amazonaws.com -it dsys/match

If you want to run ElasticSearch locally as well, have docker-compose installed on your system, clone this repository and type:

$ make dev

Match is packaged as a Docker container (dsys/match on Docker Hub), making it highly portable and scalable to billions of images. You can configure a few options using environment variables:

Using in your own Kubernetes cluster

You can configure the service, replication controller, and secret like so:

# match-service.yml
apiVersion: v1
kind: Service
metadata:
  name: match
spec:
  ports:
  - name: http
    port: 80
    protocol: TCP
  selector:
    app: match
# match-rc.yml
apiVersion: v1
kind: ReplicationController
metadata:
  name: match
spec:
  replicas: 1
  selector:
    app: match
  template:
    metadata:
      labels:
        app: match
    spec:
      containers:
      - name: match
        image: dsys/match:latest
        ports:
        - containerPort: 80
        env:
        - name: WORKER_COUNT
          value: "4"
        - name: ELASTICSEARCH_URL
          valueFrom:
            secretKeyRef:
              name: match
              key: elasticsearch.url
        - name: ELASTICSEARCH_INDEX
          valueFrom:
            secretKeyRef:
              name: match
              key: elasticsearch.index
        - name: ELASTICSEARCH_DOC_TYPE
          valueFrom:
            secretKeyRef:
              name: match
              key: elasticsearch.doc-type
# match-secret.yml
apiVersion: v1
kind: Secret
metadata:
  name: match
data:
  # https://daisy.us-west-1.es.amazonaws.com (change me)
  elasticsearch.url: aHR0cHM6Ly9kYWlzeS51cy13ZXN0LTEuZXMuYW1hem9uYXdzLmNvbQ==

  # images
  elasticsearch.index: aW1hZ2Vz

  # images
  elasticsearch.doc-type: aW1hZ2Vz

API

Match has a simple HTTP API. All request parameters are specified via application/x-www-form-urlencoded or multipart/form-data.


POST /add

Adds an image signature to the database.

Parameters

Example Response

{
  "status": "ok",
  "error": [],
  "method": "add",
  "result": []
}

DELETE /delete

Deletes an image signature from the database.

Parameters

Example Response

{
  "status": "ok",
  "error": [],
  "method": "delete",
  "result": []
}

POST /search

Searches for a similar image in the database. Scores range from 0 to 100, with 100 being a perfect match.

Parameters

Example Response

{
  "status": "ok",
  "error": [],
  "method": "search",
  "result": [
    {
      "score": 99.0,
      "filepath": "http://static.wixstatic.com/media/0149b5_345c8f862e914a80bcfcc98fcd432e97.jpg_srz_614_709_85_22_0.50_1.20_0.00_jpg_srz"
    }
  ]
}

POST /compare

Compares two images, returning a score for their similarity. Scores range from 0 to 100, with 100 being a perfect match.

Parameters

Example Response

{
  "status": "ok",
  "error": [],
  "method": "compare",
  "result": [
    {
      "score": 99.0
    }
  ]
}

GET /count

Count the number of image signatures in the database.

Example Response

{
  "status": "ok",
  "error": [],
  "method": "list",
  "result": [420]
}

GET /list

Lists the file paths for the image signatures in the database.

Parameters

Example Response

{
  "status": "ok",
  "error": [],
  "method": "list",
  "result": [
    "http://img.youtube.com/vi/iqPqylKy-bY/0.jpg",
    "https://i.ytimg.com/vi/zbjIwBggt2k/hqdefault.jpg",
    "https://s-media-cache-ak0.pinimg.com/736x/3d/67/6d/3d676d3f7f3031c9fd91c10b17d56afe.jpg"
  ]
}

GET /ping

Check for the health of the server.

Example Response

{
  "status": "ok",
  "error": [],
  "method": "ping",
  "result": []
}

Development

$ export ELASTICSEARCH_URL=https://daisy.us-west-1.es.amazonaws.com
$ make build
$ make run
$ make push

License and Acknowledgements

Match is based on ascribe/image-match, which is in turn based on the paper An image signature for any kind of image, Goldberg et al. There is an existing reference implementation which may be more suited to your needs.

Match itself is released under the BSD 3-Clause license. ascribe/image-match is released under the Apache 2.0 license.