Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colormap preference #3

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions frheed/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
"cyan": "#17becf",
}

CMAP_DICT = {
"jet": "jet",
"rainbow": "rainbow"
}


def get_data_dir(
user: Optional[str] = None,
Expand Down
4 changes: 3 additions & 1 deletion frheed/image_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ def norm_2(arr: np.ndarray) -> np.ndarray:
print(f"Normalized array in {time.time()-t0:.5f} seconds")

t0 = time.time()
cmap = "Spectral"
# cmap = "Spectral"
# cmap = "jet"
# cmap = "COLORMAP_JET"
mapped = apply_cmap(normed, cmap)
print(f"Applied colormap in {time.time()-t0:.5f} seconds")

Expand Down
23 changes: 17 additions & 6 deletions frheed/widgets/camera_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
apply_cmap, to_grayscale, ndarray_to_qpixmap, extend_image, column_to_image,
get_valid_colormaps,
)
from frheed.constants import DATA_DIR
from frheed.constants import (
DATA_DIR, CMAP_DICT)
from frheed.utils import load_settings, save_settings, get_logger


Expand All @@ -60,7 +61,13 @@
MIN_H = 348
MAX_W = 2560
MAX_H = 2560
DEFAULT_CMAP = "Spectral"

""" Valid colormap names: https://matplotlib.org/stable/tutorials/colors/colormaps.html """
# DEFAULT_CMAP = "Spectral" # not a valid name
# DEFAULT_CMAP = "rainbow"
# DEFAULT_CMAP = "jet"
DEFAULT_CMAP = list(CMAP_DICT.values())[0]

DEFAULT_INTERPOLATION = cv2.INTER_CUBIC

logger = get_logger(__name__)
Expand Down Expand Up @@ -277,7 +284,8 @@ def show_frame(self, frame: np.ndarray) -> None:
self.frame_ready.emit(frame) if self.analyze_frames else None

# Apply colormap
frame = apply_cmap(frame, self.colormap)
# frame = apply_cmap(frame, self.colormap)
frame = apply_cmap(frame, self._colormap)

# Store the processed frame
self.frame = frame.copy()
Expand Down Expand Up @@ -306,7 +314,8 @@ def save_image(self) -> None:
filepath = os.path.join(DATA_DIR, filename)

# Save the image
cv2.imwrite(filepath, frame)
# cv2.imwrite(filepath, frame)
cv2.imwrite(filepath, cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))

@pyqtSlot()
def start_or_stop_recording(self) -> None:
Expand Down Expand Up @@ -412,9 +421,11 @@ def colormap(self) -> str:
return self._colormap

@colormap.setter
def colormap(self, colormap: str) -> None:
# def colormap(self, colormap: str) -> None:
def colormap(self, colormap: CMAP_DICT) -> None:
if colormap in get_valid_colormaps():
self._colormap = colormap
# self._colormap = colormap
self.colormap = colormap
# TODO: Update label that shows current colormap

def make_camera_settings_widget(self) -> None:
Expand Down
34 changes: 31 additions & 3 deletions frheed/widgets/rheed_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

from typing import Union
import os
import matplotlib.pyplot

from PyQt5.QtWidgets import (
QWidget,
QGridLayout,
QSizePolicy,
QMenuBar,
QMessageBox
QMessageBox,
QAction,
QActionGroup
)
from PyQt5.QtCore import (
pyqtSlot,
Expand All @@ -24,7 +27,7 @@
from frheed.widgets.selection_widgets import CameraSelection
from frheed.widgets.common_widgets import HSpacer, VSpacer
from frheed.utils import snip_lists
from frheed.constants import DATA_DIR, CONFIG_DIR
from frheed.constants import DATA_DIR, CONFIG_DIR, CMAP_DICT


class RHEEDWidget(QWidget):
Expand Down Expand Up @@ -67,7 +70,25 @@ def __init__(self, parent: QWidget = None):

# "Tools" menu
self.tools_menu = self.menubar.addMenu("&Tools")
self.preferences_item = self.tools_menu.addAction("&Preferences")
# self.preferences_item = self.tools_menu.addAction("&Preferences")
self.preferences_item = self.tools_menu.addMenu("&Preferences")

self.cmap1 = QAction("jet", self)
self.cmap2 = QAction("YlGn", self)
# self.cmap3 = QAction("spring", self)
self.cmap1.setCheckable(True)
self.cmap2.setCheckable(True)
# self.cmap3.setCheckable(True)
self.preferences_item.addAction(self.cmap1)
self.preferences_item.addAction(self.cmap2)
# self.preferences_item.addAction(self.cmap3)
colormap_group = QActionGroup(self)
colormap_group.addAction(self.cmap1)
colormap_group.addAction(self.cmap2)
# colormap_group.addAction(self.cmap3)
self.cmap1.triggered.connect(self.change_cmap)
self.cmap2.triggered.connect(self.change_cmap)
# self.cmap3.triggered.connect(self.change_cmap)

# Add menubar
self.layout.addWidget(self.menubar, 0, 0, 1, 1)
Expand Down Expand Up @@ -184,6 +205,13 @@ def change_camera(self) -> None:
""" Change the active camera. """
self.camera_widget.set_camera(self.cam_selection._cam)

@pyqtSlot()
def change_cmap(self) -> None:
if self.cmap1.isChecked() == True:
self.camera_widget.set_colormap(list(CMAP_DICT.values())[0])
if self.cmap2.isChecked() == True:
self.camera_widget.set_colormap(list(CMAP_DICT.values())[1])

@pyqtSlot()
def live_plots_closed(self) -> None:
self.show_live_plots_item.setChecked(False)
Expand Down
8 changes: 8 additions & 0 deletions run_frheed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from frheed.gui import show
#from frheed.materials import Material

#gasb = Material("GaSb", "Zinc blende")

#print(gasb.compound)

show()