-2

我想将两个图像分成相等数量的块,然后将每个块的像素值求和以与相应的块总和进行比较。我使用了这段代码,我想知道如何比较每个块的积分:

//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;
}
4

1 回答 1

1

假设您的图像被分成mXn块,因此您有mXn整数值(即块的总和作为整数) Img1, Img2,然后具有mXn大小。

IplImage *Img1 , IplImage *Img2
    for(i = 0; i<=m; i++)
      for(j = 0; j<=n; j++)
       { 
          if((int)cvGetReal2D(Img1, i, j) == (int)cvGetReal2D(Img2, i, j));// get the block value and compare it.
          //write u r logic here.
       }
于 2012-05-22T05:44:41.213 回答