Code Monkey home page Code Monkey logo

elasticsearch-image's Introduction

Image Plugin for Elasticsearch

Build Status

The Image Plugin is an Content Based Image Retrieval Plugin for Elasticsearch using LIRE (Lucene Image Retrieval). It allows users to index images and search for similar images.

It adds an image field type and an image query

See http://demo.elasticsearch-image.com for a demo of the plugin

In order to install the plugin, simply run: bin/plugin install https://github.com/shi-yuan/elasticsearch-image/releases/download/v2.3.1/elasticsearch-image-2.3.1.0.zip.

Image Plugin elasticsearch Release date
2.3.1.0 (master) 2.3.1 2018-03-12
1.3.0-SNAPSHOT 1.1.0
1.2.0 1.0.1 2014-03-20
1.1.0 1.0.1 2014-03-13
1.0.0 1.0.1 2014-03-05

Example

Create Mapping

curl -XPUT 'localhost:9200/test/test/_mapping' -d '{
    "test": {
        "properties": {
            "my_img": {
                "type": "image",
                "feature": {
                    "CEDD": {
                        "hash": "BIT_SAMPLING"
                    },
                    "JCD": {
                        "hash": ["BIT_SAMPLING", "LSH"]
                    },
                    "FCTH": {}
                },
                "metadata": {
                    "jpeg.image_width": {
                        "type": "string",
                        "store": "yes"
                    },
                    "jpeg.image_height": {
                        "type": "string",
                        "store": "yes"
                    }
                }
            }
        }
    }
}'

type should be image. Mandatory

feature is a map of features for index. Mandatory, at least one is required

hash can be set if you want to search on hash. Optional

metadata is a map of metadata for index, only those metadata will be indexed. See Metadata. Optional

Index Image

curl -XPOST 'localhost:9200/test/test' -d '{
    "my_img": "... base64 encoded image ..."
}'

Search Image

curl -XPOST 'localhost:9200/test/test/_search' -d '{
    "query": {
        "image": {
            "my_img": {
                "feature": "CEDD",
                "image": "... base64 encoded image to search ...",
                "hash": "BIT_SAMPLING",
                "boost": 2.1,
                "limit": 100
            }
        }
    }
}'

feature should be one of the features in the mapping. Mandatory

image base64 of image to search. Optional if search using existing image

hash should be same to the hash set in mapping. Optional

limit limit the number of results returned (per shard) for scoring. Optional, only works when hash is specified

boost score boost Optional

Search Image using existing image in index

curl -XPOST 'localhost:9200/test/test/_search' -d '{
    "query": {
        "image": {
            "my_img": {
                "feature": "CEDD",
                "index": "test",
                "type": "test",
                "id": "image1",
                "path": "my_image",
                "hash": "BIT_SAMPLING"
            }
        }
    }
}'

index the index to fetch image from. Default to current index. Optional

type the type to fetch image from. Mandatory

id the id of the document to fetch image from. Mandatory

path the field specified as path to fetch image from. Mandatory

routing a custom routing value to be used when retrieving the external image doc. Optional

ImageQueryBuilder

byte[] bytes;
try (BytesStreamOutput os = new BytesStreamOutput()) {
    ImageIO.write(ImageIO.read(file), formatName, os);
    bytes = os.bytes().toBytes();
}

ImageQueryBuilder query = new ImageQueryBuilder("img");  //image field
query.image(bytes);
query.feature(feature);
query.hash(hash);
query.boost(boost);
query.limit(limit);
query.lookupIndex(INDEX);
query.lookupType(TYPE);
query.lookupId(itemId);	
query.lookupPath(path);
query.lookupRouting(routing);

SearchRequestBuilder queryBuilder = searchClient.prepareSearch(INDEX).setTypes(TYPE)
    .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
    .setQuery(query)
    .setFrom(from)
    .setSize(size);

Metadata

Metadata are extracted using metadata-extractor. See SampleOutput for some examples of metadata.

The field name in index will be directory.tag_name, all lower case and space becomes underscore(_). e.g. if the Directory is JPEG and Tag Name is Image Height, the field name will be jpeg.image_height

Supported Image Formats

Images are processed by Java ImageIO, supported formats can be found here

Additional formats can be supported by ImageIO plugins, for example TwelveMonkeys

Supported Features

AUTO_COLOR_CORRELOGRAM, BINARY_PATTERNS_PYRAMID, CEDD, SIMPLE_COLOR_HISTOGRAM, COLOR_LAYOUT, EDGE_HISTOGRAM, FCTH, GABOR, JCD, JOINT_HISTOGRAM, JPEG_COEFFICIENT_HISTOGRAM, LOCAL_BINARY_PATTERNS, LUMINANCE_LAYOUT, OPPONENT_HISTOGRAM, PHOG, ROTATION_INVARIANT_LOCAL_BINARY_PATTERNS, SCALABLE_COLOR, TAMURA

Supported Hash Mode

BIT_SAMPLING, LSH

Hash will increase search speed with large data sets

See Large image data sets with LIRE ?some new numbers

Settings

Setting Description Default
index.image.use_thread_pool use multiple thread when multiple features are required True
index.image.ignore_metadata_error ignore errors happened during extract metadata from image True

ChangeLog

2.3.1.0 (2018-03-12)

  • upgrade to 2.3.1.0

1.2.0 (2014-03-20)

  • Use multi-thread when multiple features are required to improve index speed
  • Allow index metadata
  • Allow query by existing image in index

1.1.0 (2014-03-13)

  • Added limit in image query
  • Added plugin version in es-plugin.properties

1.0.0 (2014-03-05)

  • initial release

elasticsearch-image's People

Contributors

kzwang avatar shi-yuan avatar

Stargazers

 avatar

Watchers

 avatar

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.