首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 平面设计 > 图形图像 >

LIRe 源代码分析 六:检索(ImageSearcher)[以颜色直方图为例]

2013-11-03 
LIRe 源代码分析 6:检索(ImageSearcher)[以颜色直方图为例]前几篇文章介绍了LIRe 的基本接口:LIRe 源代码

LIRe 源代码分析 6:检索(ImageSearcher)[以颜色直方图为例]
前几篇文章介绍了LIRe 的基本接口:
LIRe 源代码分析 1:整体结构
LIRe 源代码分析 2:基本接口(DocumentBuilder)
LIRe 源代码分析 3:基本接口(ImageSearcher)

以及其建立索引(DocumentBuilder)[以颜色直方图为例]
LIRe 源代码分析 4:建立索引(DocumentBuilder)[以颜色直方图为例]
LIRe 源代码分析 5:提取特征向量[以颜色直方图为例]

现在来看一看它的检索部分(ImageSearcher)。不同的方法的检索功能的类各不相同,它们都位于“net.semanticmetadata.lire.impl”中,如下图所示:

LIRe 源代码分析 六:检索(ImageSearcher)[以颜色直方图为例]

在这里仅分析一个比较有代表性的:颜色直方图。前文已经分析过ColorLayoutDocumentBuilder,在这里我们分析一下ColorLayoutImageSearcher。源代码如下:


看一下GenericImageSearcher的源代码:

public static double getSimilarity(int[] YCoeff1, int[] CbCoeff1, int[] CrCoeff1, int[] YCoeff2, int[] CbCoeff2, int[] CrCoeff2) {        int numYCoeff1, numYCoeff2, CCoeff1, CCoeff2, YCoeff, CCoeff;        //Numbers of the Coefficients of two descriptor values.        numYCoeff1 = YCoeff1.length;        numYCoeff2 = YCoeff2.length;        CCoeff1 = CbCoeff1.length;        CCoeff2 = CbCoeff2.length;        //take the minimal Coeff-number        YCoeff = Math.min(numYCoeff1, numYCoeff2);        CCoeff = Math.min(CCoeff1, CCoeff2);        setWeightingValues();        int j;        int[] sum = new int[3];        int diff;        sum[0] = 0;        for (j = 0; j < YCoeff; j++) {            diff = (YCoeff1[j] - YCoeff2[j]);            sum[0] += (weightMatrix[0][j] * diff * diff);        }        sum[1] = 0;        for (j = 0; j < CCoeff; j++) {            diff = (CbCoeff1[j] - CbCoeff2[j]);            sum[1] += (weightMatrix[1][j] * diff * diff);        }        sum[2] = 0;        for (j = 0; j < CCoeff; j++) {            diff = (CrCoeff1[j] - CrCoeff2[j]);            sum[2] += (weightMatrix[2][j] * diff * diff);        }        //returns the distance between the two desciptor values        return Math.sqrt(sum[0] * 1.0) + Math.sqrt(sum[1] * 1.0) + Math.sqrt(sum[2] * 1.0);    }

由代码可见,getSimilarity()通过具体的算法,计算两张图片特征向量之间的相似度。




热点排行