Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Example 1)

Mat srcMatrix(Size(256, 256), CV_64FC1, matrix); 
Mat dstMatrix(srcMatrix.size,CV_8UC1);
double scale=1.0;
double offset=0.0;
//dstMatrix = srcMatrix * scale  + offset
srcMatrix.convertTo(dstMatrix, dstMatrix.type(),scale,offset);

Example 2) you could avoid to specify size and type for dstMatrix:

Mat dstMatrix;
srcMatrix.convertTo(dstMatrix, CV_8UC1,scale,offset);

in both cases convertTo performs round (not trunc/ceil). See also this answer.

click to hide/show revision 2
No.2 Revision

updated 2016-07-01 04:48:07 -0600

berak gravatar image

Example 1)

Mat srcMatrix(Size(256, 256), CV_64FC1, matrix); 
Mat dstMatrix(srcMatrix.size,CV_8UC1);
dstMatrix(srcMatrix.size(),CV_8UC1);
double scale=1.0;
double offset=0.0;
//dstMatrix = srcMatrix * scale  + offset
srcMatrix.convertTo(dstMatrix, dstMatrix.type(),scale,offset);

Example 2) you could avoid to specify size and type for dstMatrix:

Mat dstMatrix;
srcMatrix.convertTo(dstMatrix, CV_8UC1,scale,offset);

in both cases convertTo performs round (not trunc/ceil). See also this answer.