forked from farcompen/Opencv-Compare-images
-
Notifications
You must be signed in to change notification settings - Fork 0
/
comparing_images.py
75 lines (40 loc) · 1.41 KB
/
comparing_images.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#! /usr/bin python
# -*- coding:UTF-8 -*-
import matplotlib.pyplot as plt
from skimage.measure import structural_similarity as ssim
import numpy as np
import cv2
def MSE (Resim1, Resim2):
hata = np.sum((Resim1.astype("float") - Resim2.astype("float"))**2)
hata /= float(Resim1.shape[0]* Resim1.shape[1])
return hata
def resim_karsilastir(Resim1, Resim2, title):
m = MSE(Resim1, Resim2)
s = ssim(Resim1, Resim2)
fig = plt.figure(title)
plt.suptitle ("MSE: %.2f, ssim: %.2f " % (m, s ))
#ilk resmi göster
ax = fig.add_subplot(1, 2, 1)
plt.imshow(Resim1, cmap = plt.cm.gray)
plt.axis ("off")
#ikinci resim göster
ax= fig.add_subplot(1, 2, 2)
plt.imshow(Resim2, cmap = plt.cm.gray)
plt.axis("off")
plt.show()
orjinalResim = cv2.imread("resim1.jpg")
kontrastli = cv2.imread("resim2.jpg")
#resimleri gray scale yapalım
orjinal = cv2.cvtColor(orjinalResim, cv2.COLOR_BGR2GRAY)
kontrastligray = cv2.cvtColor(kontrastli, cv2.COLOR_BGR2GRAY)
fig = plt.figure("Images")
Images = ("Orjinal", orjinal), ("Kontrasli", kontrastligray)
for (i, (name, image)) in enumerate (Images):
#resim goster
ax = fig.add_subplot(1, 3, i + 1)
ax.set_title(name)
plt.imshow(image, cmap = plt.cm.gray)
plt.axis("off")
plt.show()
resim_karsilastir(orjinal, orjinal, "orjinal vs orjinal")
resim_karsilastir(orjinal, kontrastligray, "orjinal vs kontrasli")