Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Adding Matrices without saturation

Is it possible to add two matrices (with values in [0, 255]) and store the result in a matrix with values in [0, 510]?

I would be adding up to 100 matrices that way, and want to keep the high precision (which rules out the use of cv::addWeighted()). A 16-bit int per pixel should suffice to contain these values.

I hoped this would work:

Mat A(10, 10, CV_8UC1, 200);
Mat B(10, 10, CV_8UC1, 200);
Mat C(10, 10, CV_32S, 0);
cv::add(A, B, C);

But the values in C are saturated to 255 (rather than value 400 being stored in some 16-bit data type).

Any suggestions are highly appreciated!