Ask Your Question

Revision history [back]

EMD function returning many zeros values

I'm using the function in my application with the CV_DIST_L2, and I need to compare many vectors of characteristics. I know that they are much different because I used others functions to compare, but using the EMD is returning many zero values, I'm comparing about 1 million of images. If I need to rank 10 images by the distance it is very bad because of the zero values, it is normal? For example if I have one image and I need to compare with the others 1 million, for to find the 10 more similar, may be I can't find nor the query image because of the zeros values.

click to hide/show revision 2
No.2 Revision

updated 2015-12-20 20:39:00 -0600

berak gravatar image

EMD function returning many zeros values

I'm using the function in my application with the CV_DIST_L2, and I need to compare many vectors of characteristics. I know that they are much different because I used others functions to compare, but using the EMD is returning many zero values, I'm comparing about 1 million of images. If I need to rank 10 images by the distance it is very bad because of the zero values, it is normal? For example if I have one image and I need to compare with the others 1 million, for to find the 10 more similar, may be I can't find nor the query image because of the zeros values.

char metricname[10] = "EMD";

class EarthMoversMetricEvaluator : public stBasicMetricEvaluator < tBasicArrayObject > {
public:

    virtual stDistance GetDistance(tBasicArrayObject * o1, tBasicArrayObject * o2) {
        this->UpdateDistanceCount();
        int dim = o1->GetSize();
        Mat sig1(dim, 2, CV_32FC1);
        Mat sig2(dim, 2, CV_32FC1);
        for (unsigned int a = 0; a < dim; a++) {
            sig1.at<float>(a, 0) = o1->Get(a);
            sig1.at<float>(a, 1) = a;
            sig2.at<float>(a, 0) = o2->Get(a);
            sig2.at<float>(a, 1) = a;
        }
        double d = EMD(sig1, sig2, CV_DIST_L2);
        return d;
    }
    virtual stDistance GetDistance2(tBasicArrayObject * o1, tBasicArrayObject * o2) {
        stDistance d = GetDistance(o1, o2);
        return d*d;
    }
};
typedef EarthMoversMetricEvaluator myEvaluator;

o1 and o2 are two characteristic vector with one dimension, I have one million of vectors when I do one knn query with k = 10 all answers are 0, and for one knn query it is bad, is there any solution?