title: OpenCV: Unable to correctly read a single channel png image with 16 bit depth
body: <p>I am trying to read  a png image with single channel and 16 bit depth . Subsequently I am finding the pixel values on a line:  </p>
  
  <pre><code>//read the image data in the file "MyPic.JPG" and store it in 'img'
  Mat img = imread("sir.png",  CV_LOAD_IMAGE_ANYDEPTH); 
  
  //Iterate through the line along which Intensity profile is required 
  LineIterator it(img, Point(1,1), Point(20,20), 8);
  
  vector&lt;Vec3b&gt; buf;   
  
  for(int i=0; i&lt;it.count; i++)
  {
      buf.push_back( Vec3b(*it) );
      it++;
  }
  //print pixel value on the selected line
  cerr &lt;&lt; Mat(buf) &lt;&lt; endl;
  </code></pre>
  
  <p>The printed values are always nos which are less than 255:</p>
  
  <pre><code>156, 156, 164; 153, 153, 152; 154, 154, 139; 179, 179, 180; 182, 182, 176; 2
  208, 167; 144, 144, 163; 204, 204, 206; 180, 180, 187; 174, 174, 170; 150, 1
  162; 154, 154, 170; 157, 157, 181; 181, 181, 159; 164, 164, 152; 130, 130, 1
  166, 166, 181; 153, 153, 170; 153, 153, 176; 180, 180, 198]
  </code></pre>
  
  <p>This means it is actually reading this image as 8 bit instead of 16 bit. </p>
  
  <p>I verified my image in MATLAB and I can see values which are valid for 16 bit , such as : </p>
  
  <pre><code>d=imread('sir.png');
  buf = improfile( d, [1 20], [1 20] )
  </code></pre>
  
  <p>which gives output such as: </p>
  
  <blockquote>
    <p>65535
           40092
           39321
           39578
           46003
           46774
           53456
           37008
           52428
           46260
           44718
           38550
           39578
           40349
           46517
           42148
           33410
           42662
           39321
           39321</p>
  </blockquote>
  
  <p>Why is my result in opencv differing than the actual? How do I correctly read the image so that it shows values in 16 bit?   </p>
  
  <p><strong>Update</strong></p>
  
  <p>Based on Roger's answer I have updated my code like this:</p>
  
  <pre><code>LineIterator it(img, Point(1,1), Point(20,20), 8);
  vector&lt;ushort&gt; buf;
  
  for(int i = 0; i &lt; it.count; i++)
  {
      buf.push_back(img.at&lt;ushort&gt;(it.pos()));
  }
  
  cerr &lt;&lt; Mat(buf) &lt;&lt; endl;
  </code></pre>
  
  <p>But now ALL my pixel values are coming 40092, which is wrong  as compared to MATLAB output.     </p>