LIRE源代码分析 3:整体结构

一、LIRE 检索框架

在图像检索的实际应用开发中,由于图像包含的信息很多,直接利用原始的图像像素信息进行检索其运算量非常大,但是可以利用一些从图像中抽取出的特征来表征一幅图像的内容,而这些特征是由有限字符构成字符数组,因此可以利用全文检索技术来实现图像的检索。LIRE (Lucene Image REtrieval)就是基于Lucene全文索引工具包开发的开源Java类库。
LIRE框架分为两大部分:索引生成部分(即特征库生成部分)和利用输入图像提取出的特征检索出相同或相似的库图像。创建索引的过程就是先提取图像特征,将这些图像特
征视为文本,利用Lucene全文索引来建立特征的索引,创建索引的过程主要包括建立待索引的图像文件目录,将文件目录中的图像读入,然后利用Document Builder Factory
类获取要创建的索引类型,利用Index Writer Config配置LUCENE版本,最后提取特征并将特征写入索引文件中。在LIRE中,特征是以直方图的形式来表征图像,即LIRE索引文件中保存了直方图特征,同时还保存了图像名称、路径等图像信息。在实现图像检索时先要读取本地创建的索引文件,然后创建图像的特征实例,最后进行搜索匹配。LIRE检索图像的过程如下图所示,对查询图像采用相同的特征提取方法,然后再到特征库中利用相似性度量方法匹配查找最相似的特征,最后可以映射到最相似的图像。

LIRE源代码分析 3:整体结构_第1张图片

LIRE 中实现的特征方法大多符合 MPEG 标准的方法,在 LIRE 中主要实现的图像特征有:
1)HSV 和 RGB 颜色直方图;
2)MPEG-7 标准相关的颜色特征,可以是可变长颜色、颜色布局;
3)Tamura 相关纹理特征,包括对比度,粗糙度和方向性;
4)Gabor 纹理特征;
5)JPEG 系数直方图;
6)色彩与边缘方向性的描述符;
7)分层梯度方向直方图;
8)尺度不变特征变换;
9)模糊颜色与纹理直方图。
利用 LIRE 可以很方便地创建图像特征索引并利用该索引便捷地搜索相似的图像,同时也可以向 LIRE 中添加新的特征,实现特征的扩展与修改。

二、LIRE源码分析

通过前面的介绍我们知道Lire的基本接口主要完成两项工作,生成索引和进行检索。生成索引就是根据图片提取特征向量,然后存储特征向量到索引的过程。检索就是根据输入图片的特征向量到索引中查找相似图片的过程。

一、DocumentBuilder:用于生成索引

DocumentBuilder对象由DocumentBuilderFactory工厂类创建,DocumentBuilderFactory源码如下

package net.semanticmetadata.lire;

import net.semanticmetadata.lire.imageanalysis.*;
import net.semanticmetadata.lire.impl.ChainedDocumentBuilder;
import net.semanticmetadata.lire.impl.CorrelogramDocumentBuilder;
import net.semanticmetadata.lire.impl.GenericDocumentBuilder;
import net.semanticmetadata.lire.impl.GenericFastDocumentBuilder;

