LIRE的使用:创建索引

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.");
}
}

LIRE的使用:搜索相似的图片

使用 ImageSearcherFactory 创建 ImageSearcher。例如ImageSearcherFactory.createDefaultSearcher()。

ImageSearcher 可以通过 InputStream 或BufferedImage,或者一个描述图像的Lucene的 Document 进行检索。例如使用search(BufferedImage, IndexReader) 或者search(Document, IndexReader).

返回的结果是一个 ImageSearchHits 类似于Lucene 中的Hits。

/**
* Simple image retrieval with Lire
* @author Mathias Lux, mathias <at> juggle <dot> at
*/
public class Searcher {
public static void main(String[] args) throws IOException {
// Checking if arg[0] is there and if it is an image.
BufferedImage img = null;
boolean passed = false;
if (args.length > 0) {
File f = new File(args[0]);
if (f.exists()) {
try {
img = ImageIO.read(f);
passed = true;
} catch (IOException e) {
e.printStackTrace();
}
}
}
if (!passed) {
System.out.println("No image given as first argument.");
System.out.println("Run \"Searcher <query image>\" to search for <query image>.");
System.exit(1);
} IndexReader ir = DirectoryReader.open(FSDirectory.open(new File("index")));
ImageSearcher searcher = ImageSearcherFactory.createCEDDImageSearcher(10); ImageSearchHits hits = searcher.search(img, ir);
for (int i = 0; i < hits.length(); i++) {
String fileName = hits.doc(i).getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0];
System.out.println(hits.score(i) + ": \t" + fileName);
}
}
}

LIRe提供的6种图像特征描述方法的评测

Rui Gan等人(看名字来说应该是中国人,机构写的Sun Yat-sen University应该是中山大学,但是很不幸没有找到相应的中文论文)在论文《Using LIRe to Implement Image Retrieval System Based on Multi-Feature Descriptor》中,测试了开源基于内容的图像检索类库LIRe的各种图像特征的性能。在此记录一下以作参考。

这里再提一下LIRe 的简介:LIRE(Lucene Image REtrieval)提供一种的简单方式来创建基于图像特性的Lucene索引。利用该索引就能够构建一个基于内容的图像检索(content- based image retrieval,CBIR)系统,来搜索相似的图像。LIRE使用的特性都取自MPEG-7标准: ScalableColor、ColorLayout、EdgeHistogram,目前已经支持其他更多的特性。此外该类库还提供一个搜索该索引的方 法。

本文测试了LIRe提供的以下6种特征描述方法:

实验以供选择了13个种类,一共100张图片做测试,这些图如下图所示(只是一部分):

测试的步骤不再多说,就是使用LIRe的6种特征描述方法分别建立6个索引,然后分别检索。最后得到的实验结果如图所示:

注:6种特征描述方法分别标以A,B,C,D,E,F,G。其中C为最常见的颜色直方图。

查准率(Precision)如下表所示。

查全率(Recall)如下表所示。

查全率和查准率合计如下表所示。

左边一栏对不同种类的图片分别给出了最适合的特征描述方法。

右边一栏对不同种类的图片分别给出了6种方法结合后的查全率和查准率。

转:LIRE的使用的更多相关文章

  1. 转:LIRe 源代码分析

    1:整体结构 LIRE(Lucene Image REtrieval)提供一种的简单方式来创建基于图像特性的Lucene索引.利用该索引就能够构建一个基于内容的图像检索(content- based ...

  2. LIRe提供的图像检索算法的速度

    本文翻译了LIRe的作者Mathias Lux发表的论文<LIRe: Lucene Image Retrieval - An Extensible Java CBIR Library>.主 ...

  3. LIRe 源代码分析 7:算法类[以颜色布局为例]

    ===================================================== LIRe源代码分析系列文章列表: LIRe 源代码分析 1:整体结构 LIRe 源代码分析 ...

  4. LIRe 源代码分析 6:检索(ImageSearcher)[以颜色布局为例]

    ===================================================== LIRe源代码分析系列文章列表: LIRe 源代码分析 1:整体结构 LIRe 源代码分析 ...

  5. LIRe 源代码分析 5:提取特征向量[以颜色布局为例]

    ===================================================== LIRe源代码分析系列文章列表: LIRe 源代码分析 1:整体结构 LIRe 源代码分析 ...

  6. LIRe 源代码分析 4:建立索引(DocumentBuilder)[以颜色布局为例]

    ===================================================== LIRe源代码分析系列文章列表: LIRe 源代码分析 1:整体结构 LIRe 源代码分析 ...

  7. LIRe 源代码分析 3:基本接口(ImageSearcher)

    ===================================================== LIRe源代码分析系列文章列表: LIRe 源代码分析 1:整体结构 LIRe 源代码分析 ...

  8. LIRe 源代码分析 2:基本接口(DocumentBuilder)

    ===================================================== LIRe源代码分析系列文章列表: LIRe 源代码分析 1:整体结构 LIRe 源代码分析 ...

  9. LIRe 源代码分析 1:整体结构

    ===================================================== LIRe源代码分析系列文章列表: LIRe 源代码分析 1:整体结构 LIRe 源代码分析 ...

随机推荐

  1. 数据库(表)的逻辑备份与恢复<四>

    数据库(表)的逻辑备份与恢复  介绍 逻辑备份是指使用工具 export 将数据对象的结构和数据导出到文件的过程,逻辑恢复是指当数据库对象被误操作而损坏后使用 工具 import 利用备份的文件把数 ...

  2. Odoo启动过程

    [本文基于odoo9源码编写] odoo包含的服务有 db object report workflow web[wsgi] Odoo以wsgi 规范提供Web及Web服务db/object/repo ...

  3. caffe 安装在win 7 vs2015 无gpu的安装方式-是无法安装 的

    网上多数是vs2012或者vs2013上安装方式,带NA-显卡的需要安装CUDA7.5,安装cuDNN4,cuDNN. 一 :下载caffe源码(microsoft版) 下载地址:https://gi ...

  4. cocos2d-x源码分析(1)

    class CC_DLL CCCopying { public: virtual CCObject* copyWithZone(CCZone* pZone); }; class CC_DLL CCZo ...

  5. UWP深入学习二:各种激活方式

    Launching, resuming, and multitasking How to launch an app for results Auto-launching with file and ...

  6. myeclipse2013以及以后的最新版各种破解(其实就是获取活跃码而已)

    当你下到最新版的myeclipse-blue的时候你是否会为注册激活而烦恼呢,别担心,其实激活也就那么点事儿,请遵循我如下做法就可以了: 免积分下载破解地址 http://download.csdn. ...

  7. Linux中vi、vim命令大全

    一.一般模式:删除.复制与粘贴类命令 x,X x为向后删除一个字符,X为先前删除一个字符 nx(n代表数字) 向后删除n个字符 dd 删除当前行 D 删除当前行所有字符,试成为空行 ndd(n代表数字 ...

  8. Oracle删除指定用户下所有对象

    --.sql脚本 --唯一注意的是下面的d:\dropuserobj.sql为操作的.sql; --用于删除当前用户的所有对象 --use for drop all objects in curren ...

  9. SQL Server 导入大数据脚本

    .先使用win+r运行cmd .执行osql -S DESKTOP-RGBEDS3 -U sa -P liyang -d FGCPOE_十院 -i D:\数据库\script.sql 即可!

  10. 【Leetcode】【Medium】word search

    Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from l ...