开发者

Similarity Measurement between Color Image (OpenCV)

开发者 https://www.devze.com 2023-01-25 01:17 出处:网络
I\'m working with a CBIR (Content-based Image Retrieval) project which will draw RGB histogram of images and also calculate the distance between other images with query image.

I'm working with a CBIR (Content-based Image Retrieval) project which will draw RGB histogram of images and also calculate the distance between other images with query image.

I'm using VS 2008 - MFC and OpenCV Library. The method I wanted to use for calculating the distance is Euclidean Distance(ED), but somehow I failed to work it out.

I found a function - cvCalcEMD2() that can help me calculate the distance between two histogram. To use this function, i need to create signature for my histogram.

Here is an example for creating signature that I found

in the For loop, there is a line where I need to pass in my histogram:

float bin_val = cvQueryHistValue_2D( hist1, h, s );

and in my function for histogram don't have something like the variable h_bins and s_bins

In my program, I calculate/draw my histogram into R, G and B. means, each image I've 3 histogram. eg: CvHistogram *hist_red, *hist_green, *hist_blue;

How do I us开发者_Go百科e my histogram to create signature?

*the link to my drawHistogram function is on my comment below


This is my code to create RGB hist signature in my project: In my case I needed the signature tu be an array of floats.

void makeColorSign(const IplImage* img,float** colorSign) {
    unsigned int* N = Params::colorSignSize;
    float* sign = (float*)malloc(N[0]*N[1]*3*sizeof(float));
    IplImage* s = cvCreateImage(cvSize(N[0],N[1]),img->depth,img->nChannels);
    cvResize(img,s,CV_INTER_NN);
    RgbImage rgb(s);
    for(unsigned int y=0; y<N[1]; ++y) {
        for(unsigned int x=0; x<N[0]; ++x) {
            unsigned int coord = (y*N[1]+x)*3;
            sign[coord] = rgb[y][x].r;
            sign[coord+1] = rgb[y][x].g;
            sign[coord+2] = rgb[y][x].b;
        }
    }
    *colorSign = sign;
    cvReleaseImage(&s);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号