forked from ant-trullo/SegmentTrack_v4.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompareTool.py
105 lines (80 loc) · 3.35 KB
/
CompareTool.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
"""Simple tool to compare two multi frame images
keeping update zoom and frame number.
"""
import numpy as np
import pyqtgraph as pg
# from PyQt5 import QtGui, QtWidgets, QtCore
from PyQt5 import QtGui, QtCore, QtWidgets
class CompareTool(QtWidgets.QWidget):
def __init__(self, img1, img2):
QtWidgets.QWidget.__init__(self)
tabs = QtWidgets.QTabWidget()
tab1 = QtWidgets.QWidget()
tab2 = QtWidgets.QWidget()
# mycmap = np.fromfile("mycmap.bin", "uint16").reshape((10000, 3)) # / 255.0
# colors4map = []
# for k in range(mycmap.shape[0]):
# colors4map.append(mycmap[k, :])
# colors4map[0] = np.array([0, 0, 0])
# mycmap = pg.ColorMap(np.linspace(0, 1, img2.max()), color=colors4map)
frame1 = pg.ImageView(self, name='Frame1')
frame1.ui.menuBtn.hide()
frame1.ui.roiBtn.hide()
frame1.setImage(img1)
frame1.timeLine.sigPositionChanged.connect(self.update_frame2)
frame2 = pg.ImageView(self)
frame2.ui.menuBtn.hide()
frame2.ui.roiBtn.hide()
frame2.setImage(img2)
frame2.view.setXLink('Frame1')
frame2.view.setYLink('Frame1')
frame2.timeLine.sigPositionChanged.connect(self.update_frame1)
frame2.getImageItem().mouseClickEvent = self.get_tag
# frame2.setColorMap(mycmap)
frame_numb_lbl = QtWidgets.QLabel("Frame 0", self)
frame_numb_lbl.setFixedSize(120, 25)
frame1_box = QtWidgets.QHBoxLayout()
frame1_box.addWidget(frame1)
frame2_box = QtWidgets.QHBoxLayout()
frame2_box.addWidget(frame2)
tab1.setLayout(frame1_box)
tab2.setLayout(frame2_box)
tabs.addTab(tab1, "ONE")
tabs.addTab(tab2, "TWO")
layout = QtWidgets.QVBoxLayout()
layout.addWidget(tabs)
layout.addWidget(frame_numb_lbl)
self.frame1 = frame1
self.frame2 = frame2
self.img1 = img1
self.img2 = img2
self.idxs_difr = []
self.frame_numb_lbl = frame_numb_lbl
self.setGeometry(800, 100, 900, 800)
self.setWindowTitle("CompareTool")
self.setWindowIcon(QtGui.QIcon('JD_logo.jpeg'))
self.setLayout(layout)
self.show()
# def closeEvent(self, event):
# """Close the GUI"""
# quit_msg = "Are you sure you want to exit the program?"
# reply = QtGui.QMessageBox.question(self, 'Message', quit_msg, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
#
# if reply == QtGui.QMessageBox.Yes:
# event.accept()
# else:
# event.ignore()
#
def update_frame2(self):
self.frame2.setCurrentIndex(self.frame1.currentIndex)
self.frame_numb_lbl.setText("Frame " + str(self.frame1.currentIndex))
def update_frame1(self):
self.frame1.setCurrentIndex(self.frame2.currentIndex)
def get_tag(self, event):
event.accept()
pos = event.pos()
modifiers = QtWidgets.QApplication.keyboardModifiers()
if modifiers == QtCore.Qt.ShiftModifier:
if self.img2[self.frame2.currentIndex, int(pos.x()), int(pos.y())] != 0:
self.idxs_difr.append(self.img2[self.frame2.currentIndex, int(pos.x()), int(pos.y())])
print(self.idxs_difr)