我想将两个图像分成相等数量的块,然后将每个块的像素值求和以与相应的块总和进行比较。我使用了这段代码,我想知道如何比较每个块的积分:
//Divide the image
Mat divide (Mat input)
{
Mat block;
int numberblocks=10;
int bh;
int bw;
bh=input.cols/numberblocks;
bw=input.rows/numberblocks;
double blockarea=bh*bw;
double num=0;
Mat sum = cvCreateMat(input.cols + 1, input.rows + 1, CV_32SC1);
Mat sqsum = cvCreateMat(input.cols + 1, input.rows + 1, CV_64FC1);
for (int r = 0; r < input.rows; r += bw)
{
for (int c = 0; c < input.cols; c += bh)
block = input(cv::Range(r, min(r + bw, input.rows)),cv::Range(c, min(c + bh, input.cols)));
integral(input, sum, sqsum);
//double mean=(cv::sum(block).val[0])/255;
//double whiteratio=mean/blockarea;
num++;
}
return sqsum;
}
int main(int argc, char ** argv)
{
Mat I = imread("01.png", CV_LOAD_IMAGE_GRAYSCALE);
Mat Idivided= divide (I);
imshow("name1", Idivided);
waitKey(0);
return 0;
}