ImageUtils { public static BufferedImage getMarkedImage(BufferedImage image, DiffPoints diffPoints) { List<Rectangle> diffAreas = convertDiffPointsToAreas(diffPoints); BufferedImage mark = getMarkImage(); int markerMaxX = image.getWidth(); int markerMaxY = image.getHeight(); int markerMinX = 0; int markerMinY = 0; boolean extend = false; final int imageMargin = 4; final int markWidth = 30; final int markHeight = 25; for (Rectangle area : diffAreas) { if (markerMaxX < (int) area.getMaxX() + imageMargin) { markerMaxX = (int) area.getMaxX() + imageMargin; extend = true; } if (markerMaxY < (int) area.getMaxY() + imageMargin) { markerMaxY = (int) area.getMaxY() + imageMargin; extend = true; } if (markerMinX > area.getMinX() - markWidth) { markerMinX = (int) area.getMinX() - markWidth; extend = true; } if (markerMinY > area.getMinY() - markHeight) { markerMinY = (int) area.getMinY() - markHeight; extend = true; } } BufferedImage markedImg; Graphics2D marker; if (extend) { markedImg = new BufferedImage(markerMaxX - markerMinX, markerMaxY - markerMinY, BufferedImage.TYPE_INT_ARGB); marker = (Graphics2D) markedImg.getGraphics(); marker.setBackground(Color.GRAY); marker.clearRect(0, 0, markerMaxX - markerMinX, markerMaxY - markerMinY); marker.drawImage(image, -markerMinX, -markerMinY, image.getWidth(), image.getHeight(), null); } else { markedImg = getDeepCopyImage(image); marker = (Graphics2D) markedImg.getGraphics(); } for (Rectangle area : diffAreas) { marker.drawImage(mark, area.x - markWidth - markerMinX, area.y - markHeight - markerMinY, null); final float markerR = 1.0f; final float markerG = 0.0f; final float markerB = 0.0f; final float markerA = 0.5f; final float markeStroke = 4.0f; marker.setColor(new Color(markerR, markerG, markerB, markerA)); marker.setStroke(new BasicStroke(markeStroke)); final int markerPadding = 2; marker.drawRect(area.x - markerPadding - markerMinX, area.y - markerPadding - markerMinY, area.width + markerPadding * 2, area.height + markerPadding * 2); } return markedImg; } 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 testGetMarkedImage() throws Exception { BufferedImage image = ImageIO.read(getClass().getResource("web_page_screenshot.png")); List<Point> points = new ArrayList<Point>(); points.add(new Point(100, 100)); DiffPoints diffPoints = new DiffPoints(points, new ArrayList<Point>()); BufferedImage expected = ImageIO.read(getClass().getResource("ImageUtilsTest_get_marked_image.png")); BufferedImage actual = ImageUtils.getMarkedImage(image, diffPoints); assertThat(ImageUtils.imageEquals(expected, actual), is(true)); }