# Revision history [back]

Got it thanks to berak! It seems so obvious after a good night's sleep.

The scale value for cv::Mat::convertTo() should be the maximum possible value of the data type over the maximum possible value of the arbitrary range. So if the values range are in the range 0 - 10000, conversion would be done like so to remain in 16 bits:

raw.convertTo(raw, CV_16UC1, 65535.0 / 10000);


and to convert to 8 bits:

raw.convertTo(raw, CV_8UC1, 255.0 / 10000);


Got it thanks to berak! It seems so obvious after a good night's sleep.

The scale value for cv::Mat::convertTo() should be the maximum possible value of the data type over the maximum possible value of the arbitrary range. So if the values range are in the range 0 - 10000, conversion would be done like so to remain in 16 bits:

raw.convertTo(raw, CV_16UC1, 65535.0 / 10000);


and to convert to 8 bits:

raw.convertTo(raw, CV_8UC1, 255.0 / 10000);