LIRE(Lucene Image REtrieval)提供一种的简单方式来创建基于图像特性的Lucene索引。利用该索引就能够构建一个基于内容的图像检索(content- based image retrieval,CBIR)系统,来搜索相似的图像。LIRE使用的特性都取自MPEG-7标准: ScalableColor、ColorLayout、EdgeHistogram。
使用DocumentBuilderFactory
创建 DocumentBuilder
,例如DocumentBuilderFactory.getCEDDDocumentBuilder()
.
将图片加入索引index 需要以下2步:
-
使用
DocumentBuilder
创建Document:builder.createDocument(FileInputStream, String)
.(第一个参数是图片文件) -
将document 加入 index.
LIRE支持很多种的特征值。具体可以看 DocumentBuilderFactory
类的源代码。也可以使用 ChainedDocumentBuilder
同时使用多种特征值。
创建索引的方法如下代码所示
/** * Simple index creation with Lire * * @author Mathias Lux, mathias@juggle.at */ public class Indexer { public static void main(String[] args) throws IOException { // Checking if arg[0] is there and if it is a directory. boolean passed = false; if (args.length > 0) { File f = new File(args[0]); System.out.println("Indexing images in " + args[0]); if (f.exists() && f.isDirectory()) passed = true; } if (!passed) { System.out.println("No directory given as first argument."); System.out.println("Run \"Indexer <directory>\" to index files of a directory."); System.exit(1); } // Getting all images from a directory and its sub directories. ArrayList<String> images = FileUtils.getAllImages(new File(args[0]), true); // Creating a CEDD document builder and indexing al files. DocumentBuilder builder = DocumentBuilderFactory.getCEDDDocumentBuilder(); // Creating an Lucene IndexWriter IndexWriterConfig conf = new IndexWriterConfig(LuceneUtils.LUCENE_VERSION, new WhitespaceAnalyzer(LuceneUtils.LUCENE_VERSION)); IndexWriter iw = new IndexWriter(FSDirectory.open(new File("index")), conf); // Iterating through images building the low level features for (Iterator<String> it = images.iterator(); it.hasNext(); ) { String imageFilePath = it.next(); System.out.println("Indexing " + imageFilePath); try { BufferedImage img = ImageIO.read(new FileInputStream(imageFilePath)); Document document = builder.createDocument(img, imageFilePath); iw.addDocument(document); } catch (Exception e) { System.err.println("Error reading image or indexing it."); e.printStackTrace(); } } // closing the IndexWriter iw.close(); System.out.println("Finished indexing."); } }
原文:
http://www.semanticmetadata.net/wiki/doku.php?id=lire:createindex
相关推荐
- **创建索引**:使用`FSDirectory`和`IndexWriter`将图像特征写入Lucene索引。 - **查询**:通过`Searcher`类执行相似性搜索,返回最相似的图像。 ### 3. 应用场景 Lire适用于各种需要图像检索的场合,包括: -...
这个样例展示了如何利用Lire工具进行图像搜索,主要分为两个步骤:创建索引(indexing)和相似度比对(searching)。下面将详细解释这两个过程以及Lire库的工作原理。 **1. Lire库简介** Lire是基于Apache Lucene...
mysqlLIRE(Lucene Image REtrieval)是一个强大的工具,它简化了基于图像特征的Lucene索引的创建过程。该程序利用MPEG-7标准中的ScalableColor、ColorLayout和EdgeHistogram等特性,为图像内容的检索提供了高效而...
在这个项目中,我们将深入探讨如何使用Java中的LIRE库来创建一个基于Lucene的检索索引,从而实现CBIR功能。LIRE(Lucene for Image REtrieval)是一个开源库,它扩展了Apache Lucene的功能,使其能够处理和检索图像...
在给出的代码示例中,`createIndex`方法演示了如何使用LIRE创建索引。首先,通过`DocumentBuilderFactory`获取适当的`DocumentBuilder`,然后配置`IndexWriterConfig`和`Analyzer`。接着,遍历要索引的图像文件,...
在压缩包文件`lireTest`中,可能包含了一个演示程序,展示了如何使用LIRE库进行图像检索的完整流程,包括如何初始化`indexer`,如何构建索引,如何创建`searcher`,以及如何进行相似度查询。通常,这个程序会包含...
5. **查询与检索**:使用查询图像的特征进行相似性搜索,获取相似图像的列表。 在“image-similarity-with-lire-master”这个项目中,包含了使用LIRE库进行图像相似度比较的源代码。开发者可以通过阅读和运行这些...
以下是一个简单的示例代码,展示了如何使用Lire创建索引: ```java import net.semanticmetadata.lire.imageanalysis.LireFeature; import net.semanticmetadata.lire.imageanalysis.feature.AverageColor; import ...
LIRE(Lucene Image REtrieval)提供一种的简单方式来创建基于图像特性的Lucene索引。利用该索引就能够构建一个基于内容的图像检索(content- based image retrieval,CBIR)系统,来搜索相似的图像。LIRE使用的特性都...
LIRE(Lucene Image REtrieval)提供一种的简单方式来创建基于图像特性的Lucene索引。利用该索引就能够构建一个基于内容的图像检索(content- based image retrieval,CBIR)系统,来搜索相似的图像。LIRE使用的特性都...
LIRE(Lucene Image REtrieval)提供一种的简单方式来创建基于图像特性的Lucene索引。LIRE使用的特性都取自MPEG-7标准: ScalableColor、ColorLayout、EdgeHistogram。 这是一个完整的例子程序。
- **特征提取**:使用LIRE库从每张图像中提取关键点和描述符。 - **索引构建**:将提取的特征编码并建立倒排索引。 - **查询处理**:接收查询图像,同样提取特征并编码,然后在索引中进行搜索。 - **结果展示**:...
LIRE(Lucene Image REtrieval)提供一种的简单方式来创建基于图像特性的Lucene索引。利用该索引就能够构建一个基于内容的图像检索(content- based image retrieval,CBIR)系统,来搜索相似的图像,提取图像特征,...
4. 创建索引:使用Lucene创建一个包含图像特征的索引。 5. 查询执行:用户输入一个查询图像,系统通过LIRE和Lucene找出相似图像。 6. 结果展示:返回并显示最相似的图像列表。 在这个过程中,学生可能会学习到如何...
5. **索引编写器(IndexWriter)**:用于创建和更新索引,将文档添加到索引中。开发者可以通过 IndexWriter 控制索引的更新策略。 6. **查询解析器(QueryParser)**:将用户输入的查询字符串转化为 Lucene 可理解...
5. 运行示例代码,创建图像索引并进行搜索。 在实际应用中,你可以根据需求调整Lire提供的各种参数,例如特征提取器类型、特征向量的维度等,以优化搜索性能。同时,LireDemo也可以作为一个学习平台,帮助开发者...
"lire-0.9.3.jar"是LIRE(Lucene Image REtrieval)库,它是专门为图像检索扩展Apache Lucene而设计的,提供了多种图像特征的提取和编码方法。"jdom-2.0.6.jar"则是用于处理XML文档的Java库,可能用于存储和读取用户...