ImageUtils { public static List<ObjectGroup> convertDiffPointsToObjectGroups(DiffPoints DP, int group_distance) { List<Point> diffPoints = DP.getDiffPoints(); if (diffPoints == null || diffPoints.isEmpty()) { return new ArrayList<ObjectGroup>(); } int mergeFlag = 0; List<ObjectGroup> diffGroups = new ArrayList<ObjectGroup>(); for (Point point : diffPoints) { ObjectGroup objectGroup = new ObjectGroup(new Point(point.x, point.y), group_distance); for (ObjectGroup diffGroup : diffGroups) { if (diffGroup.canMerge(objectGroup)) { diffGroup.union(objectGroup); mergeFlag = 1; break; } } if (mergeFlag != 1) { diffGroups.add(objectGroup); } mergeFlag = 0; } return ObjectGroup.mergeAllPossibleObjects(diffGroups); } private  ImageUtils(); static ImageComparedResult compare(BufferedImage image1, Rectangle imageArea1, BufferedImage image2,
			Rectangle imageArea2, CompareOption[] options); static boolean isContained(BufferedImage entireImage, BufferedImage partImage); static double[][] calcIntegralImage(BufferedImage source); static boolean imageEquals(BufferedImage image1, BufferedImage image2); static BufferedImage getMaskedImage(BufferedImage image, List<Rectangle> maskAreas); static BufferedImage getMarkedImage(BufferedImage image, DiffPoints diffPoints); static BufferedImage getDiffImage(BufferedImage leftImage, BufferedImage rightImage, DiffPoints diffPoints); static BufferedImage trim(BufferedImage image, int trimTop, int trimLeft, int trimBottom, int trimRight); static BufferedImage verticalMerge(List<BufferedImage> images); static BufferedImage merge(List<List<BufferedImage>> images); static int[] getRGB(BufferedImage image, int width, int height); static int[] toARGB(int pixel); static int toPixel(int[] argb); static int toPixel(int r, int g, int b); static int toPixel(int a, int r, int g, int b); static int detectBackgroundColor(BufferedImage b); static boolean getObjectRectangle(BufferedImage image, Rectangle rectangle); static double norm(int pixel1, int pixel2); static double[] countSubpixel(BufferedImage bimage); static void removeRedundantRectangles(List<Rectangle> rectangles, int xLimit, int yLimit); static void removeOverlappingRectangles(List<Rectangle> rectangles); static void reshapeRect(Rectangle rectangle, int xLimit, int yLimit); static Rectangle getTightDiffArea(Rectangle rectangle, int xLimit, int yLimit); static List<Rectangle> convertObjectGroupsToAreas(List<ObjectGroup> objectGroups); static List<ObjectGroup> convertDiffPointsToObjectGroups(DiffPoints DP, int group_distance); static BufferedImage getSubImage(BufferedImage image, Rectangle rectangle); static Offset findDominantOffset(BufferedImage expectedImage, BufferedImage actualImage, double diffThreshold); static BufferedImage getDominantImage(BufferedImage expectedImage, BufferedImage actualImage, Offset offset); static int getSizeRelationType(int expectedWidth, int expectedHeight, int actualWidth, int actualHeight);  }
@Test public void testConvertDiffPointsToObjectGroups() throws Exception { BufferedImage image1 = ImageIO .read(getClass().getResource("ImageUtilsTest_convert_object_groups_to_areas_expected.png")); Rectangle rectangle1 = new Rectangle(0, 0, image1.getWidth(), image1.getHeight()); BufferedImage image2 = ImageIO .read(getClass().getResource("ImageUtilsTest_convert_object_groups_to_areas_actual.png")); Rectangle rectangle2 = new Rectangle(0, 0, image2.getWidth(), image2.getHeight()); ImageComparedResult result = new DefaultImageComparator().compare(image1, rectangle1, image2, rectangle2); List<Point> points = ((DiffPoints) result).getDiffPoints(); DiffPoints diffPoints = new DiffPoints(points, new ArrayList<Point>()); int x = 1; int y = 0; int width = 3; int height = 2; int margin = DEFAULT_GROUP_DISTANCE / 2; Rectangle expected = new Rectangle(x - margin, y - margin, 2 * margin + width, 2 * margin + height); List<ObjectGroup> actual = ImageUtils.convertDiffPointsToObjectGroups(diffPoints, DEFAULT_GROUP_DISTANCE); assertThat(actual.size(), is(1)); assertThat(actual.get(0).getRectangle(), is(expected)); }