/**
 * Use DocumentBuilderFactory to create a DocumentBuilder, which
 * will create Lucene Documents from images.  
* This file is part of the Caliph and Emir project: http://www.SemanticMetadata.net *
Date: 31.01.2006 *
Time: 23:00:32 * * @author Mathias Lux, [email protected] */ public class DocumentBuilderFactory { /** * Creates a simple version of a DocumentBuilder. In this case the * {@link net.semanticmetadata.lire.imageanalysis.CEDD} is used as a feature * * @return a simple and efficient DocumentBuilder. * @see net.semanticmetadata.lire.imageanalysis.CEDD */ public static DocumentBuilder getDefaultDocumentBuilder() { return new GenericFastDocumentBuilder(CEDD.class, DocumentBuilder.FIELD_NAME_CEDD); } /** * Creates a simple version of a DocumentBuilder using the MPEG/-7 visual features features * all available descriptors are used. * * @return a fully featured DocumentBuilder. * @see net.semanticmetadata.lire.imageanalysis.ColorLayout * @see net.semanticmetadata.lire.imageanalysis.EdgeHistogram * @see net.semanticmetadata.lire.imageanalysis.ScalableColor * @deprecated Use ChainedDocumentBuilder instead */ public static DocumentBuilder getExtensiveDocumentBuilder() { ChainedDocumentBuilder cb = new ChainedDocumentBuilder(); cb.addBuilder(DocumentBuilderFactory.getColorLayoutBuilder()); cb.addBuilder(DocumentBuilderFactory.getEdgeHistogramBuilder()); cb.addBuilder(DocumentBuilderFactory.getScalableColorBuilder()); return cb; } /** * Creates a fast (byte[] based) version of the MPEG-7 ColorLayout document builder. * * @return the document builder. */ public static DocumentBuilder getColorLayoutBuilder() { return new GenericFastDocumentBuilder(ColorLayout.class, DocumentBuilder.FIELD_NAME_COLORLAYOUT); } /** * Creates a fast (byte[] based) version of the MPEG-7 EdgeHistogram document builder. * * @return the document builder. */ public static DocumentBuilder getEdgeHistogramBuilder() { return new GenericFastDocumentBuilder(EdgeHistogram.class, DocumentBuilder.FIELD_NAME_EDGEHISTOGRAM); } /** * Creates a fast (byte[] based) version of the MPEG-7 ColorLayout document builder. * * @return the document builder. */ public static DocumentBuilder getScalableColorBuilder() { return new GenericFastDocumentBuilder(ScalableColor.class, DocumentBuilder.FIELD_NAME_SCALABLECOLOR); } /** * Creates a simple version of a DocumentBuilder using ScalableColor. * * @return a fully featured DocumentBuilder. * @see net.semanticmetadata.lire.imageanalysis.ScalableColor * @deprecated Use ColorHistogram and the respective factory methods to get it instead */ public static DocumentBuilder getColorOnlyDocumentBuilder() { return DocumentBuilderFactory.getScalableColorBuilder(); } /** * Creates a simple version of a DocumentBuilder using the ColorLayout feature. Don't use this method any more but * use the respective feature bound method instead. * * @return a simple and fast DocumentBuilder. * @see net.semanticmetadata.lire.imageanalysis.ColorLayout * @deprecated use MPEG-7 feature ColorLayout or CEDD, which are both really fast. */ public static DocumentBuilder getFastDocumentBuilder() { return DocumentBuilderFactory.getColorLayoutBuilder(); } /** * Creates a DocumentBuilder for the AutoColorCorrelation feature. Note that the extraction of this feature * is especially slow! So use it only on small images! Images that do not fit in a 200x200 pixel box are * resized by the document builder to ensure shorter processing time. See * {@link net.semanticmetadata.lire.imageanalysis.AutoColorCorrelogram} for more information on the image feature. * Be sure to use the same options for the ImageSearcher as you used for the DocumentBuilder. * * @return the created AutoCorrelation feature DocumentBuilder. */ public static DocumentBuilder getAutoColorCorrelogramDocumentBuilder() { return new GenericDocumentBuilder(AutoColorCorrelogram.class, DocumentBuilder.FIELD_NAME_AUTOCOLORCORRELOGRAM, GenericDocumentBuilder.Mode.Fast); } /** * Creates a DocumentBuilder for the AutoColorCorrelation feature. Note that the extraction of this feature * is especially slow, but this is a more fast, but less accurate settings version! * Images that do not fit in a defined bounding box they are * resized by the document builder to ensure shorter processing time. See * {@link net.semanticmetadata.lire.imageanalysis.AutoColorCorrelogram} for more information on the image feature. * Be sure to use the same options for the ImageSearcher as you used for the DocumentBuilder. * * @return the created AutoCorrelation feature DocumentBuilder. * @deprecated Use #getAutoColorCorrelogramDocumentBuilder instead. */ public static DocumentBuilder getFastAutoColorCorrelationDocumentBuilder() { return new CorrelogramDocumentBuilder(AutoColorCorrelogram.Mode.SuperFast); } /** * Creates a DocumentBuilder for the CEDD feature. See * {@link net.semanticmetadata.lire.imageanalysis.CEDD} for more information on the image feature. * Be sure to use the same options for the ImageSearcher as you used for the DocumentBuilder. * * @return the created CEDD feature DocumentBuilder. */ public static DocumentBuilder getCEDDDocumentBuilder() { // return new CEDDDocumentBuilder(); return new GenericFastDocumentBuilder(CEDD.class, DocumentBuilder.FIELD_NAME_CEDD); } /** * Creates a DocumentBuilder for the FCTH feature. See * {@link net.semanticmetadata.lire.imageanalysis.FCTH} for more information on the image feature. * Be sure to use the same options for the ImageSearcher as you used for the DocumentBuilder. * * @return the created FCTH feature DocumentBuilder. */ public static DocumentBuilder getFCTHDocumentBuilder() { return new GenericDocumentBuilder(FCTH.class, DocumentBuilder.FIELD_NAME_FCTH, GenericDocumentBuilder.Mode.Fast); } /** * Creates a DocumentBuilder for the JCD feature. See * {@link net.semanticmetadata.lire.imageanalysis.JCD} for more information on the image feature. * Be sure to use the same options for the ImageSearcher as you used for the DocumentBuilder. * * @return the created DocumentBuilder */ public static DocumentBuilder getJCDDocumentBuilder() { return new GenericFastDocumentBuilder(JCD.class, DocumentBuilder.FIELD_NAME_JCD); } /** * Creates a DocumentBuilder for the JpegCoefficientHistogram feature. See * {@link net.semanticmetadata.lire.imageanalysis.JpegCoefficientHistogram} for more * information on the image feature. * Be sure to use the same options for the ImageSearcher as you used for the DocumentBuilder. * * @return the created DocumentBuilder */ public static DocumentBuilder getJpegCoefficientHistogramDocumentBuilder() { return new GenericDocumentBuilder(JpegCoefficientHistogram.class, DocumentBuilder.FIELD_NAME_JPEGCOEFFS, GenericDocumentBuilder.Mode.Fast); } /** * Creates a DocumentBuilder for simple RGB color histograms. See * {@link net.semanticmetadata.lire.imageanalysis.SimpleColorHistogram} for more * information on the image feature. * Be sure to use the same options for the ImageSearcher as you used for the DocumentBuilder. * * @return the created feature DocumentBuilder. */ public static DocumentBuilder getColorHistogramDocumentBuilder() { return new GenericDocumentBuilder(SimpleColorHistogram.class, DocumentBuilder.FIELD_NAME_COLORHISTOGRAM, GenericDocumentBuilder.Mode.Fast); } /** * Creates a DocumentBuilder for three Tamura features. See * {@link net.semanticmetadata.lire.imageanalysis.Tamura} for more * information on the image feature. * Be sure to use the same options for the ImageSearcher as you used for the DocumentBuilder. * * @return the created Tamura feature DocumentBuilder. */ public static DocumentBuilder getTamuraDocumentBuilder() { return new GenericFastDocumentBuilder(Tamura.class, DocumentBuilder.FIELD_NAME_TAMURA); } /** * Creates a DocumentBuilder for the Gabor feature. See * {@link net.semanticmetadata.lire.imageanalysis.Gabor} for more * information on the image feature. * Be sure to use the same options for the ImageSearcher as you used for the DocumentBuilder. * * @return the created Tamura feature DocumentBuilder. */ public static DocumentBuilder getGaborDocumentBuilder() { return new GenericFastDocumentBuilder(Gabor.class, DocumentBuilder.FIELD_NAME_GABOR); } /** * Creates and returns a DocumentBuilder, which contains all available features. For * AutoColorCorrelogram the getAutoColorCorrelogramDocumentBuilder() is used. Therefore * it is compatible with the respective Searcher. * * @return a combination of all available features. */ public static DocumentBuilder getFullDocumentBuilder() { ChainedDocumentBuilder cdb = new ChainedDocumentBuilder(); cdb.addBuilder(DocumentBuilderFactory.getExtensiveDocumentBuilder()); cdb.addBuilder(DocumentBuilderFactory.getAutoColorCorrelogramDocumentBuilder()); cdb.addBuilder(DocumentBuilderFactory.getCEDDDocumentBuilder()); cdb.addBuilder(DocumentBuilderFactory.getFCTHDocumentBuilder()); cdb.addBuilder(DocumentBuilderFactory.getColorHistogramDocumentBuilder()); cdb.addBuilder(DocumentBuilderFactory.getTamuraDocumentBuilder()); cdb.addBuilder(DocumentBuilderFactory.getGaborDocumentBuilder()); return cdb; } }

从源码可以看出,不同的方法对应不同的特征提取方式。

(1)getDefaultDocumentBuilder()

CEDD(Color and Edge Directivity Descriptor,CEDD)颜色和边缘的方向性描述符特征的提取

(2)getColorLayoutBuilder()

MPEG-7图像颜色布局描述符特征的提取

(3)getEdgeHistogramBuilder()

MPEG-7图像边缘直方图描述符特征的提取 

(4)getScalableColorBuilder()

(5)getAutoColorCorrelogramDocumentBuilder()

MPEG-7颜色相关直方图描述符特征的提取 

(6)getCEDDDocumentBuilder()

CEDD(Color and Edge Directivity Descriptor,CEDD)颜色和边缘的方向性描述符特征的提取

(7)getFCTHDocumentBuilder()

FCTH(Fuzzy Color and Texture Histogram)模糊颜色和纹理直方图描述符特征的提取

(8)getJCDDocumentBuilder

JCD是CEDD和FCTH这两种特征的一种组合.

(9)getJpegCoefficientHistogramDocumentBuilder()

(10)getColorHistogramDocumentBuilder()

颜色直方图描述符

(11)getTamuraDocumentBuilder()

Tamura 纹理分析法

(12)getGaborDocumentBuilder()

Gabor滤波器

二、ImageSearcher:用于检索


你可能感兴趣的:(LIRE/图像检索)