title: How to reduce colors to a specified palette
body: <p>I need to solve the following problem:</p>
  
  <p>INPUT: Image IM, Palette PA</p>
  
  <p>OUTPUT: IM only with the colours of PA</p>
  
  <p>The input image is in RGB but I can convert it to HSV. The colour target palette I specify contains at the moment: black, white, light gray, gray, dark gray, blue, pink, red, purple, green, yellow, brown, orange.</p>
  
  <p>I searched a lot for that, but I can only find reducing an image to the most common colours or reducing it to a fixed palette like 16 colours EGA graphics.</p>
  
  <p>I found the best answer of this:
  <a href="https://stackoverflow.com/questions/236692/how-do-i-convert-any-image-to-a-4-color-paletted-image-using-the-python-imaging">How do I convert any image to a 4-color paletted image using the Python Imaging Library?</a> </p>
  
  <p>It has an input palette and reduces the image to that. Is there an equal way to do in in OpenCV with C++ ?</p>