code: function optimizeHistogram(histogram, options) {
    options = _.defaults(options || {}, {
      colorDistanceThreshold: 22
    });
  
    for (var i = 0; i < histogram.length - 1; i++) {
      if (histogram[i].count === 0) {
        continue;
      }
  
      for (var j = i + 1; j < histogram.length; j++) {
        var distance = getColorDistance(histogram[i].color, histogram[j].color);
  
        if (distance <= options.colorDistanceThreshold) {
          histogram[i].count += histogram[j].count;
          histogram[j].count = 0;
        }
      }
    }
  
    histogram = _.filter(histogram, function (group) {
      return group.count > 0;
    });
  
    return sortByCountDesc(histogram);
  }
docs: Merges groups with colors that are close enough into single group.