title: color depth reduction with opencv and LUT
body: <p>I'd like to perform a color reduction via color depth scaling.</p>
  
  <p>Like this example:
  <img src="https://i.stack.imgur.com/vXORW.jpg" alt="enter image description here"></p>
  
  <p>the first image is CGA resolution, the second is EGA, the third is HAM.
  I'd like to do it with cv::LUT because i think it is the betterway to do it.
  I can do with greyscale with this code:</p>
  
  <pre><code>Mat img = imread("test1.jpg", 0);
  uchar* p;
  Mat lookUpTable(1, 256, CV_8U);
  p = lookUpTable.data;
  for( int i = 0; i &lt; 256; ++i)
      p[i] = 16 * (i/16)
  LUT(img, lookUpTable, reduced);
  </code></pre>
  
  <p>original:<img src="https://i.stack.imgur.com/dtKXB.png" alt="enter image description here"></p>
  
  <p>color reduced: <img src="https://i.stack.imgur.com/HfuWz.png" alt="enter image description here"></p>
  
  <p>but if i try to do it with color I get strange result..</p>
  
  <p><img src="https://i.stack.imgur.com/BjwXo.png" alt="enter image description here"></p>
  
  <p>with this code:</p>
  
  <pre><code>imgColor = imread("test1.jpg");
  Mat reducedColor;
  int n = 16;
  for (int i=0; i&lt;256; i++) {
      uchar value = floor(i/n) * n;
      cout &lt;&lt; (int)value &lt;&lt; endl;
      lut.at&lt;Vec3b&gt;(i)[2]= (value &gt;&gt; 16) &amp; 0xff;
      lut.at&lt;Vec3b&gt;(i)[1]= (value &gt;&gt; 8) &amp; 0xff;
      lut.at&lt;Vec3b&gt;(i)[0]= value &amp; 0xff;
  } 
  LUT(imgColor, lut, reducedColor);
  </code></pre>