Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8015251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:12:09+00:00 2026-06-04T20:12:09+00:00

I tried to sum pixels values on black and white area, through dividing the

  • 0

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.

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?

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<9;a++)
    {
       for (int r = 0; r < I.rows; r += bw)
       {
             for (int c = 0; c < 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<block.rows;i++)
         {
             for(int j=0;j<block.cols;j++)
                 {
                sums[a] = sum + block.at<uchar>(i,j); //sums[k-1] + block.at<uchar>(i,j);
             }
         }
         cout<<"sum of"<<a<<"is"<<sums[a]<<endl;


    }


return sums;

}    
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T20:12:10+00:00Added an answer on June 4, 2026 at 8:12 pm

    I think this will do

         for(int i=0;i<block.rows;i++)
         {
             for(int j=0;j<block.cols;j++)
                 {
    
                  sum = sum + block.at<uchar>(i,j); //sums[k-1] + block.at<uchar>(i,j);
             }
         }
         sums[a]=sum;
    

    Debug it to be sure. Without using sum it would be:

         for(int i=0;i<block.rows;i++)
         {
             for(int j=0;j<block.cols;j++)
                 {
    
                   sums[a] =  sums[a] + block.at<uchar>(i,j); //sums[k-1] + block.at<uchar>(i,j);
             }
         }         
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For a small project (Problem 10 Project Euler) i tried to sum up all
I was writing a quick one-liner in GHCi and tried to compose sum with
I've tried different collections in Scala to sum it's elements and they are much
i tried the brute force way: #include <stdio.h> int sum(int a [],int b[], int
Tried to reuse Sum but got this error: cannot resolve method Sum how can
I'm trying to make a macro to sum a variable length column. I've tried
I'm using the WPF Grid to align objects, and ran into a rather glaring
I tried to make a code that calculates the values of the formulas the
I've tried to port the following sum in a php for loop this way:
Trying to get a check sum of results of a SELECT statement, tried this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.