title: Convert different shades of a color in an image to one color
body: <p>How can I convert the light gray background color (with variation in its shades) to a single color, say light gray? I want the dark gray color embedded on top of the background color to be one single color as well. Until now, what I have done is to assign these two regions with two closest color names ('lightgray' and 'dimgray') and minimize the sum of squared differences for each pixel's r,g,b and get the closest color from webcolors module.</p>
  
  <pre><code>rd = (r_c - requested_color[0]) ** 2
  gd = (g_c - requested_color[1]) ** 2
  bd = (b_c - requested_color[2]) ** 2
  </code></pre>
  
  <p><strong>Original image:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/sZBla.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sZBla.png" alt="enter image description here"></a></p>
  
  <p><strong>Image produced from my python code:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/o5y3d.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/o5y3d.png" alt="enter image description here"></a></p>
  
  <p>You can see that that along the boundaries I am not able to get the light gray color as you could see in the original image.</p>