static DoublePt centroidForColorPredicate(F1<Int, Bool> pred, RGBImage img) {
  int w = img.getWidth(), h = img.getHeight();
  double sumX = 0, sumY = 0;
  int sum = 0;
  for y to h: for x to w:
    if (pred.get(img.getInt(x, y))) {
      sumX += x;
      sumY += y;
      ++sum;
    }
  if (sum == 0) null;
  ret DoublePt(sumX/sum, sumY/sum);
}