public int[] quantize(Contour c) throws ContourQuantizerException {
    if (c.size() < time_bins) {
      throw new ContourQuantizerException(
          "Cannot construct a quantized contour with fewer than time_bins values. time bins:" + time_bins +
              ", contour size: " + c.size());
    }
    int[] qc = new int[time_bins];

    int index = 0;
    int count = 0;
    double sum = 0;
    for (int i = 0; i < c.size(); ++i) {
      if (Math.floor(((double) i / c.size()) * time_bins) > index) {
        double mean = sum / count;
        int value = (int) Math.round((mean - min_value) / (max_value - min_value));
        value = value < 0 ? 0 : value >= value_bins ? value_bins - 1 : value;

        qc[index] = value;
        index = (int) Math.floor(((double) i / c.size()) * time_bins);
        sum = 0;
        count = 0;
      }
      sum += c.get(i);
      ++count;
    }
    int value = (int) Math.round((sum / count - min_value) / (max_value - min_value));
    value = value < 0 ? 0 : value >= value_bins ? value_bins - 1 : value;
    qc[index] = value;

    return qc;
  }