├── .gitignore
├── .idea
└── vcs.xml
├── README.md
├── pom.xml
└── src
└── main
├── java
└── com
│ └── github
│ └── romankh3
│ └── usage
│ └── imagecomparison
│ └── Main.java
└── resources
├── image1.png
└── image2.png
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/*
2 | build/*
3 | *.iml
4 | out/*
5 | .gradle/*
6 | target/*
7 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Usage of Image-Comparison
2 | Examples of the usage [image-comparison](https://github.com/romankh3/image-comparison) project.
3 |
4 | # Description
5 | The main idea is to show how to use this comparison tool.
6 |
7 | ## Dependency
8 | It's easy to add dependency.
9 |
10 | **Latest version is `4.1.0`**
11 |
12 | ### Maven
13 | ```xml
14 |
15 | com.github.romankh3
16 | image-comparison
17 | 4.1.0
18 |
19 | ```
20 |
21 | ### Gradle
22 | ```groovy
23 | compile 'com.github.romankh3:image-comparison:4.1.0'
24 | ```
25 |
26 | ## Code
27 | See the example of the usage below:
28 | ```java
29 | public class Main {
30 |
31 | public static void main(String[] args) {
32 | // load the images to be compared
33 | BufferedImage bufferedImage1 = ImageComparisonUtil.readImageFromResources("image1.png");
34 | BufferedImage bufferedImage2 = ImageComparisonUtil.readImageFromResources("image2.png");
35 |
36 | // where to save the result (leave null if you want to see the result in the UI)
37 | File resultDestination = new File( "result.png" );
38 |
39 | //Create ImageComparison object for it.
40 | ImageComparison imageComparison = new ImageComparison( bufferedImage1, bufferedImage2, resultDestination );
41 |
42 | //Can be used another constructor for it, without destination.
43 | new ImageComparison("image1.png", "image2.png");
44 | //or
45 | new ImageComparison(bufferedImage1, bufferedImage2);
46 |
47 |
48 |
49 | //Also can be configured BEFORE comparing next properties:
50 |
51 | //Threshold - it's the max distance between non-equal pixels. By default it's 5.
52 | imageComparison.setThreshold(10);
53 | imageComparison.getThreshold();
54 |
55 | //RectangleListWidth - Width of the line that is drawn in the rectangle. By default it's 1.
56 | imageComparison.setRectangleLineWidth(5);
57 | imageComparison.getRectangleLineWidth();
58 |
59 | //Destination. Before comparing also can be added destination file for result image.
60 | imageComparison.setDestination(resultDestination);
61 | imageComparison.getDestination();
62 |
63 | //MaximalRectangleCount - It means that would get first x biggest rectangles for drawing.
64 | // by default all the rectangles would be drawn.
65 | imageComparison.setMaximalRectangleCount(10);
66 | imageComparison.getMaximalRectangleCount();
67 |
68 | //MinimalRectangleSize - The number of the minimal rectangle size. Count as (width x height).
69 | // by default it's 1.
70 | imageComparison.setMinimalRectangleSize(100);
71 | imageComparison.getMinimalRectangleSize();
72 |
73 | //After configuring the ImageComparison object, can be executed compare() method:
74 | ImageComparisonResult comparisonResult = imageComparison.compareImages();
75 |
76 | //Can be found ComparisonState.
77 | ImageComparisonState comparisonState = comparisonResult.getImageComparisonState();
78 |
79 | //And Result Image
80 | BufferedImage resultImage = comparisonResult.getResult();
81 |
82 | //Image can be saved after comparison, using ImageComparisonUtil.
83 | ImageComparisonUtil.saveImage(resultDestination, resultImage);
84 | }
85 | }
86 | ```
87 |
88 | # Contribution
89 | Feel free to create Pull-Request of the example of the usage `image-comparison` tool.
90 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.github.romankh3
8 | usage-image-comparison
9 | 1.0-SNAPSHOT
10 |
11 |
12 | 1.8
13 | 1.8
14 |
15 |
16 |
17 |
18 | com.github.romankh3
19 | image-comparison
20 | 4.3.0
21 |
22 |
23 |
24 | org.mockito
25 | mockito-core
26 | 2.26.0
27 | test
28 |
29 |
30 | junit
31 | junit
32 | 4.13.1
33 | test
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/src/main/java/com/github/romankh3/usage/imagecomparison/Main.java:
--------------------------------------------------------------------------------
1 | package com.github.romankh3.usage.imagecomparison;
2 |
3 | import com.github.romankh3.image.comparison.ImageComparison;
4 | import com.github.romankh3.image.comparison.ImageComparisonUtil;
5 | import com.github.romankh3.image.comparison.model.ImageComparisonResult;
6 | import com.github.romankh3.image.comparison.model.ImageComparisonState;
7 | import java.awt.image.BufferedImage;
8 | import java.io.File;
9 |
10 | /**
11 | * Main class for showing the usage.
12 | */
13 | public class Main {
14 |
15 | public static void main(String[] args) {
16 | // load the images to be compared
17 | BufferedImage bufferedImage1 = ImageComparisonUtil.readImageFromResources("image1.png");
18 | BufferedImage bufferedImage2 = ImageComparisonUtil.readImageFromResources("image2.png");
19 |
20 | // where to save the result (leave null if you want to see the result in the UI)
21 | File resultDestination = new File("result.png");
22 |
23 | //Create ImageComparison object for it.
24 | ImageComparison imageComparison = new ImageComparison(bufferedImage1, bufferedImage2, resultDestination);
25 |
26 | //Can be used another constructor for it, without destination.
27 | new ImageComparison("image1.png", "image2.png");
28 | //or
29 | new ImageComparison(bufferedImage1, bufferedImage2);
30 |
31 | //Also can be configured BEFORE comparing next properties:
32 |
33 | //Threshold - it's the max distance between non-equal pixels. By default it's 5.
34 | imageComparison.setThreshold(10);
35 | imageComparison.getThreshold();
36 |
37 | //RectangleListWidth - Width of the line that is drawn in the rectangle. By default it's 1.
38 | imageComparison.setRectangleLineWidth(5);
39 | imageComparison.getRectangleLineWidth();
40 |
41 | //Destination. Before comparing also can be added destination file for result image.
42 | imageComparison.setDestination(resultDestination);
43 | imageComparison.getDestination();
44 |
45 | //MaximalRectangleCount - It means that would get first x biggest rectangles for drawing.
46 | // by default all the rectangles would be drawn.
47 | imageComparison.setMaximalRectangleCount(10);
48 | imageComparison.getMaximalRectangleCount();
49 |
50 | //MinimalRectangleSize - The number of the minimal rectangle size. Count as (width x height).
51 | // by default it's 1.
52 | imageComparison.setMinimalRectangleSize(100);
53 | imageComparison.getMinimalRectangleSize();
54 |
55 | //After configuring the ImageComparison object, can be executed compare() method:
56 | ImageComparisonResult comparisonResult = imageComparison.compareImages();
57 |
58 | //Can be found ComparisonState.
59 | ImageComparisonState comparisonState = comparisonResult.getImageComparisonState();
60 |
61 | //And Result Image
62 | BufferedImage resultImage = comparisonResult.getResult();
63 |
64 | //Image can be saved after comparison, using ImageComparisonUtil.
65 | ImageComparisonUtil.saveImage(resultDestination, resultImage);
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/main/resources/image1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/romankh3/usage-image-comparison/30281abf805a3269d5b1f935070074bac03c8788/src/main/resources/image1.png
--------------------------------------------------------------------------------
/src/main/resources/image2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/romankh3/usage-image-comparison/30281abf805a3269d5b1f935070074bac03c8788/src/main/resources/image2.png
--------------------------------------------------------------------------------