code: public static MarvinImage rgbToBinary(MarvinImage img, int threshold) {
          MarvinImage resultImage = new MarvinImage(img.getWidth(), img.getHeight(), MarvinImage.COLOR_MODEL_BINARY);
  
          for (int y = 0; y < img.getHeight(); y++) {
              for (int x = 0; x < img.getWidth(); x++) {
                  int gray = (int) ((img.getIntComponent0(x, y) * 0.3) + (img.getIntComponent1(x, y) * 0.59) + (img.getIntComponent2(x, y) * 0.11));
  
                  if (gray <= threshold) {
                      resultImage.setBinaryColor(x, y, true);
                  } else {
                      resultImage.setBinaryColor(x, y, false);
                  }
              }
          }
          return resultImage;
      }
docs: Converts an image in RGB mode to BINARY mode
  
  @param img       image
  @param threshold grays cale threshold
  @return new MarvinImage instance in BINARY mode