title: Issue with finding closest colors with taken image from camera
body: <p>I have a project which needs to identify the closest color and corresponding location of the taken image from a Camera. However, right now I am facing the problem what the color cannot be correctly identified, could anyone can point me out what is my problems? Below is the flow of my project. </p>
  
  <ol>
  <li>Taken an image from Camera as a template (Template). Template image contains various of objects which each object contains a dominant color and each objects are separated</li>
  <li><p>Split the image based on no. of objects detected,in each object image, finding max. Location of H, S , V channels using 1D histogram. </p></li>
  <li><p>Take another image (Target) using the same Camera, target image is similar to template image but the objects inside may a bit overlapped and/or locations are different</p></li>
  <li><p>Using the information got in 2), finding the closest color using 3D distance and rebuild the image (ie. replacing each pixel value to the closest color). 
  If the pixels H value is 15deg away from the dominant H value got in 2), then the pixel will not be compared to that color. </p></li>
  <li><p>Finding the contours of each color in rebuild target image, finding each color location. </p></li>
  </ol>
  
  <p>Right now the problem is, when I rebuild the image in step 4, I found that the color is not identified correctly. some of the colors inside rebuilt image can be identified only in a very small portion, or with black pixels like pepper noise (since if none of the colors can be identified, ie. HUE value is +/-15deg away color to be compared, or S / V value is away from color to be compared, that pixel will be replaced to black pixel)  </p>
  
  <p>Even though if I take 2 images with object, location and light source the same, one image as the template and the other one is the target image, I found that the rebuild image color still contains error. </p>
  
  <p>So now I am not sure what is the actual problem is, but my guess is coming from finding the H,S,V dominant location. Could it be better if I finding max. Location [H,S] and V channels instead of H,S,V channels separately? Or any suggestions to point out? Thanks a lot  </p>
  
  <p><a href="https://i.stack.imgur.com/YBf1E.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YBf1E.png" alt="This is the image I take and rebuild, the first row is bad result and 2nd row is good result(The rebuilt image on right can be regenerated more than 80% of original area)"></a></p>