Hi guys, let's say that I have a CV_16UC1
matrix with float values which it needs to be transformed to CV_8UC1
for now no any further process in between and then back to CV_16UC1
. The way I am doing it at the moment is:
// img is the 16bit image
double minval,maxval;
minMaxLoc(img, &minval, &maxval, NULL, NULL);
img.convertTo(img, CV_8UC1, 255.0 / maxval);
img.convertTo(img, CV_16UC1, maxval / 255.0);
However, the values in the new 16bit matrix slightly differ from the original ones. My question is there a better way to recover the original float values as it was (I guess no, but I need to ask :-p), or at least decrease the difference to the minimum?