ImageUtils { static List<Rectangle> convertSizeDiffPointsToAreas(List<Point> sizeDiffPoints) { List<Rectangle> areas = new ArrayList<Rectangle>(); if (sizeDiffPoints == null || sizeDiffPoints.isEmpty()) { return areas; } Point start = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE); Point end = new Point(Integer.MIN_VALUE, Integer.MIN_VALUE); for (Point point : sizeDiffPoints) { if (point.y == 0 && start.x > point.x) { start.x = point.x; } if (point.x == 0 && start.y > point.y) { start.y = point.y; } if (end.x < point.x) { end.x = point.x; } if (end.y < point.y) { end.y = point.y; } } if (start.x <= end.x) { areas.add(new Rectangle(start.x, 0, end.x - start.x, end.y)); } if (start.y <= end.y) { final int rectMargin = 3; areas.add(new Rectangle(-rectMargin, start.y - rectMargin, end.x + rectMargin * 2, end.y - start.y + rectMargin * 2)); } return areas; } 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 testConvertSizeDiffPointsToAreas() throws Exception { BufferedImage image1 = ImageIO .read(getClass().getResource("ImageUtilsTest_convert_size_diff_points_to_areas_expected.png")); Rectangle rectangle1 = new Rectangle(0, 0, image1.getWidth(), image1.getHeight()); BufferedImage image2 = ImageIO .read(getClass().getResource("ImageUtilsTest_convert_size_diff_points_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> sizeDiffPoints = ((DiffPoints) result).getSizeDiffPoints(); int startX = 21; int startY = 21; int endX = 30; int endY = 30; int rectMargin = 3; List<Rectangle> expected = new ArrayList<Rectangle>(); expected.add(new Rectangle(startX, 0, endX - startX, endY)); expected.add( new Rectangle(-rectMargin, startY - rectMargin, endX + rectMargin * 2, endY - startY + rectMargin * 2)); List<Rectangle> actual = ImageUtils.convertSizeDiffPointsToAreas(sizeDiffPoints); assertThat(actual, is(expected)); }