Lire - Lucene Image REtrieval 0.5.1 review
DownloadLire, the Lucene Image REtrieval library is a simple way to create a Lucene index of image features for content based image retrieval
|
|
Lire, the Lucene Image REtrieval library is a simple way to create a Lucene index of image features for content based image retrieval (CBIR).
The used features are taken from the MPEG-7 Standard: ScalableColor, ColorLayout and EdgeHistogram. Furthermore methods for searching the index are provided.
The LIRE library is part of the Caliph & Emir project and aims to provide the CBIR features of Caliph & Emir to other Java projects in an easy and light weight way.
Creating an Index
Use DocumentBuilderFactory to create a DocumentBuilder, which will create Lucene Documents from images. Add this documents to an index like this:
System.out.println(">> Indexing " + images.size() + " files.");
DocumentBuilder builder = DocumentBuilderFactory.getExtensiveDocumentBuilder();
IndexWriter iw = new IndexWriter(indexPath, new SimpleAnalyzer(), true);
int count = 0;
long time = System.currentTimeMillis();
for (String identifier : images) {
Document doc = builder.createDocument(new FileInputStream(identifier), identifier);
iw.addDocument(doc);
count ++;
if (count % 25 == 0) System.out.println(count + " files indexed.");
}
long timeTaken = (System.currentTimeMillis() - time);
float sec = ((float) timeTaken) / 1000f;
System.out.println(sec + " seconds taken, " + (timeTaken / count) + " ms per image.");
iw.optimize();
iw.close();
Searching in an Index
Use the ImageSearcherFactory for creating an ImageSearcher, which will retrieve the images for you from the index.
IndexReader reader = IndexReader.open(indexPath);
ImageSearcher searcher = ImageSearcherFactory.createDefaultSearcher();
FileInputStream imageStream = new FileInputStream("image.jpg");
BufferedImage bimg = ImageIO.read(imageStream);
// searching for an image:
ImageSearchHits hits = null;
hits = searcher.search(bimg, reader);
for (int i = 0; i < 5; i++) {
System.out.println(hits.score(i) + ": " + hits.doc(i).getField(DocumentBuilder.FIELD_NAME_IDENTIFIER).stringValue());
}
// searching for a document:
Document document = hits.doc(0);
hits = searcher.search(document, reader);
for (int i = 0; i < 5; i++) {
System.out.println(hits.score(i) + ": " + hits.doc(i).getField(DocumentBuilder.FIELD_NAME_IDENTIFIER).stringValue());
}
What's New in This Release:
Since Lire already supports Color histograms (with the MPEG-7 ScalableColor descriptor), functions for searching for colors have been integrated by by adding a searcher for color only search operations, a document builder restricted to color, and a document factory for fast and efficient creation of documents describing images with one color only.
Lire - Lucene Image REtrieval 0.5.1 keywords