title: sum of image pixels
body: <p>I tried to sum pixels values on black and white area, through dividing the image into a grid of blocks and getting the sum of pixels for each block.</p>
  
  <p>When I printed the values of each, the values were all the same = 255.
  My question is: Why does this happen? Some blocks have only black pixels and some have black and white?</p>
  
  <pre><code>double* divide (Mat I)
           {
               //double* pointer;
           static double*  sums= new double [9];
          //pointer= sums[0];
            //double sums2[10];
  
            Mat block;
                //Mat block2;
  
      int numberblocks=9; 
      int bh;
      int bw;
      //int bh2;
      //int bw2;
  
      bh=I.cols/numberblocks;
      bw=I.rows/numberblocks; 
      //bh2=u.cols/numberblocks;
      //bw2=u.rows/numberblocks; 
      //
      double blockarea=bh*bw;
      //double num=0;
      //double blockarea2=bh2*bw2;
  
      //int r=0;
      //int c=0;
      //int err=0;
  
      for(int a=0;a&lt;9;a++)
      {
         for (int r = 0; r &lt; I.rows; r += bw)
         {
               for (int c = 0; c &lt; I.cols; c += bh)
                   {
  
                   block  = I(cv::Range(r, min(r + bw, I.rows)),cv::Range(c, min(c + bh, I.cols)));
  
  
                    }
         }
         double sum=0;
  
           for(int i=0;i&lt;block.rows;i++)
           {
               for(int j=0;j&lt;block.cols;j++)
                   {
                  sums[a] = sum + block.at&lt;uchar&gt;(i,j); //sums[k-1] + block.at&lt;uchar&gt;(i,j);
               }
           }
           cout&lt;&lt;"sum of"&lt;&lt;a&lt;&lt;"is"&lt;&lt;sums[a]&lt;&lt;endl;
  
  
      }
  
  
  return sums;
  
  }    
  </code></pre>