-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInputImageLabel.py
92 lines (75 loc) · 3.91 KB
/
InputImageLabel.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
import ImageProcessor
import ImageSelector
from PyQt5.QtCore import QPoint
from PyQt5.QtWidgets import QLabel, QGridLayout, QComboBox, QFrame, QSlider
from PyQt5.QtCore import Qt
FT_COMPONENTS = [["Magnitude", "Phase"], ["Real", "Imaginary"]]
class InputImageLabel(QLabel):
def __init__(self, MainWindow, region_slider, parent=None, label_size = (300, 400), removable = False):
super().__init__(parent)
self.MainWindow = MainWindow
self.removable = removable
self.image = ImageProcessor.ImageProcessor(self, label_size = label_size)
self.image.load_image("Images\\Queen-Elizabeth-II.jpg")
self.image.resize_image()
self.last_mouse_pos = QPoint()
self.ft_label = ImageSelector.ImageSelector(slider= region_slider, label_size= label_size)
self.weight_slider = create_slider(0, 200)
line = create_line()
self.ft_pair_label = QLabel("Weight:")
combobox_label = QLabel("FT Component:")
self.ft_combobox = QComboBox()
self.ft_combobox.addItems(FT_COMPONENTS[0])
self.ft_combobox.currentIndexChanged.connect(MainWindow.mix_images)
self.ft_combobox.currentIndexChanged.connect(lambda: MainWindow.change_ft_component(
self.ft_combobox.currentText(), self.image, self.ft_label))
self.weight_slider.valueChanged.connect(MainWindow.mix_images)
MainWindow.change_ft_component(self.ft_combobox.currentText(), self.image, self.ft_label)
self.setFixedSize(*label_size)
self.image_layout = QGridLayout()
self.image_layout.addWidget(self, 0, 0, 1, 2)
self.image_layout.addWidget(self.ft_label, 0, 3, 1, 2)
self.image_layout.addWidget(self.ft_pair_label, 1, 0, 2, 1)
self.image_layout.addWidget(self.weight_slider, 1, 1, 2, 1)
self.image_layout.addWidget(line, 1, 2, 2, 1)
self.image_layout.addWidget(combobox_label, 1, 3, 2, 1)
self.image_layout.addWidget(self.ft_combobox, 1, 4, 2, 1)
def mouseDoubleClickEvent(self, event):
if event.button() == Qt.LeftButton:
self.image.load_image()
elif event.button() == Qt.RightButton and self.removable:
self.image.image = None
self.image.update_display()
self.MainWindow.resize_images()
self.MainWindow.change_ft_component(self.ft_combobox.currentText(), self.image, self.ft_label)
self.MainWindow.mix_images()
self.weight_slider.setValue(100)
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.last_mouse_pos = event.pos()
self.initial_brightness = self.image.brightness
self.initial_contrast = self.image.contrast
def mouseMoveEvent(self, event):
if self.image.image is not None and event.buttons() & Qt.LeftButton:
delta = event.pos() - self.last_mouse_pos
self.last_mouse_pos = event.pos()
new_brightness = self.initial_brightness - delta.y() /10
new_contrast = max(0.1, self.initial_contrast + delta.x()/10 * 0.01)
brightness_min, brightness_max = -50, 50
contrast_min, contrast_max = 0.5, 2.0
self.image.brightness = max(brightness_min, min(brightness_max, new_brightness))
self.image.contrast = max(contrast_min, min(contrast_max, new_contrast))
self.image.adjust_brightness_contrast()
def create_line(horizontal = False, thick_line = True):
line = QFrame()
line.setFrameShape(QFrame.HLine) if horizontal else line.setFrameShape(QFrame.VLine)
line.setFrameShadow(QFrame.Sunken)
if thick_line: line.setStyleSheet("border: 1px solid purple;")
return line
def create_slider(minimum, maximum):
slider = QSlider()
slider.setOrientation(Qt.Horizontal)
slider.setMinimum(minimum)
slider.setMaximum(maximum)
slider.setValue(maximum // 2)
return slider