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.
2 | No.2 Revision |
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.