EMD距离详细介绍已经在在这里已经给出。
思路:我们把一张图像的归一化的一维直方图作为signature的权重值,把色相的值作为signature。也就是一般在比较两幅图像的EMD距离时,signature是一样,只是权重值不一样。
通过以下程序,就可以得到一幅图像的signature:
#include<iostream>
using namespace std;
#include<opencv2\core\core.hpp>
#include<opencv2\highgui\highgui.hpp>
#include<opencv2\imgproc\imgproc.hpp>
using namespace cv;
int main(int argc,char* argv[])
{
Mat image,imageHsv,hist,histRow,normalHist;
image = imread(argv[1],1);
if(argc !=2 || !image.data)
{
cerr << " No image!" <<endl;
}
//颜色空间的转换
cvtColor(image,imageHsv,CV_BGR2HSV);
//一维直方图
int hbins = 90;
int histSize[] = {hbins};
float hranges[] = {0.0,180.0};
const float* ranges[] = {hranges};
int channels[] ={0};
calcHist(&imageHsv,1,channels,Mat(),hist,1,histSize,ranges,true,false);
normalize(hist,normalHist,1,0,CV_L1,CV_32F);
Mat signature(hbins,2,CV_32FC1);
normalHist.copyTo(signature.col(0));
//我们把bin的均值作为signature中的特征,放在signature的第二列
float step = 180.0/hbins;
for( int r=0;r < hbins; r++)
signature.at<float>(r,1) =(step*r+(step*(r+1)-1))/2.0;
return 0;
}图像检索:一维直方图+EMD距离,布布扣,bubuko.com
原文:http://blog.csdn.net/zhangping1987/article/details/37560397