Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

the short answer is: you can't.

the longer one: a uchar Mat holds integer values, 0,1,2,3,...255. so assigning 0.01 will lead to rounding to the nearest integer, 0.

a value of 0.01 would probably only make sense for a float image in the [0..1] range, so:

Mat contrast = ... // CV_8U
Mat contrast_f;
contrast.convertTo( contrast_f, CV_32F, 1.0/255);

for (int y=0; y<contrast_f.rows; y++)
{
    for (int x=0; x<contrast_f.cols; x++)
    {
        if(contrast_f.at<float>(y, x) ==0)
            contrast_f.at<float>(y, x) = 0.01f;
    }
}

if you still want to keep your uchar contrast image, the smallest non-0 value you can assign is 1 (while the largest is 255).