Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

histogram comparison

Hi at all! I must do an histogram comparison with a formula that computes the intersection of histograms. My histograms have 256 bins. How I realize this formula correctly? I 'm using this for object tracking with colors.

enter code here

image description

Post below one my possible solution but I think that this not execute exactly the formula

int const block = 768; Mat background = imread("Scene.jpg",CV_LOAD_IMAGE_COLOR);\Scene1.jpg",CV_LOAD_IMAGE_COLOR); //bacground histograms Mat hB_b[block]; Mat hB_g[block]; Mat hB_r[block]; //currents histogram Mat hC_b[block];
Mat hC_g[block];
Mat hC_r[block]; float somma_bkg_b = 0; float somma_bkg_g = 0; float somma_bkg_r = 0;

float sommatoria_bkg_b[block]; float sommatoria_bkg_g[block]; float sommatoria_bkg_r[block]; for(int a=0; a<320; a+=10) { for(int b=0; b<240; b+=10) { Mat SUPPORT (background, Rect(a,b,10,10)); vector<mat> bgr_planes; split( SUPPORT, bgr_planes ); calcHist( &bgr_planes[0], 1, 0, Mat(), hB_b[conteggio], 1, &histSize, &histRange, uniform, accumulate ); calcHist( &bgr_planes[1], 1, 0, Mat(), hB_g[conteggio], 1, &histSize, &histRange, uniform, accumulate ); calcHist( &bgr_planes[2], 1, 0, Mat(), hB_r[conteggio], 1, &histSize, &histRange, uniform, accumulate ); for(int b=0; b<256; b++) { somma_bkg_b = somma_bkg_b + hB_b[conteggio].at<int>(b); somma_bkg_g = somma_bkg_g + hB_g[conteggio].at<int>(b); somma_bkg_r = somma_bkg_b + hB_r[conteggio].at<int>(b); } sommatoria_bkg_b[conteggio] = somma_bkg_b; sommatoria_bkg_g[conteggio] = somma_bkg_g; sommatoria_bkg_r[conteggio] = somma_bkg_r; conteggio++; } } Mat current = imread("Scene2.jpg",CV_LOAD_IMAGE_COLOR); for(int a=0; a<320; a+=10) { for(int b=0; b<240; b+=10) { Mat SUPPORT_2 (current_frame, Rect(a,b,10,10)); ricostruzione[conteggio_c] = SUPPORT_2.clone(); vector<mat> bgr_planes_c; split( SUPPORT_2, bgr_planes_c ); calcHist( &bgr_planes_c[0], 1, 0, Mat(), hC_b[conteggio_c], 1, &histSize, &histRange, uniform, accumulate ); calcHist( &bgr_planes_c[1], 1, 0, Mat(), hC_g[conteggio_c], 1, &histSize, &histRange, uniform, accumulate ); calcHist( &bgr_planes_c[2], 1, 0, Mat(), hC_r[conteggio_c], 1, &histSize, &histRange, uniform, accumulate ); double f_intersezione_b[block]; double f_intersezione_g[block]; double f_intersezione_r[block]; float min_Bb = 0; float min_Bg = 0; float min_Br = 0; float min_Cb = 0; float min_Cg = 0; float min_Cr = 0; float min_num_b = 0; float min_num_g = 0; float min_num_r = 0; float min_sum_b = 0; float min_sum_g = 0; float min_sum_r = 0; float pos_min_b = 0; float somma_minimi_b = 0; float pos_min_g = 0; float somma_minimi_g = 0; float pos_min_r = 0; float somma_minimi_r = 0; for (int t=0; t<block; t++)="" {="" for="" (int="" u="0;" u&lt;256;="" u++)="" {="" intersect="" formula="" (blu)***************************************************="" if="" (hb_b[t].at<int="">(u) <= hC_b[t].at<int>(u)) pos_min_b = hB_b[t].at<int>(u); else pos_min_b = hC_b[t].at<int>(u); somma_minimi_b += pos_min_b; //intersect formula (GREEN)*************** if (hB_g[t].at<int>(u) <= hC_g[t].at<int>(u)) pos_min_g = hB_g[t].at<int>(u); else pos_min_g = hC_g[t].at<int>(u); somma_minimi_g += pos_min_g; //intersect formula (RED)***************** if (hB_r[t].at<int>(u) <= hC_r[t].at<int>(u)) pos_min_r = hB_r[t].at<int>(u); else pos_min_r = hC_r[t].at<int>(u); somma_minimi_r += pos_min_r;
}

         f_intersezione_b[t] = somma_minimi_b / sommatoria_bkg_b[t];
         f_intersezione_g[t] = somma_minimi_g / sommatoria_bkg_g[t];
         f_intersezione_r[t] = somma_minimi_r / sommatoria_bkg_r[t];
           }

thanks at all for your time!

click to hide/show revision 2
No.2 Revision

updated 2016-01-08 03:49:49 -0600

berak gravatar image

histogram comparison

Hi at all! I must do an histogram comparison with a formula that computes the intersection of histograms. My histograms have 256 bins. How I realize this formula correctly? I 'm using this for object tracking with colors.

enter code here

image description

Post below one my possible solution but I think that this not execute exactly the formula

int const block = 768;
Mat background = imread("Scene.jpg",CV_LOAD_IMAGE_COLOR);\Scene1.jpg",CV_LOAD_IMAGE_COLOR);
imread("Scene.jpg",CV_LOAD_IMAGE_COLOR);\\Scene1.jpg",CV_LOAD_IMAGE_COLOR);
//bacground histograms
Mat hB_b[block]; 
Mat hB_g[block];
Mat hB_r[block]; 
//currents histogram
Mat hC_b[block]; 
Mat hC_g[block];
Mat hC_r[block]; float somma_bkg_b = 0; float somma_bkg_g = 0; float somma_bkg_r = 0;

0; float sommatoria_bkg_b[block]; float sommatoria_bkg_g[block]; float sommatoria_bkg_r[block]; for(int a=0; a<320; a+=10) { for(int b=0; b<240; b+=10) { Mat SUPPORT (background, Rect(a,b,10,10)); vector<mat> vector<Mat> bgr_planes; split( SUPPORT, bgr_planes ); calcHist( &bgr_planes[0], 1, 0, Mat(), hB_b[conteggio], 1, &histSize, &histRange, uniform, accumulate ); calcHist( &bgr_planes[1], 1, 0, Mat(), hB_g[conteggio], 1, &histSize, &histRange, uniform, accumulate ); calcHist( &bgr_planes[2], 1, 0, Mat(), hB_r[conteggio], 1, &histSize, &histRange, uniform, accumulate ); for(int b=0; b<256; b++) { somma_bkg_b = somma_bkg_b + hB_b[conteggio].at<int>(b); somma_bkg_g = somma_bkg_g + hB_g[conteggio].at<int>(b); somma_bkg_r = somma_bkg_b + hB_r[conteggio].at<int>(b); } sommatoria_bkg_b[conteggio] = somma_bkg_b; sommatoria_bkg_g[conteggio] = somma_bkg_g; sommatoria_bkg_r[conteggio] = somma_bkg_r; conteggio++; } } Mat current = imread("Scene2.jpg",CV_LOAD_IMAGE_COLOR); for(int a=0; a<320; a+=10) { for(int b=0; b<240; b+=10) { Mat SUPPORT_2 (current_frame, Rect(a,b,10,10)); ricostruzione[conteggio_c] = SUPPORT_2.clone(); vector<mat> vector<Mat> bgr_planes_c; split( SUPPORT_2, bgr_planes_c ); calcHist( &bgr_planes_c[0], 1, 0, Mat(), hC_b[conteggio_c], 1, &histSize, &histRange, uniform, accumulate ); calcHist( &bgr_planes_c[1], 1, 0, Mat(), hC_g[conteggio_c], 1, &histSize, &histRange, uniform, accumulate ); calcHist( &bgr_planes_c[2], 1, 0, Mat(), hC_r[conteggio_c], 1, &histSize, &histRange, uniform, accumulate ); double f_intersezione_b[block]; double f_intersezione_g[block]; double f_intersezione_r[block]; float min_Bb = 0; float min_Bg = 0; float min_Br = 0; float min_Cb = 0; float min_Cg = 0; float min_Cr = 0; float min_num_b = 0; float min_num_g = 0; float min_num_r = 0; float min_sum_b = 0; float min_sum_g = 0; float min_sum_r = 0; float pos_min_b = 0; float somma_minimi_b = 0; float pos_min_g = 0; float somma_minimi_g = 0; float pos_min_r = 0; float somma_minimi_r = 0; for (int t=0; t<block; t++)="" {="" for="" (int="" u="0;" u&lt;256;="" u++)="" {="" intersect="" formula="" (blu)***************************************************="" if="" (hb_b[t].at<int="">(u) t++) { for (int u=0; u<256; u++) { //intersect formula (BLU)*************************************************** if (hB_b[t].at<int>(u) <= hC_b[t].at<int>(u)) pos_min_b = hB_b[t].at<int>(u); else pos_min_b = hC_b[t].at<int>(u); somma_minimi_b += pos_min_b; //intersect formula (GREEN)*************** (GREEN)************************************************* if (hB_g[t].at<int>(u) <= hC_g[t].at<int>(u)) pos_min_g = hB_g[t].at<int>(u); else pos_min_g = hC_g[t].at<int>(u); somma_minimi_g += pos_min_g; //intersect formula (RED)***************** (RED)*************************************************** if (hB_r[t].at<int>(u) <= hC_r[t].at<int>(u)) pos_min_r = hB_r[t].at<int>(u); else pos_min_r = hC_r[t].at<int>(u); somma_minimi_r += pos_min_r;
}

                             
            }

             f_intersezione_b[t] = somma_minimi_b / sommatoria_bkg_b[t];
          f_intersezione_g[t] = somma_minimi_g / sommatoria_bkg_g[t];
          f_intersezione_r[t] = somma_minimi_r / sommatoria_bkg_r[t];
            }

thanks at all for your time!

histogram comparison

Hi at all! I must do an histogram comparison with a formula that computes the intersection of histograms. My histograms have 256 bins. How I realize this formula correctly? I 'm using this for object tracking with colors.

enter code here

image description

Post below one my possible solution but I think that this not execute exactly the formula

int const block = 768;
Mat background = imread("Scene.jpg",CV_LOAD_IMAGE_COLOR);\\Scene1.jpg",CV_LOAD_IMAGE_COLOR);
//bacground histograms
Mat hB_b[block]; 
Mat hB_g[block];
Mat hB_r[block]; 
//currents histogram
Mat hC_b[block];  
Mat hC_g[block];   
Mat hC_r[block]; 
float somma_bkg_b = 0;
float somma_bkg_g = 0;
float somma_bkg_r = 0;

float sommatoria_bkg_b[block];
float sommatoria_bkg_g[block];
float sommatoria_bkg_r[block];
sum_bkg_b = 0;
float sum_bkg_g = 0;
float sum_bkg_r = 0;

float summ_bkg_b[block];
float summ_bkg_g[block];
float summ_bkg_r[block];
for(int a=0; a<320; a+=10)
{
    for(int b=0; b<240; b+=10)
    {
             Mat SUPPORT (background, Rect(a,b,10,10));
             vector<Mat> bgr_planes;
         split( SUPPORT, bgr_planes ); 
             calcHist( &bgr_planes[0], 1, 0, Mat(), hB_b[conteggio], hB_b[count], 1, &histSize, &histRange, uniform, accumulate );
         calcHist( &bgr_planes[1], 1, 0, Mat(), hB_g[conteggio], hB_g[count], 1, &histSize, &histRange, uniform, accumulate );
         calcHist( &bgr_planes[2], 1, 0, Mat(), hB_r[conteggio], hB_r[count], 1, &histSize, &histRange, uniform, accumulate );
             for(int b=0; b<256; b++)
         {
           somma_bkg_b = somma_bkg_b sum_bkg_b = sum_bkg_b + hB_b[conteggio].at<int>(b);
           somma_bkg_g = somma_bkg_g hB_b[count].at<int>(b);
           sum_bkg_g = sum_bkg_g + hB_g[conteggio].at<int>(b);
           somma_bkg_r = somma_bkg_b hB_g[count].at<int>(b);
           sum_bkg_r = sum_bkg_b + hB_r[conteggio].at<int>(b);
hB_r[count].at<int>(b);
         }
         sommatoria_bkg_b[conteggio] = somma_bkg_b; 
         sommatoria_bkg_g[conteggio] = somma_bkg_g;
         sommatoria_bkg_r[conteggio] = somma_bkg_r;
             conteggio++;
summ_bkg_b[count] = sum_bkg_b; 
         summ_bkg_g[count] = sum_bkg_g;
         summ_bkg_r[count] = sum_bkg_r;
             count++;
    }
}
Mat current = imread("Scene2.jpg",CV_LOAD_IMAGE_COLOR);
for(int a=0; a<320; a+=10)
{
    for(int b=0; b<240; b+=10)
    {
        Mat SUPPORT_2 (current_frame, (current, Rect(a,b,10,10));
            ricostruzione[conteggio_c] ricostruzione[count_c] = SUPPORT_2.clone();
                vector<Mat> bgr_planes_c;
        split( SUPPORT_2, bgr_planes_c );
                calcHist( &bgr_planes_c[0], 1, 0, Mat(), hC_b[conteggio_c], hC_b[count_c], 1, &histSize, &histRange, uniform, accumulate );
        calcHist( &bgr_planes_c[1], 1, 0, Mat(), hC_g[conteggio_c], hC_g[count_c], 1, &histSize, &histRange, uniform, accumulate );
        calcHist( &bgr_planes_c[2], 1, 0, Mat(), hC_r[conteggio_c], hC_r[count_c], 1, &histSize, &histRange, uniform, accumulate );
                double f_intersezione_b[block]; f_intersect_b[block]; 
        double f_intersezione_g[block];
f_intersect_g[block];
        double f_intersezione_r[block];
f_intersect_r[block];
                float min_Bb = 0;
        float min_Bg = 0;
        float min_Br = 0;
        float min_Cb = 0;
        float min_Cg = 0;
        float min_Cr = 0;
        float min_num_b = 0;
        float min_num_g = 0;
        float min_num_r = 0;
        float min_sum_b = 0;
        float min_sum_g = 0;
        float min_sum_r = 0;
        float pos_min_b = 0;
        float somma_minimi_b sum_min_b = 0;
        float pos_min_g = 0;
        float somma_minimi_g sum_min_g = 0;
        float pos_min_r = 0;
        float somma_minimi_r sum_min_r = 0;
                for (int t=0; t<block; t++)
        {
            for (int u=0; u<256; u++)
            {
                             //intersect formula (BLU)***************************************************
                if (hB_b[t].at<int>(u) <= hC_b[t].at<int>(u))
                     pos_min_b = hB_b[t].at<int>(u);
                else 
                    pos_min_b = hC_b[t].at<int>(u);
                somma_minimi_b sum_min_b += pos_min_b;
                //intersect formula (GREEN)*************************************************
                if (hB_g[t].at<int>(u) <= hC_g[t].at<int>(u))
                    pos_min_g = hB_g[t].at<int>(u);
                else 
                     pos_min_g = hC_g[t].at<int>(u);
                somma_minimi_g sum_min_g += pos_min_g;
                //intersect formula (RED)***************************************************
                if (hB_r[t].at<int>(u) <= hC_r[t].at<int>(u))
                     pos_min_r = hB_r[t].at<int>(u);
                else 
                    pos_min_r = hC_r[t].at<int>(u);
                somma_minimi_r sum_mini_r += pos_min_r;                              
            }

             f_intersezione_b[t] = somma_minimi_b f_intersect_b[t] = sum_min_b / sommatoria_bkg_b[t];
             f_intersezione_g[t] = somma_minimi_g summ_bkg_b[t];
             f_intersect_g[t] = sum_min_g / sommatoria_bkg_g[t];
             f_intersezione_r[t] = somma_minimi_r summ_bkg_g[t];
             f_intersect_r[t] = sum_min_r / sommatoria_bkg_r[t];
summ_bkg_r[t];
               }

thanks at all for your time!