title: Normalize pixel values between 0 and 1
body: <p>I am looking to normalize the pixel values of an image to the range [0..1] using C++/OpenCV. However, when I do the normalization using either <code>image *= 1./255</code> or the normalize function the pixel values are rounded down to zero. I have tried setting the image to type <code>CV_32FC3</code>.</p>
  
  <p>Below is the code I have:</p>
  
  <pre><code>  Mat image;
    image = imread(imageLoc, CV_LOAD_IMAGE_COLOR | CV_LOAD_IMAGE_ANYDEPTH);
  
    Mat tempImage;
  
    // (didn't work) tempImage *= 1./255;
  
    image.convertTo(tempImage, CV_32F, 3);
    normalize(image, tempImage, 0, 1, CV_MINMAX);
  
    int r = 100;
    int c = 150;
  
    uchar* ptr = (uchar*)(tempImage.data + r * tempImage.step);
    Vec3f tempVals;
    tempVals.val[0] =  ptr[3*c+1];
    tempVals.val[1] =  ptr[3*c+2];
    tempVals.val[2] =  ptr[3*c+3];
    cout&lt;&lt;" temp image - "&lt;&lt; tempVals &lt;&lt; endl;
  
    uchar* ptr2 = (uchar*)(image.data + r * image.step);
    Vec3f imVals;
    imVals.val[0] =  ptr2[3*c+1];
    imVals.val[1] =  ptr2[3*c+2];
    imVals.val[2] =  ptr2[3*c+3];
    cout&lt;&lt;" image - "&lt;&lt; imVals &lt;&lt; endl;
  </code></pre>
  
  <p>This produces the following output in the console:</p>
  
  <pre><code>temp image - [0, 0, 0]
  image - [90, 78, 60]
  </code></pre>