title: Saving 16-bit image in opencv with cmap (cv::ColorMap only supports source images of type CV_8UC1 or CV_8UC3 in function 'operator()')
body: <p>I'm trying to save/show a 16-bit numpy array (as image) in opencv with cmap, it doesn't work. On the other hand, it works smoothly in matplotlib.</p>
  
  <p>My deep learning model gives a numpy array <code>arr</code> (<code>&lt;class 'numpy.ndarray'&gt;</code>). You can get it from <a href="https://www.dropbox.com/s/p83yohb2m4o7wgy/pred_depth_scale.npy?dl=0" rel="nofollow noreferrer">here</a>.</p>
  
  <pre><code># np array predicted from a depth model
  &gt;&gt;&gt; arr16 = np.load('pred_depth_scale.npy')
  &gt;&gt;&gt; arr16.dtype, arr16.shape
  (dtype('uint16'), (466, 492))
  &gt;&gt;&gt; cv2.imshow('img', arr16)
  # shows image in grayscale
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/FARmY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FARmY.png" alt="uint16_cv2_imshow"></a></p>
  
  <p>I want to convert it to other colormap:</p>
  
  <pre><code>&gt;&gt;&gt; arr16 = cv2.applyColorMap(arr16, cv2.COLORMAP_COOL)
  </code></pre>
  
  <p>It throws the following error:</p>
  
  <blockquote>
    <p>error: OpenCV(4.1.0) /io/opencv/modules/imgproc/src/colormap.cpp:684:
    error: (-5:Bad argument) cv::ColorMap only supports source images of
    type CV_8UC1 or CV_8UC3 in function 'operator()'</p>
  </blockquote>
  
  <p>Now, if I convert the image to <code>uint8</code>, the image contains noise.</p>
  
  <pre><code>&gt;&gt;&gt; arr8 = arr16.astype(np.uint8)
  &gt;&gt;&gt; arr8 = cv2.applyColorMap(arr8, cv2.COLORMAP_COOL)
  &gt;&gt;&gt; cv2.imshow('img', arr8)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/LDkcx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LDkcx.png" alt="uint8_cv2_imshow"></a></p>
  
  <p>On the other hand, with matplotlib, <code>cmap</code> works fine as follows:</p>
  
  <pre><code>&gt;&gt;&gt; plt.imshow(arr16, cmap='magma')
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/DqgqN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DqgqN.png" alt="uint16_plt_imshow"></a></p>
  
  <p>My <strong>question</strong> is: How do I save/show a 16-bit image in opencv with cmap?</p>