Color similarity measurement (OpenCV)

I am working on a CBIR (Content-based Image Retrieval) project that will draw a histogram of RGB images, as well as calculate the distance between other images using a query image.

I am using VS 2008 - MFC and OpenCV Library. The method I wanted to use to calculate the distance is Euclidean distance (ED), but somehow I could not handle it.

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

Here is an example for creating a signature that I found

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

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

and in my histogram function there is nothing like the variable h_bins and s_bins

In my program, I calculate / draw a histogram in R, G, and B. So each image has 3 histograms. for example: CvHistogram * hist_red, * hist_green, * hist_blue;

How to use my histogram to create a signature?

* link to my drawHistogram function is given in my comment below

+3
source share
1 answer

This is my code to create the RGB signature in my project: In my case, I need the signature tu - 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
source

Source: https://habr.com/ru/post/1774595/


All Articles