title: Get dominant colors from image discarding the background
body: <p>What is the best (result, not performance) algorithm to fetch dominant colors from an image. The algorithm should discard the background of the image.</p>
  
  <p>I know I can build an array of colors and how many they appear in the image, but I need a way to determine what is the background and what is the foreground, and keep only the second (foreground) in mind while read the dominant colors.</p>
  
  <p>The problem is very hard especially for gradient backgrounds or backrounds with patterns (not plain)</p>