Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

is there a better way to recover float values?

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?

is there a better way to recover float 16UC bit values?

Hi guys, let's say that I have a CV_16UC1 matrix with float 16bit unsigned short 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?

is there a better way to recover 16UC bit values?

Hi guys, let's say that I have a CV_16UC1 matrix with 16bit unsigned short 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 how I can decrease the difference between the original and new values to the minimum?minimum as possible?