转: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.");
}
}
使用 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);
}
}
}
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的使用的更多相关文章
- 转:LIRe 源代码分析
1:整体结构 LIRE(Lucene Image REtrieval)提供一种的简单方式来创建基于图像特性的Lucene索引.利用该索引就能够构建一个基于内容的图像检索(content- based ...
- LIRe提供的图像检索算法的速度
本文翻译了LIRe的作者Mathias Lux发表的论文<LIRe: Lucene Image Retrieval - An Extensible Java CBIR Library>.主 ...
- LIRe 源代码分析 7:算法类[以颜色布局为例]
===================================================== LIRe源代码分析系列文章列表: LIRe 源代码分析 1:整体结构 LIRe 源代码分析 ...
- LIRe 源代码分析 6:检索(ImageSearcher)[以颜色布局为例]
===================================================== LIRe源代码分析系列文章列表: LIRe 源代码分析 1:整体结构 LIRe 源代码分析 ...
- LIRe 源代码分析 5:提取特征向量[以颜色布局为例]
===================================================== LIRe源代码分析系列文章列表: LIRe 源代码分析 1:整体结构 LIRe 源代码分析 ...
- LIRe 源代码分析 4:建立索引(DocumentBuilder)[以颜色布局为例]
===================================================== LIRe源代码分析系列文章列表: LIRe 源代码分析 1:整体结构 LIRe 源代码分析 ...
- LIRe 源代码分析 3:基本接口(ImageSearcher)
===================================================== LIRe源代码分析系列文章列表: LIRe 源代码分析 1:整体结构 LIRe 源代码分析 ...
- LIRe 源代码分析 2:基本接口(DocumentBuilder)
===================================================== LIRe源代码分析系列文章列表: LIRe 源代码分析 1:整体结构 LIRe 源代码分析 ...
- LIRe 源代码分析 1:整体结构
===================================================== LIRe源代码分析系列文章列表: LIRe 源代码分析 1:整体结构 LIRe 源代码分析 ...
随机推荐
- select与poll函数介绍
select与poll函数介绍 在所有依从POSIX的平台上,select函数使我们可以执行I/O多路转接.传向select的参数告诉内核: 1)我们所关心的描述符 2)对于每个描述符我们所关心的状态 ...
- nginx 的基础配置[转]
nginx 的基础配置 分类: 工具软件2013-11-13 23:26 11人阅读 评论(0) 收藏 举报 目录(?)[-] 管理配置文件 全局配置 虚拟机server配置 location配置 ...
- MFC下无法为空间添加变量解决
许久不用MFC,今天在vs2008下用MFC写个小东西,结果在为控件添加变量的时候,居然无法成功——那个界面显示怪怪的,点击完成提示失败. 还好同事遇到过这个问题,给出链接http://hi.b ...
- WPF中ListBox的样式设置
设置之后的效果为
- Navicat for Oracle 连接oracle 配置
oci.dll 替换为对应oracle版本的oci.dll
- IOS 导航栏
系统状态栏改为白色:在Supporting Files文件的info.plist文件中添加 新的key,名字为View controller-based status bar appearance,并 ...
- session的使用方法
概念:session把客户资料存在服务器中,给浏览器一个加密凭证,每次登录生成的凭证都不相同,浏览器用cookie保存凭证.下次访问时服务器收到凭证后,打开文件读取session信息.session_ ...
- 团队作业week2
软件分析和用户需求调查 (2013) 具体内容参看邹欣老师的博客:http://www.cnblogs.com/xinz/p/3308608.html. 作业提交期限:2013年9月25日上课前.
- XmlSerializer 对象的Xml序列化和反序列化,XMLROOT别名设置
这篇随笔对应的.Net命名空间是System.Xml.Serialization:文中的示例代码需要引用这个命名空间. 为什么要做序列化和反序列化? .Net程序执行时,对象都驻留在内存中:内存中 ...
- C# 图片盖章功能实现,支持拖拽-旋转-放缩-保存
实现图片盖章功能,在图片上点击,增加“图章”小图片,可以拖拽“图章”到任意位置,也可以点击图章右下角园框,令图片跟着鼠标旋转和放缩. 操作方法:1.点击增加“图章”2.选中移动图标3.点中右下角放缩旋 ...