0

I'd like to sum my 4X4 block. Suppose I have an image and will divide it into 4X4 blocks. Then afterward I'd like to determine the sum of each block using cvIntegral. How can I cope this?

Here is my basic program in order to calculate integral image value of whole image:

float s = 0.0f;
//Read in the image
IplImage* hImage = cvLoadImage("bayer-image.jpg",0);
UINT width = hImage->width; UINT height = hImage->height;

CvMat* sum = cvCreateMat(height + 1, width + 1, CV_32SC1);
CvMat* sqsum = cvCreateMat(height + 1, width + 1, CV_64FC1);

cvIntegral(hImage, sum, sqsum);

cvReleaseImage(&hImage);
cvReleaseMat(&sum);
cvReleaseMat(&sqsum);

What should I do next?

Really thanks in advance.

Mr.K
  • 305
  • 7
  • 18

1 Answers1

0

Check this out http://en.wikipedia.org/wiki/Summed_area_table

As an example, the block defined by the corners (1, 1) and (4, 4) has the area

a1 = integral(0,0)+integral(4,4)-integral(4,0)-integral(0,4);

Sam
  • 19,708
  • 4
  • 59
  • 82
  • Hi again, you also replied my histogram mean question few weeks ago. Anyway actually I got the whole underlying theory of integral image, but programmatically I need the hints how to code it. Since I'm quite new in opencv. Do you mind giving example from my code above? thanks. – Mr.K Nov 08 '11 at 12:21
  • :) i'm sorry, but it's better for both of us that you do it by yourself. I do not have the time, and you need to learn opencv. Check this answer to learn how to access matrix elements http://stackoverflow.com/questions/1844736/accesing-a-matrix-element-in-the-mat-object-not-the-cvmat-object-in-opencv-c And good luck! – Sam Nov 08 '11 at 12:38
  • P.S. Don't forget to follow the rules of SO: if answer is good, upvote it and/or accept as correct answer. And, more important, answer questions where you are a field expert. – Sam Nov 08 '11 at 12:40
  • Hi again, I've finished using cvIntegral, for 1 channel I used CV_MAT_ELEM( *sum , int, 0, 0) and so forth, then 3 channels I used CV_MAT_ELEM_CN(*sum,double,4,8 * nChannels + 0) and so forth.BUT when comparing with conventional looping for sum each 4x4 blocks, the integral approach cannot outperform the conventional approach, the result showed 27 FPS for Integral and 30 FPS for conventional one. Do you have any suggestion? thanks. – Mr.K Nov 16 '11 at 17:36
  • That's a different story. You can optimize it in many ways, all depending on your target device, your programming skills and the available time :) The best is to use your first approach (direct summing of the interest pixels and use SIMD to accelerate it) – Sam Nov 17 '11 at 07:11
  • Thanks Vasile, your aid helped me a lot. – Mr.K Nov 24 '11 at 17:17