title: OpenCV: How to visualize a depth image
body: <p>I am using a dataset in which it has images where each pixel is a 16 bit unsigned int storing the depth value of that pixel in mm. I am trying to visualize this as a greyscale depth image by doing the following:</p>
  
  <pre><code>cv::Mat depthImage; 
  depthImage = cv::imread("coffee_mug_1_1_1_depthcrop.png", CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR ); // Read the file 
  depthImage.convertTo(depthImage, CV_32F); // convert the image data to float type   
  namedWindow("window");
  float max = 0;
  for(int i = 0; i &lt; depthImage.rows; i++){
      for(int j = 0; j &lt; depthImage.cols; j++){
          if(depthImage.at&lt;float&gt;(i,j) &gt; max){
              max = depthImage.at&lt;float&gt;(i,j);
          }
      }   
  }
  cout &lt;&lt; max &lt;&lt; endl;
  
  
  float divisor = max / 255.0;
  cout &lt;&lt; divisor &lt;&lt; endl;
  for(int i = 0; i &lt; depthImage.rows; i++){
      for(int j = 0; j &lt; depthImage.cols; j++){
          cout &lt;&lt; depthImage.at&lt;float&gt;(i,j) &lt;&lt; ", ";
          max = depthImage.at&lt;float&gt;(i,j) /= divisor;
          cout &lt;&lt; depthImage.at&lt;float&gt;(i,j) &lt;&lt; endl;
      }   
  }
  
  
  imshow("window", depthImage);
  waitKey(0);
  </code></pre>
  
  <p>However, it is only showing two colours this is because all of the values are close together i.e. in the range of 150-175 + the small values which show up black (see below).</p>
  
  <p><img src="https://i.stack.imgur.com/1RyEd.png" alt="rgb image">
  <img src="https://i.stack.imgur.com/fUDAG.png" alt="greyscale image"></p>
  
  <p>Is there a way to normalize this data such that it will show various grey levels to highlight these small depth differences?</p>