• Skip to main content
  • Skip to primary sidebar

ITechOasis

Ease Your IT+Tech Experience!

  • Home
  • All Courses
  • My Account
  • Blog
You are here: Home / Tools / How to Find the Difference Between Two Images Using Python ?

ITechOasis / February 4, 2018

How to Find the Difference Between Two Images Using Python ?

Check Following Code: PIL


#[Optional] Images Variables from command arguments

#from sys import argv

#base_image = argv[1]
#test_image = argv[2]
#result_image= argv[3]

#[Main] 

from PIL import Image,ImageChops,ImageOps
from functools import reduce
import math,operator

# Images Variables 
base_image = "1.jpg"
test_image = "2.jpg"
result_image= "result.jpg"

print("-------------------------------- ")
# Base Image 
baseImage = Image.open(base_image).convert('RGB')
print("Base Image = ",base_image , " : ")
print("Width = ",baseImage.width, "Height = ",baseImage.height)

# Test Image 
testImage = Image.open(test_image).convert('RGB')
print("Test Image = ",test_image , " : ")
print("Width = ",testImage.width, "Height = ",testImage.height)

print("================================ ")

#ITechOasis Image Comparision
diff_Image=ImageChops.difference(baseImage, testImage).convert('RGB')

To Change Difference section color :

#Difference in Color
diffInColor = Image.new('RGB', diff_Image.size, 'red')
newDiff = ImageChops.multiply(diffInColor, diff_Image)

To Check % Image Difference:

#Image_Difference
h = newDiff.histogram()
Image_Difference = math.sqrt(reduce(operator.add,map(lambda h, i: h*(i**2), h, range(256))) / (float(baseImage.size[0]) * baseImage.size[1]))

if newDiff.getbbox() is None: 
 newDiff.save(result_image)
 print ("[Pass] Both Images are Same. Image_Difference = ", Image_Difference)
else:
 newDiff.save(result_image)
 print ("[FAIL] Images are Different ! Image_Difference = ", Image_Difference)

print("================================ ")

Read :

  • Link 1 
  • Link 2 
  • Link 3

 

Filed Under: Tools Tagged With: image processing, PIL, Python

Software Testing – Manual+ Interview

Software Testing – Manual+ Interview

0
20h
I
By ITechOasis In Software Testing
Start Learning
Software Testing – FULL COURSE (Manual + Automation + Interview)
5.00
(2)

Software Testing – FULL COURSE (Manual + Automation + Interview)

1
50h
I
By ITechOasis In Software Testing
Start Learning
Robot Framework with Selenium & Python – UI+API Testing
5.00
(1)

Robot Framework with Selenium & Python – UI+API Testing

3
20h
I
By ITechOasis In Automation
Start Learning
Selenium with Java – Web Automation Framework from Scratch

Selenium with Java – Web Automation Framework from Scratch

2
30h
I
By ITechOasis In Automation
Start Learning
Python for Beginners – Learn Programming from scratch
5.00
(1)

Python for Beginners – Learn Programming from scratch

3
10h
I
By ITechOasis In Programming
₹5000 ₹3000
30% Booked
Add to cart
JAVA for Beginners – Learn Programming from scratch
5.00
(1)

JAVA for Beginners – Learn Programming from scratch

1
15h
I
By ITechOasis In Programming
₹8000 ₹5000
13% Booked
Add to cart

Reader Interactions

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

New title
Software Testing – Manual+ Interview

Software Testing – Manual+ Interview

0
20h
I
By ITechOasis In Software Testing
Start Learning
Software Testing – FULL COURSE (Manual + Automation + Interview)
5.00
(2)

Software Testing – FULL COURSE (Manual + Automation + Interview)

1
50h
I
By ITechOasis In Software Testing
Start Learning
Robot Framework with Selenium & Python – UI+API Testing
5.00
(1)

Robot Framework with Selenium & Python – UI+API Testing

3
20h
I
By ITechOasis In Automation
Start Learning
Selenium with Java – Web Automation Framework from Scratch

Selenium with Java – Web Automation Framework from Scratch

2
30h
I
By ITechOasis In Automation
Start Learning
Python for Beginners – Learn Programming from scratch
5.00
(1)

Python for Beginners – Learn Programming from scratch

3
10h
I
By ITechOasis In Programming
₹5000 ₹3000
30% Booked
Add to cart
JAVA for Beginners – Learn Programming from scratch
5.00
(1)

JAVA for Beginners – Learn Programming from scratch

1
15h
I
By ITechOasis In Programming
₹8000 ₹5000
13% Booked
Add to cart

·

  • About Us
  • Disclaimer
  • Privacy Policy
  • Terms and Services
  • Contact

Login

Register | Lost your password?

Register

Log In | Lost your password?

Reset Password

Lost your password? Please enter your username or email address. You will receive a link to create a new password via email.

Log In | Register

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.