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
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.