https://github.com/romankh3/usage-image-comparison
Examples of the usage image-comparison project
https://github.com/romankh3/usage-image-comparison
Last synced: 2 months ago
JSON representation
Examples of the usage image-comparison project
- Host: GitHub
- URL: https://github.com/romankh3/usage-image-comparison
- Owner: romankh3
- Created: 2019-04-12T13:50:59.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-04-05T02:31:16.000Z (about 4 years ago)
- Last Synced: 2023-02-27T01:06:39.057Z (over 2 years ago)
- Language: Java
- Homepage: https://t.me/romankh3
- Size: 130 KB
- Stars: 11
- Watchers: 4
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Usage of Image-Comparison
Examples of the usage [image-comparison](https://github.com/romankh3/image-comparison) project.# Description
The main idea is to show how to use this comparison tool.## Dependency
It's easy to add dependency.**Latest version is `4.1.0`**
### Maven
```xml
com.github.romankh3
image-comparison
4.1.0
```### Gradle
```groovy
compile 'com.github.romankh3:image-comparison:4.1.0'
```## Code
See the example of the usage below:
```java
public class Main {public static void main(String[] args) {
// load the images to be compared
BufferedImage bufferedImage1 = ImageComparisonUtil.readImageFromResources("image1.png");
BufferedImage bufferedImage2 = ImageComparisonUtil.readImageFromResources("image2.png");// where to save the result (leave null if you want to see the result in the UI)
File resultDestination = new File( "result.png" );//Create ImageComparison object for it.
ImageComparison imageComparison = new ImageComparison( bufferedImage1, bufferedImage2, resultDestination );//Can be used another constructor for it, without destination.
new ImageComparison("image1.png", "image2.png");
//or
new ImageComparison(bufferedImage1, bufferedImage2);//Also can be configured BEFORE comparing next properties:
//Threshold - it's the max distance between non-equal pixels. By default it's 5.
imageComparison.setThreshold(10);
imageComparison.getThreshold();//RectangleListWidth - Width of the line that is drawn in the rectangle. By default it's 1.
imageComparison.setRectangleLineWidth(5);
imageComparison.getRectangleLineWidth();//Destination. Before comparing also can be added destination file for result image.
imageComparison.setDestination(resultDestination);
imageComparison.getDestination();//MaximalRectangleCount - It means that would get first x biggest rectangles for drawing.
// by default all the rectangles would be drawn.
imageComparison.setMaximalRectangleCount(10);
imageComparison.getMaximalRectangleCount();//MinimalRectangleSize - The number of the minimal rectangle size. Count as (width x height).
// by default it's 1.
imageComparison.setMinimalRectangleSize(100);
imageComparison.getMinimalRectangleSize();//After configuring the ImageComparison object, can be executed compare() method:
ImageComparisonResult comparisonResult = imageComparison.compareImages();//Can be found ComparisonState.
ImageComparisonState comparisonState = comparisonResult.getImageComparisonState();//And Result Image
BufferedImage resultImage = comparisonResult.getResult();//Image can be saved after comparison, using ImageComparisonUtil.
ImageComparisonUtil.saveImage(resultDestination, resultImage);
}
}
```# Contribution
Feel free to create Pull-Request of the example of the usage `image-comparison` tool.