1 | initial version |
this is a bit tricky. since adding up 8 or 16 bit images might lead to overflow, you need an image with a type larger than your single pics to hold the accumulated values.
Mat img = imread("lena.jpg", 0);
Mat acc(img.size(), CV_64F, Scalar(0)); // all black, *double* image
accumulate(img,acc);
accumulate(img,acc);
accumulate(img,acc);
accumulate(img,acc);
Mat avg;
acc.convertTo(avg, CV_8U, 1.0/4); // back to u8 land, divide by count
imshow("average", avg);
waitKey();
2 | No.2 Revision |
this is a bit tricky. since adding up 8 or 16 bit images might lead to overflow, you need an image with a type larger than your single pics to hold the accumulated values.
Mat img = imread("lena.jpg", 0);
0); // grayscale for simplicity
Mat acc(img.size(), CV_64F, Scalar(0)); // all black, *double* image
accumulate(img,acc);
accumulate(img,acc);
accumulate(img,acc);
accumulate(img,acc);
Mat avg;
acc.convertTo(avg, CV_8U, 1.0/4); // back to u8 land, divide by count
imshow("average", avg);
waitKey();