SimilarityUtils { public static double calcFeatureDistance(Color[][] expectedFeature, Color[][] actualFeature) { int r, g, b; double dist = 0; for (int row = 0; row < FeatureRow; row++) { for (int col = 0; col < FeatureCol; col++) { r = expectedFeature[row][col].getRed() - actualFeature[row][col].getRed(); g = expectedFeature[row][col].getGreen() - actualFeature[row][col].getGreen(); b = expectedFeature[row][col].getBlue() - actualFeature[row][col].getBlue(); dist += r * r + g * g + b * b; } } return Math.sqrt(dist) / (Math.sqrt(3 * FeatureRow * FeatureCol) * 255); } 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 testCalcFeatureDistance() throws Exception { Color[][] feature1 = new Color[5][5]; Color[][] feature2 = new Color[5][5]; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { feature1[i][j] = new Color(0xff, 0xff, 0xff); feature2[i][j] = new Color(0xff, 0xff, 0xff); } } double actual = SimilarityUtils.calcFeatureDistance(feature1, feature2); assertThat(actual, is(0.0)); }
@Test public void testCalcFeatureDistanceWithDiff() throws Exception { Color[][] feature1 = new Color[5][5]; Color[][] feature2 = new Color[5][5]; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { feature1[i][j] = new Color(0xff, 0xff, 0xff); feature2[i][j] = new Color(0x00, 0x00, 0x00); } } double actual = SimilarityUtils.calcFeatureDistance(feature1, feature2); assertThat(actual, is(1.0)); }