ImageUtils { public static void removeRedundantRectangles(List<Rectangle> rectangles, int xLimit, int yLimit) { int minLength = 1; List<Rectangle> removeList = new ArrayList<Rectangle>(); for (Rectangle rectangle : rectangles) { reshapeRect(rectangle, xLimit, yLimit); if (rectangle.getX() >= (xLimit - minLength) || rectangle.getY() >= (yLimit - minLength) || rectangle.getWidth() < minLength || rectangle.getHeight() < minLength) { removeList.add(rectangle); } } for (Rectangle removeRect : removeList) { rectangles.remove(removeRect); } } 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 testRemoveRedundantRectangles() throws Exception { List<Rectangle> rectangles = new ArrayList<Rectangle>(); rectangles.add(new Rectangle(0, 0, 89, 89)); rectangles.add(new Rectangle(0, 0, 90, 90)); rectangles.add(new Rectangle(0, 0, 91, 91)); int xLimit = 90; int yLimit = 90; double[][] expected = { { 0.0, 0.0, 89.0, 89.0 }, { 0.0, 0.0, 90.0, 90.0 }, { 0.0, 0.0, 90.0, 90.0 } }; ImageUtils.removeRedundantRectangles(rectangles, xLimit, yLimit); assertThat(rectangles.size(), is(3)); for (int i = 0; i < rectangles.size(); i++) { Rectangle rectangle = rectangles.get(i); assertThat(rectangle.getX(), is(expected[i][0])); assertThat(rectangle.getY(), is(expected[i][1])); assertThat(rectangle.getWidth(), is(expected[i][2])); assertThat(rectangle.getHeight(), is(expected[i][3])); } }