zz from: http://hi.baidu.com/johnsoncr/blog/item/953d9f95f9aab9057af48078.html
LIRE(Lucene Image REtrieval)提供一种的简单方式来创建基于图像特性的Lucene索引。利用该索引就能够构建一个基于内容的图像检索(content- based image retrieval,CBIR)系统,来搜索相似的图像。LIRE使用的特性都取自MPEG-7标准: ScalableColor、ColorLayout、EdgeHistogram。此外该类库还提供一个搜索该索引的方法。
官方网址:http://www.semanticmetadata.net/lire/
文档 网址:www.semanticmetadata.net/wiki/doku.php
Creating an Index with Lire
Use the DocumentBuilderFactory
to create a DocumentBuilder
, for instance withDocumentBuilderFactory.getExtensiveDocumentBuilder()
. Add images to an index using following steps:
-
With this
DocumentBuilder
Lucene documents can be created from images, for instance withbuilder.createDocument(FileInputStream, String)
. -
Eventually enrich the documents with your own data.
-
Add the document to an index.
For a really big index use .getFastDocumentBuilder()
method from DocumentBuilderFactory
, otherwise the.getDefaultDocumentBuilder()
or the .getExtensiveDocumentBuilder()
. Following MPEG-7 descriptors are used by the different DocumentBuilders:
-
Fast: ColorLayout
-
Default: ColorLayout and EdgeHistogram
-
Extensive: ColorLayout, EdgeHistogram and ScalableColor
For more information please consult the Java API Doc. Sample code is available in the sources, take a look at the JUnit test classes.
Sample Code
Note that the way of opening an index with the IndexReader and IndexWriter of Lucene has changed with Lucene 3.0. I assume to use LIRe v0.8, which already supports Lucene 3.0.1
Searching with Lire
Use the ImageSearcherFactory
for creating an ImageSearcher
, which will retrieve the images from the index. This can be done by calling ImageSearcherFactory.createDefaultSearcher()
. The ImageSearcher
will query for an image, given by an InputStream
or a BufferedImage
, or a Lucene Document
describing an image, for instance with the method search(BufferedImage, IndexReader)
or search(Document, IndexReader)
.
Please note that the ImageSearcher
uses a Lucene IndexReader
and does the retrieval with a linear search in the index. The results are returned as ImageSearchHits
object, which aims to simulate a Lucene Hits
object.
Note also that the IndexSearcher
only uses image features, which are available in the specific Document
in the index. If documents only have been indexed with the fast DocumentBuilder
there is no ColorHistogram or EdgeHistogram feature available in the indexed documents, only the ColorLayout feature.
Searching with Weights
Within the ImageSearcherFactory
one can use the method createWeightedSearcher(int maximumHits, float colorHistogramWeight, float colorDistributionWeight, float textureWeight)
to adjust the weights for searching. Note that the extensive DocumentBuilder
has to be used to build the index to discover the full potential of weighting.
Also note that only weights in [0,1]
are allowed and the sum of the weights has to be greater than 0.
Sample Code for a Simple Search Implementation