Image Processing in Java | Set 14 ( Comparison of two images )
We strongly recommend to refer below posts as a prerequisite of this.
- Image Processing in Java | Set 1 (Read and Write)
- Image Processing In Java | Set 2 (Get and set Pixels)
In this article we will learn how to compare two given images (must be of same dimensions) and print the percentage of difference between them.
Step 1 – Check if dimensions of both the image match.
Step 2 – Get the RGB values of both images.
Step 3 – Calculate the difference in two corresponding pixel of three color components.
Step 4 – Repeat Step 2-3 for each pixel of the images.
Step 5 – Calculate the percentage by dividing the sum of differences with:
- Number of pixels, to obtain the average difference per pixel
- 3, to obtain the average difference per color component
- 255, to obtain a value between 0.0 and 1.0 which can be converted into a percent value
NOTE:Code will not run on online ide since it requires image in drive.
Output : Difference Percentage–>2.843600130405922
Output : Difference Percentage–>6.471412648669786
Output : Difference Percentage–>0.0
This article is contributed by Pratik Agarwal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.