画像をブロックのグリッドに分割し、各ブロックのピクセルの合計を取得することにより、白黒領域のピクセル値を合計しようとしました。
それぞれの値を印刷すると、値はすべて同じ = 255 でした。私の質問は、なぜこれが起こるのですか? 一部のブロックには黒のピクセルのみがあり、一部のブロックには白黒がありますか?
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;
}