0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-14 03:31:50 +02:00

feat: rotation of the image to the left/right by 90, 180, 270 degree

This commit is contained in:
wyzula-jan
2023-09-08 14:24:17 +02:00
parent 4fa8d46631
commit 327f6b3df3

View File

@ -9,7 +9,6 @@ import zmq
from PyQt5.QtCore import pyqtSlot, pyqtSignal from PyQt5.QtCore import pyqtSlot, pyqtSignal
from PyQt5.QtWidgets import QWidget from PyQt5.QtWidgets import QWidget
from pyqtgraph.Qt import uic from pyqtgraph.Qt import uic
from scipy.stats import multivariate_normal from scipy.stats import multivariate_normal
@ -58,7 +57,9 @@ class EigerPlot(QWidget):
self.doubleSpinBox_hist_max.valueChanged.connect(self.update_hist) self.doubleSpinBox_hist_max.valueChanged.connect(self.update_hist)
# ComboBoxes # ComboBoxes
self.comboBox_rotation.currentIndexChanged.connect(lambda k: self.rotate_data(k)) self.comboBox_rotation.currentIndexChanged.connect(
lambda k: self.rotate_data(self.image, k)
)
# Signal/Slots # Signal/Slots
self.update_signale.connect(self.on_image_update) self.update_signale.connect(self.on_image_update)
@ -74,19 +75,35 @@ class EigerPlot(QWidget):
self.hist_levels[1] + 0.1 * self.hist_levels[1], self.hist_levels[1] + 0.1 * self.hist_levels[1],
) )
def rotate_data(self, k: int = 0) -> None: def rotate_data(self, data, k: int = 0, direction: int = 0) -> np.ndarray:
"""Rotate image by 90 degrees k times. """Rotate image by 90 degrees k times.
Args: Args:
k(int): Number of times to rotate image by 90 degrees. k(int): Number of times to rotate image by 90 degrees.
direction(int): 0 for clockwise, 1 for counter-clockwise
""" """
self.image = np.rot90(self.image, k=k)
if direction == 0:
data = np.rot90(self.image, k=k, axes=(1, 0))
else:
data = np.rot90(self.image, k=k, axes=(0, 1))
return data
def transpose_data(self): def transpose_data(self):
self.image = np.transpose(self.image) self.image = np.transpose(self.image)
@pyqtSlot() @pyqtSlot()
def on_image_update(self): def on_image_update(self):
if self.comboBox_rotation.currentIndex() == 0: # non rotated image
self.imageItem.setImage(self.image, autoLevels=False)
else: # rotated image
self.image = self.rotate_data(
data=self.image,
k=self.comboBox_rotation.currentIndex(),
direction=self.comboBox_direction.currentIndex(),
)
self.imageItem.setImage(self.image, autoLevels=False) self.imageItem.setImage(self.image, autoLevels=False)
############################### ###############################