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: ...
随机推荐
- Hexo 简明教程
概述 对于个人独立博客的搭建,或者一些产品网站的介绍我个人比较推崇直接用静态网站生成器来完成这个事情,对于,静态网页部署方便,浏览速度快. 以下为部分静态网站生成器简要列表: Ruby Jekyll ...
- 奥比中光Orbbec Astra Pro RGBD 3D视觉传感器在ROS(indigo和kinetic)使用说明 rgb depth同时显示
Orbbec Astra Pro传感器在ROS(indigo和kinetic)使用说明 rgb depth同时显示 这款摄像头使用uvc输入彩色信息,需要libuvc和libuvc_ros这样才能在R ...
- #pragma pack(x) CPU对齐
编译器会尽量把成员对齐以提高内存的命中率.对齐是可以更改的,使用"#pragma pack(x)" 可以改变编译器的对齐方式. C++固有类型的对界取编译器对齐方式与自身大小中较小 ...
- 手把手图文并茂教你发布Android开源库
转载请把头部出处链接和尾部二维码一起转载,本文出自逆流的鱼,文章链接: http://blog.csdn.net/hejjunlin/article/details/52452220 经常逛githu ...
- 巨星陨落 - Jim Gary
偶然在微软Research中搜论文时搜到了神牛Jim Gary的paper,看着照片有点眼熟,貌似在买过的哪本书中见过.于是就饶有兴致地看着Jim的生平介绍,结果- "Dr. Gray j ...
- mapdb的一些性能测试
jdk1.6,8g,64位,Intel Core i5-4210U CPU @ 1.70GHz 2.40GHz 使用memorydb 100个htreemap,每个htreemap对应50条线程操作, ...
- (一〇七)iPad开发之modal的切换方式与展示方式
在iPad上modal有四种切换方式,分别是竖直进入(由下到上,默认方式).水平翻转.淡入淡出. 属性要设置在将要modal出来的控制器上: /* typedef NS_ENUM(NSInteger, ...
- 【Unity技巧】LOGO闪光效果
写在前面 本文参考了风宇冲的博文,在按照这篇博文实现LOGO闪光时,发现了一些问题.最严重的就是背景无法透明,看上去背景始终是黑色的:其次就是各个变量的意义不是非常明确,调节起来不方便:而且在闪光条的 ...
- UNIX环境高级编程——pthread_create的问题
linux 下常用的创建多线程函数pthread_create(pthread_t * thread , pthread_attr_t * attr , void *(*start_routine)( ...
- Ubuntu文件中文乱码
如图,该文件在gedit打开中文显示正常 在命令行中用vim打开,显示内容如下: 使用命令进行编码转换 iconv -f gbk -t utf8 ./SogouQ.mini > ./sougou ...