Integral graph is a very common method in images. It was first learned in the Fast Calculation of Haar features (refer to blog: using the integral image method to quickly calculate Haar features), and then developed to mean filtering, binarization and other image processing methods are also very common.
For a brief introduction to the integral graph, refer to the blog post: using the integral image method to quickly calculate Haar features, which will not be repeated here. This article describes how to calculate the integral graph.
Because the information stored by each unit in the integral graph is the sum of all pixels in the upper left corner of the position in the source image, you need to directly calculate the integral graph for a W * H image:
(1 + 2 +... + W-1) * H + (1 + 2 +... + W) * (H = 1) = (W-2) * H/(W-1) + 2 (W + 1) * (H-1)/W
Addition.
A simple and fast calculation method the most direct and fast calculation method is to calculate the points at the current position by using the calculation points. Its idea is just like the method for quickly calculating Haar features.
That is, Integral (I, j) = Integral (I, J-1) + Integral (I-1, j)-Integral (I-1, J-1) + Image (I, j); so, to obtain the integral graph for a W * H image, you must:
(W-1) + (H-1) + 3 * (W-1) * (H-1)Addition. The Code is as follows:
Void integral (unsigned char * inputMatrix, unsigned long * outputMatrix, int width, int height) {// calculate integral of the first linefor (int I = 0; I
0) {outputMatrix [I] + = outputMatrix [I-1];} for (int I = 1; I
By observing the previous method, we found that the Integral (I, j) does not need to be calculated by the three points, but only needs the Integral (I, J-1) on the left) add the sum of the current column. That is, Integral (I, j) = Integral (I, J-1) + ColumnSum (j); therefore, for a W * H image to obtain the Integral graph directly, only need:
(W-1) + (H-1) + 2 * (W-1) * (H-1)Addition. The Code is as follows:
Void fastIntegral (unsigned char * inputMatrix, unsigned long * outputMatrix, int width, int height) {unsigned long * columnSum = new unsigned long [width]; // sum of each column // calculate integral of the first linefor (int I = 0; I
0) {outputMatrix [I] + = outputMatrix [I-1];} for (int I = 1; I
(Reprinted please indicate the author and Source: http://blog.csdn.net/xiaowei_cqu is not allowed for commercial use)