code: public double getOverlapScore(BufferedImage refImage, BufferedImage tplImage) {
          try (ByteArrayOutputStream img1 = new ByteArrayOutputStream();
               ByteArrayOutputStream img2 = new ByteArrayOutputStream()) {
              ImageIO.write(refImage, "png", img1);
              ImageIO.write(tplImage, "png", img2);
              return comparator
                      .getImagesSimilarity(Base64.getEncoder().encode(img1.toByteArray()),
                              Base64.getEncoder().encode(img2.toByteArray()))
                      .getScore();
          } catch (IOException e) {
              throw new ScreenshotComparisonError(e);
          }
      }
docs: Compares two valid java bitmaps and calculates similarity score between them.
  Both images are expected to be of the same size/resolution. The method
  implicitly invokes {@link ComparesImages#getImagesSimilarity(byte[], byte[])}.
  
  @param refImage   reference image
  @param tplImage   template
  @return similarity score value in range (-1.0, 1.0]. 1.0 is returned if the images are equal
  @throws ScreenshotComparisonError if provided images are not valid or have
  different resolution