@Override
  public void createModel(RectangleLength2D_I32 target) {

    float total = 0;

    for (int y = 0; y < target.height; y++) {
      int index = imageRed.startIndex + (y + target.y0) * imageRed.stride + target.x0;
      for (int x = 0; x < target.width; x++, index++) {
        int r = imageRed.data[index] & 0xFF;
        int g = imageGreen.data[index] & 0xFF;
        int b = imageBlue.data[index] & 0xFF;

        ColorHsv.rgbToHsv(r, g, b, hsv);

        if (hsv[2] < minimumValue) continue;

        binsH[(int) (hsv[0] / sizeH)]++;
        binsS[(int) (hsv[1] / sizeS)]++;

        total++;
      }
    }

    // normalize the sum to one
    for (int i = 0; i < binsH.length; i++) {
      binsH[i] /= total;
      binsS[i] /= total;
    }
  }
  @Override
  public float compute(int x, int y) {

    int index = imageRed.getIndex(x, y);

    int r = imageRed.data[index] & 0xFF;
    int g = imageGreen.data[index] & 0xFF;
    int b = imageBlue.data[index] & 0xFF;

    ColorHsv.rgbToHsv(r, g, b, hsv);

    if (hsv[2] < minimumValue) return 0f;

    return binsH[(int) (hsv[0] / sizeH)] * binsS[(int) (hsv[1] / sizeS)];
  }