Skip to content

ArtemKudriaC/image-comparison

 
 

logo-trans Download Codacy Badge Build Status Coverage Status BCH compliance PRs Welcome

About

The program in Java that compares any 2 images and shows the differences visually by drawing rectangles. The Usages of the image-comparison can be found here Usage Image Comparison

Requirements

  • Implementation is using only standard core language and platform features, no 3rd party libraries and plagiarized code is permitted.
  • Pixels (with the same coordinates in two images) can be visually similar, but have different values of RGB. 2 pixels are considered to be "different" if they differ more than 10% from each other.
  • The output of the comparison is a copy of one of the images. The differences are outlined with red rectangles as shown below.
  • No third party libraries or borrowed code are in usage.

Building

To clone and build this project, run the following commands:

git clone https://github.com/romankh3/image-comparison
cd image-comparison
./gradlew check jar

This will compile, run the tests, and create a runnable jar at ${projectDir}/build/libs.

Release Notes

2.1.0

  • Added publishing to JCenter

2.0.2

  • fixed bug #11(finally!!)
  • fixed bug #43

2.0.1

  • fixed bug #21

2.0

  • use as a library

1.0

The program in Java that compares any 2 images and shows the differences visually by drawing rectangles.

  • Implementation is using only standard core language and platform features, no 3rd party libraries and plagiarized code is permitted.
  • Pixels (with the same coordinates in two images) can be visually similar, but have different values of RGB. We are only consider 2 pixels to be "different" if the difference between them is more than 10%.
  • The output of the comparison is a copy of one of the images image with differences outlined with red rectangles as shown below.
  • No third party libraries and borrowed code are not using.

Usage

Using the command-line

This library can be used as a command-line utility to compare two images.

After building with ./gradlew jar, you will find the runnable jar at ${projectDir}/build/libs.

To compare two images in files a.png and b.png, for example, run:

java -jar image-comparison.jar a.png b.png

To save the result image in a third file, say comparison.png, just give that file as a third argument:

java -jar image-comparison.jar a.png b.png comparison.png

To show more usage details, run:

java -jar image-comparison.jar -h

Using as a Java library

Dependency

Maven
<dependency>
    <groupId>com.github.romankh3</groupId>
    <artifactId>image-comparison</artifactId>
    <version>2.1.0</version>
</dependency>
Gradle
compile 'com.github.romankh3:image-comparison:2.1.0'

To compare two images programmatically

class Example {
    public static void main( String[] args ) {
        // load the images to be compared
        BufferedImage bufferedImage1 = ImageComparisonTools.readImageFromResources("image1.png");
        BufferedImage bufferedImage2 = ImageComparisonTools.readImageFromResources("image2.png");
        
        // where to save the result (leave null if you want to see the result in the UI)
        File result = new File( "result.png" );
        
        // compare them
        BufferedImage drawnDifferences = new ImageComparison( image1, image2, result ).compareImages();
    }
}

Demo

Run the ./run.sh script to run the demo.

You will get the result of comparing two images. The images, which are using:

Image 1

image1

Image 2

image2

Result

result

License

This project is unlicense - see the LICENSE file for details

Thanks @dee-y for designing this logo

Also if you're interesting - see my other repositories

About

Java Library that compares 2 images with the same sizes and shows the differences visually by drawing rectangles.

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Java 99.5%
  • Shell 0.5%