SimilarityUtils { public static SimilarityUnit calcSimilarity(BufferedImage expectedImage, BufferedImage actualImage, Rectangle rectangle, ComparedRectangleArea similarRectangle, Offset offset) { return calcSimilarity(expectedImage, actualImage, rectangle, similarRectangle, offset, -1); } private  SimilarityUtils(); static SimilarityUnit calcSimilarity(BufferedImage expectedImage, BufferedImage actualImage,
			Rectangle rectangle, ComparedRectangleArea similarRectangle, Offset offset); static SimilarityUnit calcSimilarity(BufferedImage expectedImage, BufferedImage actualImage,
			Rectangle rectangle, ComparedRectangleArea similarRectangle, Offset offset, double similarityFeatureMatrix); static double calcFeatureDistance(Color[][] expectedFeature, Color[][] actualFeature); static boolean checkFeatureSize(int width, int height); static double calcSimilarityByFeatureMatrix(BufferedImage expectedImage, BufferedImage actualImage,
			Rectangle rectangle, Offset offset); static double calcSimilarityByFeatureMatrix(BufferedImage expectedImage, BufferedImage actualImage,
			Rectangle expectedFrame, Rectangle actualFrame); static SimilarityUnit calcSimilarityPixelByPixel(BufferedImage expectedImage, BufferedImage actualImage,
			Rectangle rectangle, Offset offset);  }
@Test public void testCalcSimilarity() throws Exception { BufferedImage image1 = ImageIO.read(getClass().getResource("hifive_logo.png")); BufferedImage image2 = ImageIO.read(getClass().getResource("hifive_logo.png")); Rectangle rectangle = new Rectangle(0, 0, image1.getWidth(), image1.getHeight()); ComparedRectangleArea similarRectangle = new ComparedRectangleArea(rectangle); Offset offset = new Offset(0, 0); SimilarityUnit unit; double actual; unit = SimilarityUtils.calcSimilarity(image1, image2, rectangle, similarRectangle, offset); actual = unit.getSimilarityThresDiff(); assertThat(actual, is(1.0)); unit = SimilarityUtils.calcSimilarity(image1, image2, rectangle, similarRectangle, offset, 1.0); actual = unit.getSimilarityThresDiff(); assertThat(actual, is(1.0)); }
@Test public void testCalcSimilarityWithDiff() throws Exception { BufferedImage image1 = ImageIO.read(getClass().getResource("hifive_logo.png")); BufferedImage image2 = ImageIO.read(getClass().getResource("hifive_logo_similar.png")); Rectangle rectangle = new Rectangle(0, 0, image1.getWidth(), image1.getHeight()); ComparedRectangleArea similarRectangle = new ComparedRectangleArea(rectangle); Offset offset = new Offset(0, 0); SimilarityUnit unit; double actual; unit = SimilarityUtils.calcSimilarity(image1, image2, rectangle, similarRectangle, offset); actual = unit.getSimilarityThresDiff(); assertThat(actual, is(0.97)); unit = SimilarityUtils.calcSimilarity(image1, image2, rectangle, similarRectangle, offset, 1.0); actual = unit.getSimilarityThresDiff(); assertThat(actual, is(0.97)); }