LIRe 源代码分析 4:建立索引(DocumentBuilder)[以颜色布局为例]
=====================================================
LIRe源代码分析系列文章列表:
LIRe 源代码分析 2:基本接口(DocumentBuilder)
LIRe 源代码分析 3:基本接口(ImageSearcher)
LIRe 源代码分析 4:建立索引(DocumentBuilder)[以颜色布局为例]
LIRe 源代码分析 6:检索(ImageSearcher)[以颜色布局为例]
=====================================================
前几篇文章介绍了LIRe 的基本接口。现在来看一看它的实现部分,本文先来看一看建立索引((DocumentBuilder))部分。不同的特征向量提取方法的建立索引的类各不相同,它们都位于“net.semanticmetadata.lire.impl”中,如下图所示:
由图可见,每一种方法对应一个DocumentBuilder和一个ImageSearcher,类的数量非常的多,无法一一分析。在这里仅分析一个比较有代表性的:颜色布局。
颜色直方图建立索引的类的名称是ColorLayoutDocumentBuilder,该类继承了AbstractDocumentBuilder,它的源代码如下所示:
/*
* This file is part of the LIRe project: http://www.semanticmetadata.net/lire
* LIRe is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* LIRe is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LIRe; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* We kindly ask you to refer the following paper in any publication mentioning Lire:
*
* Lux Mathias, Savvas A. Chatzichristofis. Lire: Lucene Image Retrieval 鈥�
* An Extensible Java CBIR Library. In proceedings of the 16th ACM International
* Conference on Multimedia, pp. 1085-1088, Vancouver, Canada, 2008
*
* http://doi.acm.org/10.1145/1459359.1459577
*
* Copyright statement:
* --------------------
* (c) 2002-2011 by Mathias Lux (mathias@juggle.at)
* http://www.semanticmetadata.net/lire
*/
package net.semanticmetadata.lire.impl;
import net.semanticmetadata.lire.AbstractDocumentBuilder;
import net.semanticmetadata.lire.DocumentBuilder;
import net.semanticmetadata.lire.imageanalysis.ColorLayout;
import net.semanticmetadata.lire.utils.ImageUtils;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import java.awt.image.BufferedImage;
import java.util.logging.Logger;
/**
* Provides a faster way of searching based on byte arrays instead of Strings. The method
* {@link net.semanticmetadata.lire.imageanalysis.ColorLayout#getByteArrayRepresentation()} is used
* to generate the signature of the descriptor much faster.
* User: Mathias Lux, mathias@juggle.at
* Date: 30.06.2011
*/
public class ColorLayoutDocumentBuilder extends AbstractDocumentBuilder {
private Logger logger = Logger.getLogger(getClass().getName());
public static final int MAX_IMAGE_DIMENSION = 1024;
public Document createDocument(BufferedImage image, String identifier) {
assert (image != null);
BufferedImage bimg = image;
// Scaling image is especially with the correlogram features very important!
// All images are scaled to guarantee a certain upper limit for indexing.
if (Math.max(image.getHeight(), image.getWidth()) > MAX_IMAGE_DIMENSION) {
bimg = ImageUtils.scaleImage(image, MAX_IMAGE_DIMENSION);
}
Document doc = null;
logger.finer("Starting extraction from image [ColorLayout - fast].");
ColorLayout vd = new ColorLayout();
vd.extract(bimg);
logger.fine("Extraction finished [ColorLayout - fast].");
doc = new Document();
doc.add(new Field(DocumentBuilder.FIELD_NAME_COLORLAYOUT_FAST, vd.getByteArrayRepresentation()));
if (identifier != null)
doc.add(new Field(DocumentBuilder.FIELD_NAME_IDENTIFIER, identifier, Field.Store.YES, Field.Index.NOT_ANALYZED));
return doc;
}
}
从源代码来看,其实主要就一个函数:createDocument(BufferedImage image, String identifier),该函数的流程如下所示:
1.如果输入的图像分辨率过大(在这里是大于1024),则将图像缩小。
2.新建一个ColorLayout类型的对象vd。
3.调用vd.extract()提取特征向量。
4.调用vd.getByteArrayRepresentation()获得特征向量。
5.将获得的特征向量加入Document,返回Document。
其实其他方法的DocumentBuilder的实现和颜色直方图的DocumentBuilder差不多。例如CEDDDocumentBuilder的源代码如下所示:
/*
* This file is part of the LIRe project: http://www.semanticmetadata.net/lire
* LIRe is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* LIRe is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LIRe; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* We kindly ask you to refer the following paper in any publication mentioning Lire:
*
* Lux Mathias, Savvas A. Chatzichristofis. Lire: Lucene Image Retrieval 鈥�
* An Extensible Java CBIR Library. In proceedings of the 16th ACM International
* Conference on Multimedia, pp. 1085-1088, Vancouver, Canada, 2008
*
* http://doi.acm.org/10.1145/1459359.1459577
*
* Copyright statement:
* ~~~~~~~~~~~~~~~~~~~~
* (c) 2002-2011 by Mathias Lux (mathias@juggle.at)
* http://www.semanticmetadata.net/lire
*/
package net.semanticmetadata.lire.impl;
import net.semanticmetadata.lire.AbstractDocumentBuilder;
import net.semanticmetadata.lire.DocumentBuilder;
import net.semanticmetadata.lire.imageanalysis.CEDD;
import net.semanticmetadata.lire.utils.ImageUtils;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import java.awt.image.BufferedImage;
import java.util.logging.Logger;
/**
* Provides a faster way of searching based on byte arrays instead of Strings. The method
* {@link net.semanticmetadata.lire.imageanalysis.CEDD#getByteArrayRepresentation()} is used
* to generate the signature of the descriptor much faster.
* User: Mathias Lux, mathias@juggle.at
* Date: 12.03.2010
* Time: 13:21:35
*
* @see GenericFastDocumentBuilder
* @deprecated use GenericFastDocumentBuilder instead.
*/
public class CEDDDocumentBuilder extends AbstractDocumentBuilder {
private Logger logger = Logger.getLogger(getClass().getName());
public static final int MAX_IMAGE_DIMENSION = 1024;
public Document createDocument(BufferedImage image, String identifier) {
assert (image != null);
BufferedImage bimg = image;
// Scaling image is especially with the correlogram features very important!
// All images are scaled to guarantee a certain upper limit for indexing.
if (Math.max(image.getHeight(), image.getWidth()) > MAX_IMAGE_DIMENSION) {
bimg = ImageUtils.scaleImage(image, MAX_IMAGE_DIMENSION);
}
Document doc = null;
logger.finer("Starting extraction from image [CEDD - fast].");
CEDD vd = new CEDD();
vd.extract(bimg);
logger.fine("Extraction finished [CEDD - fast].");
doc = new Document();
doc.add(new Field(DocumentBuilder.FIELD_NAME_CEDD, vd.getByteArrayRepresentation()));
if (identifier != null)
doc.add(new Field(DocumentBuilder.FIELD_NAME_IDENTIFIER, identifier, Field.Store.YES, Field.Index.NOT_ANALYZED));
return doc;
}
}
LIRe 源代码分析 4:建立索引(DocumentBuilder)[以颜色布局为例]的更多相关文章
- LIRe 源代码分析 5:提取特征向量[以颜色布局为例]
===================================================== LIRe源代码分析系列文章列表: LIRe 源代码分析 1:整体结构 LIRe 源代码分析 ...
- LIRe 源代码分析 2:基本接口(DocumentBuilder)
===================================================== LIRe源代码分析系列文章列表: LIRe 源代码分析 1:整体结构 LIRe 源代码分析 ...
- LIRe 源代码分析 7:算法类[以颜色布局为例]
===================================================== LIRe源代码分析系列文章列表: LIRe 源代码分析 1:整体结构 LIRe 源代码分析 ...
- LIRe 源代码分析 6:检索(ImageSearcher)[以颜色布局为例]
===================================================== LIRe源代码分析系列文章列表: LIRe 源代码分析 1:整体结构 LIRe 源代码分析 ...
- LIRe 源代码分析 3:基本接口(ImageSearcher)
===================================================== LIRe源代码分析系列文章列表: LIRe 源代码分析 1:整体结构 LIRe 源代码分析 ...
- LIRe 源代码分析 1:整体结构
===================================================== LIRe源代码分析系列文章列表: LIRe 源代码分析 1:整体结构 LIRe 源代码分析 ...
- 转:LIRe 源代码分析
1:整体结构 LIRE(Lucene Image REtrieval)提供一种的简单方式来创建基于图像特性的Lucene索引.利用该索引就能够构建一个基于内容的图像检索(content- based ...
- Lucene建立索引搜索入门实例
第一部分:Lucene建立索引 Lucene建立索引主要有以下两步:第一步:建立索引器第二步:添加索引文件准备在f盘建立lucene文件夹,然后 ...
- RTMPdump(libRTMP) 源代码分析 7: 建立一个流媒体连接 (NetStream部分 2)
===================================================== RTMPdump(libRTMP) 源代码分析系列文章: RTMPdump 源代码分析 1: ...
随机推荐
- Android 多窗口详解
多窗口支持 Android N 添加了对同时显示多个应用窗口的支持. 在手持设备上,两个应用可以在"分屏"模式中左右并排或上下并排显示. 在电视设备上,应用可以使用"画中 ...
- 学习TensorFlow,保存学习到的网络结构参数并调用
在深度学习中,不管使用那种学习框架,我们会遇到一个很重要的问题,那就是在训练完之后,如何存储学习到的深度网络的参数?在测试时,如何调用这些网络参数?针对这两个问题,本篇博文主要探索TensorFlow ...
- 剑指Offer——乐视笔试题+知识点总结
剑指Offer--乐视笔试题+知识点总结 情景回顾 时间:2016.9.19 15:10-17:10 地点:山东省网络环境智能计算技术重点实验室 事件:乐视笔试 总体来说,乐视笔试内容体量不算少, ...
- cocos2d-x 3.11 游戏开发环境搭建流程
cocos2d-x 3.11.1 游戏开发环境搭建流程 1. 准备下面的软件 1) Windows7 64Bit+ VS2013 (VC++) 这个不用多说. 2) cocos2d-x-3.11.1. ...
- UNIX网络编程——常用服务器模型总结
下面有9种服务器模型分别是: 迭代服务器. 并发服务器,为每个客户fork一个进程. 预先派生子进程,每个子进程都调用accept,accept无上锁保护. 预先派生子进程,以文件锁的方式保护acce ...
- Dynamics CRM 2015 站点地图公告配置实体显示名称的变更
CRM更新2015后,在设置里找不到公告配置了 在原来的位置上你会东西一个叫活动源配置的东西,点开看后就是原来的公告配置.
- J2EE进阶(五)Spring在web.xml中的配置
J2EE进阶(五)Spring在web.xml中的配置 前言 在实际项目中spring的配置文件applicationcontext.xml是通过spring提供的加载机制自动加载到容器中.在web ...
- 关于"net::ERR_CONNECTION_ABORTED"和"Firebug 达到了 Post 请求大小限制"的问题
1.其中"net::ERR_CONNECTION_ABORTED"是在Chrome的控制台中打印出来的. 2."Firebug 达到了 Post 请求大小限制" ...
- Ubuntu15.10下制作Linux 操作系统优盘启动盘
上次电脑出现了一些问题,于是不得不重新装机了.下面就跟大家分享一下我在Ubuntu下制作优盘启动盘的一些心得. 准备原料 我这里用到的是 镜像文件是:debian-8.3.0-amd64-DVD-2. ...
- Cookie 进阶
Cookie作为一个客户端技术被广泛的应用着.我今天也来谈一谈我对Cookie的理解. 先来一个小菜(实现"上次登录时间") 具体的思路如下: 通过request.getCooki ...