title: Image Quantization with quantums Algorithm question
body: <p>I came across a question and unable to find a feasible solution.</p>
  <p>Image Quantization</p>
  <p>Given a grayscale mage, each pixels color range from (0 to 255), compress the range of values to a given number of quantum values.</p>
  <p>The goal is to do that with the minimum sum of costs needed, the cost of a pixel is defined as the absolute difference between its color and the closest quantum value for it.</p>
  <p>Example</p>
  <p>There are 3 rows 3 columns, image [[7,2,8], [8,2,3], [9,8 255]] quantums = 3 number of quantum values.The optimal quantum values are (2,8,255) Leading to the minimum sum of costs |7-8| + |2-2| + |8-8| + |8-8| + |2-2| + |3-2| + |9-8| + |8-8| + |255-255| = 1+0+0+0+0+1+1+0+0 = 3</p>
  <p>Function description</p>
  <p>Complete the solve function provided in the editor. This function takes the following 4 parameters and returns the minimum sum of costs.</p>
  <p>n Represents the number of rows in the image</p>
  <p>m Represents the number of columns in the image</p>
  <p>image Represents the image</p>
  <p>quantums Represents the number of quantum values.</p>
  <p>Output:
  Print a single integer the minimum sum of costs/</p>
  <pre><code>Constraints: 
  
  1&lt;=n,m&lt;=100
  0&lt;=image|i||j|&lt;=255
  1&lt;=quantums&lt;=256
  
  Sample Input 1
  3
  3
  7 2 8
  8 2 3
  9 8 255
  10
  
  Sample output 1
  0
  </code></pre>
  <p><strong>Explanation</strong></p>
  <p>The optimum quantum values are {0,1,2,3,4,5,7,8,9,255} Leading the minimum sum of costs |7-7| + |2-2| + |8-8| + |8-8| + |2-2| + |3-3| + |9-9| + |8-8| + |255-255| = 0+0+0+0+0+0+0+0+0 = 0</p>
  <p>can anyone help me to reach the solution ?</p>