-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRMS.py
More file actions
50 lines (45 loc) · 1.27 KB
/
Copy pathRMS.py
File metadata and controls
50 lines (45 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Aug 22 19:18:45 2019
@author: abhrajyotidas
"""
from PIL import Image
from PIL import ImageChops
import math
def rmsdiff_2011(im1, im2):
"Calculate the root-mean-square difference between two images"
diff = ImageChops.difference(im1, im2)
h = diff.histogram()
sq = (value*(idx**2) for idx, value in enumerate(h))
sum_of_squares = sum(sq)
rms = math.sqrt(sum_of_squares/float(im1.size[0] * im1.size[1]))
return rms
def main():
filename1= "chest-xray.jpg"
filename2= "chest-xary-cipher.jpg"
im1 = Image.open(filename1)
# im1 = intImage(im1)
# print(im1)
im2 = Image.open(filename2)
rms = rmsdiff_2011(im1,im2)
print(rms)
def intImage(image):
im = Image.open(image) # Can be many different formats.
pix = im.load()
image_size=im.size()
image_matrix = []
for width in range(int(image_size[0])):
row = []
for height in range(int(image_size[1])):
try:
row.append(pix[width,height][0])
except:
row=[pix[width,height][0]]
try:
image_matrix.append(row)
except:
image_matrix = [row]
return image_matrix
if __name__ == "__main__":
main()