[Algorithm design] Quick points calculation

Source: Internet
Author: User

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)
     
    

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.