-
Notifications
You must be signed in to change notification settings - Fork 0
/
image_1.py
120 lines (102 loc) · 4.46 KB
/
image_1.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
from IMAGE import Ui_Dialog
from PyQt5.QtWidgets import QApplication, QWidget, QInputDialog, QLineEdit, QFileDialog, QDialog
from PyQt5 import QtWidgets
from PyQt5 import QtGui
import sys
from PIL import Image
from skimage.measure import compare_ssim
import imutils
import cv2
import webbrowser
image = Ui_Dialog()
class ui(QDialog):
def __init__(self):
super(ui, self).__init__()
image.setupUi(self)
image.pushButton.clicked.connect(self.file)
image.pushButton_2.clicked.connect(self.convert)
image.pushButton_3.clicked.connect(self.file1)
image.pushButton_4.clicked.connect(self.save_file)
image.pushButton_5.clicked.connect(self.info)
self.show()
self.s="\t\t****INSTRUCTIONS****\n\n1.UPLOAD IMAGE OF SAME SIZE \n\n2.PRESS CHECK TO COMPARE\n\n3.PRESS SAVE TO SAVE FILE" \
" WITH EXT (.JPG)(.PNG) "
image.lineEdit_3.setText(self.s)
self.img1=None
self.temp=True
self.img2 = None
self.modified=None
self.imageA=None
self.imageB = None
def file(self):
self.fname = QFileDialog.getOpenFileName(self, 'Open file', '../ ', "Image Files(*.png *.jpg *.bmp)")
image.lineEdit.setText(self.fname[0])
self.img1 = self.fname[0]
image.lineEdit_3.setText("IMAGE1 LOADED:\n{0}".format(self.img1))
def file1(self):
self.fname1 = QFileDialog.getOpenFileName(self, 'Open file', '../ ', "Image Files(*.png *.jpg *.bmp)")
image.lineEdit_2.setText(self.fname1[0])
print(self.fname1[0])
self.img2 = self.fname1[0]
image.lineEdit_3.append("\n\nIMAGE2 LOADED:\n{0}".format(self.img2))
def info(self):
self.temp=not self.temp
if self.temp== False:
image.lineEdit_3.setText("\t\t ♥♥THANK YOU FOR SUPPORTING♥♥ \n"
"\n\n DHARANISH N H"
"\n\n UNDER GUIDANCE"
"\n\n VIVIAN DAVIS")
webbrowser.open("https://www.linkedin.com/in/dharanish-nh-27426115b")
else:
image.lineEdit_3.setText(self.s)
def convert(self):
try:
self.imageA = cv2.imread(self.img1)
self.imageB = cv2.imread(self.img2)
# convert the images to grayscale
grayA = cv2.cvtColor(self.imageA, cv2.COLOR_BGR2GRAY)
grayB = cv2.cvtColor(self.imageB, cv2.COLOR_BGR2GRAY)
# compute the Structural Similarity Index (SSIM) between the two
# images, ensuring that the difference image is returned
(score, diff) = compare_ssim(grayA, grayB, full=True)
diff = (diff * 255).astype("uint8")
print("SSIM: {}".format(score))
# threshold the difference image, followed by finding contours to
# obtain the regions of the two input images that differ
thresh = cv2.threshold(diff, 0, 255,
cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)
# loop over the contours
for c in cnts:
# compute the bounding box of the contour and then draw the
# bounding box on both input images to represent where the two
# images differ
(x, y, w, h) = cv2.boundingRect(c)
cv2.rectangle(self.imageA, (x, y), (x + w, y + h), (0, 0, 255), 2)
cv2.rectangle(self.imageB, (x, y), (x + w, y + h), (0, 0, 255), 2)
# show the output images
cv2.imshow("Original", self.imageA)
cv2.imshow("Modified", self.imageB)
image.lineEdit_3.setText("SUCCESS")
# cv2.imshow("Diff", diff)
# cv2.imshow("Thresh", thresh)
cv2.waitKey(0)
cv2.destroyAllWindows()
except Exception as e:
image.lineEdit_3.setText(str(e))
def save_file(self):
self.modified = QFileDialog.getSaveFileName(self,'Save File', "Image Files(*.png *.jpg *.bmp)")
print(self.modified[0])
try:
img_save=Image.fromarray(self.imageB)
img_save.save(self.modified[0])
image.lineEdit_3.setText("SAVED")
except Exception as e:
image.lineEdit_3.setText(str(e))
if __name__ == '__main__':
h =QApplication(sys.argv)
n = ui()
n.show()
h.exec_()