Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
__pycache__/
.vscode
.idea
*.log
42 changes: 19 additions & 23 deletions cmp_viewer/ImageViewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,42 @@
# python -m cmp_viewer.imageviewer
"""ImageViewer is an initial core for opening and viewing CMP image stacks"""
import sys
import cv2
import os
import glob
from cmp_viewer.rgb import *
from cmp_viewer.clusterImgSelect import *
from cmp_viewer.Cluster import *
import nornir_imageregistration
import datetime
from cmp_viewer import models
from PIL import Image
import typing
from numpy.typing import NDArray
import numpy as np
import re
import csv
import cv2
from cmp_viewer.dialogs import ImageSelectDlg
from cmp_viewer.rgb import create_composite_image
from cmp_viewer.cluster_widget import Cluster
from cmp_viewer import utils
from cmp_viewer import mask as mask_module
from cmp_viewer.utils import KMeansSettings, ISODATASettings

from PyQt5.QtWidgets import QApplication, QGraphicsScene, QGraphicsView
from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtWidgets import QScrollArea
from PyQt5.QtWidgets import QWidget
from PyQt5.QtGui import QImage, QColor
from PyQt5.QtWidgets import QMenuBar
from PyQt5.QtGui import QImage
from PyQt5.QtWidgets import QFileDialog
from PyQt5.QtWidgets import QAction
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QGridLayout
from PyQt5.QtWidgets import QLabel
from PyQt5.QtWidgets import QLineEdit
from PyQt5.QtWidgets import QRadioButton
from PyQt5.QtWidgets import QPushButton
from PyQt5.QtWidgets import QVBoxLayout
from PyQt5.QtWidgets import QHBoxLayout
from PyQt5.QtWidgets import QListView
from PyQt5.QtWidgets import QListWidget
from PyQt5.QtWidgets import QComboBox
from PyQt5.QtWidgets import QSlider, QProgressDialog, QListWidgetItem, QColorDialog, QMenu, QInputDialog
from PyQt5 import QtWidgets
from PyQt5 import QtGui
from PyQt5.QtGui import QPixmap, qRgb
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QMessageBox
from functools import partial

__version__ = '1.5.2'
__author__ = "RL Pfeiffer & NQN Studios"
Expand Down Expand Up @@ -104,7 +100,7 @@ def __init__(self, starting_images_folder=None):
self.leftControlsScrollArea.setWidget(self.leftControlsWidget)
self.leftControlsScrollArea.setWidgetResizable(True)
self.leftControlsScrollArea.setFixedWidth(400) # Fixed width to prevent overlap
self.leftControlsScrollArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.leftControlsScrollArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
self.leftControlsScrollArea.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)

# Add the left controls scroll area to the main layout
Expand Down Expand Up @@ -1215,7 +1211,7 @@ def merge_selected_clusters(self):
Merge selected clusters into a single cluster.

This method gathers the checked clusters in the Cluster Mask Visibility list,
calls the merge_clusters method in Cluster.py with those IDs, and invokes
calls the merge_clusters method in cluster_widget.py with those IDs, and invokes
the on_cluster_callback with the updated labels/settings.
"""
if self.clusterview is None or self._masks is None:
Expand All @@ -1233,7 +1229,7 @@ def merge_selected_clusters(self):
QMessageBox.warning(self, "Insufficient Clusters Selected", "Please check at least two clusters to merge in the Cluster Mask Visibility list.")
return

# Call the merge_clusters method in Cluster.py
# Call the merge_clusters method in cluster_widget.py
new_labels, new_settings = self.clusterview.merge_clusters(checked_ids)

if new_labels is None:
Expand Down Expand Up @@ -1303,7 +1299,7 @@ def export_cluster_masks(self):
output_path = os.path.join(output_dir, f"cluster_{cluster_id}_mask")

# Use Cluster class to export the mask
success = self.clusterview.export_cluster_mask(cluster_id, output_path, file_format)
success = mask_module.export_cluster_mask(cluster_id, output_path, file_format)

if not success:
print(f"Failed to export mask for cluster {cluster_id}")
Expand All @@ -1330,7 +1326,7 @@ def show_label_image(self, img, num_labels: int):
self._num_labels = num_labels

# Use Cluster class to prepare the image and get the color table
prepared_img, self._color_table = self.clusterview.prepare_label_image_for_display(img, num_labels)
prepared_img, self._color_table = utils.prepare_label_image_for_display(img, num_labels)
self._clustered_image = prepared_img

# Create QImage from the prepared image
Expand Down Expand Up @@ -1382,7 +1378,7 @@ def show_label_image(self, img, num_labels: int):

# Calculate optimal scale factor
if self.clusterview is not None:
scale_factor = self.clusterview.calculate_optimal_scale_factor(height, width)
scale_factor = utils.calculate_optimal_scale_factor(height, width)
else:
max_pixels = 500000
scale_factor = np.sqrt(max_pixels / (height * width)) if height * width > max_pixels else 1.0
Expand All @@ -1408,7 +1404,7 @@ def show_label_image(self, img, num_labels: int):

# Create mask overlay
if self.clusterview is not None:
overlay = self.clusterview.create_mask_overlay(
overlay = mask_module.create_mask_overlay(
mask, color, self._mask_opacity,
target_width=new_width, target_height=new_height
)
Expand Down Expand Up @@ -1451,7 +1447,7 @@ def show_label_image(self, img, num_labels: int):
smask = any_entry[0]
height, width = smask.shape
if self.clusterview is not None:
scale_factor = self.clusterview.calculate_optimal_scale_factor(height, width)
scale_factor = utils.calculate_optimal_scale_factor(height, width)
else:
max_pixels = 500000
scale_factor = np.sqrt(max_pixels / (height * width)) if height * width > max_pixels else 1.0
Expand All @@ -1475,7 +1471,7 @@ def show_label_image(self, img, num_labels: int):
continue
# Create overlay
if self.clusterview is not None:
overlay = self.clusterview.create_mask_overlay(
overlay = mask_module.create_mask_overlay(
mask, color, self._mask_opacity,
target_width=new_width, target_height=new_height
)
Expand Down
19 changes: 8 additions & 11 deletions cmp_viewer/ImageViewerBU.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
# python -m cmp_viewer.imageviewer
"""ImageViewer is an initial core for opening and viewing CMP image stacks"""
import sys
import cv2
import os
import glob
from cmp_viewer.rgb import *
from cmp_viewer.clusterImgSelect import *
from cmp_viewer.Cluster import *

from cmp_viewer.dialogs import ImageSelectDlg
from cmp_viewer.display import create_composite_image
from cmp_viewer.cluster_widget import *
import nornir_imageregistration
from cmp_viewer import models
from PIL import Image
Expand All @@ -18,31 +17,29 @@
from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtWidgets import QScrollArea
from PyQt5.QtWidgets import QWidget
from PyQt5.QtGui import QImage, QColor
from PyQt5.QtWidgets import QMenuBar
from PyQt5.QtGui import QImage
from PyQt5.QtWidgets import QFileDialog
from PyQt5.QtWidgets import QAction
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QGridLayout
from PyQt5.QtWidgets import QLabel
from PyQt5.QtWidgets import QLineEdit
from PyQt5.QtWidgets import QRadioButton
from PyQt5.QtWidgets import QPushButton
from PyQt5.QtWidgets import QVBoxLayout
from PyQt5.QtWidgets import QHBoxLayout
from PyQt5.QtWidgets import QListView
from PyQt5.QtWidgets import QListWidget
from PyQt5.QtWidgets import QComboBox
from PyQt5.QtWidgets import QSlider, QProgressDialog, QListWidgetItem
from PyQt5 import QtWidgets
from PyQt5 import QtGui
from PyQt5.QtGui import QPixmap, qRgb
from PyQt5.QtWidgets import QMessageBox
from functools import partial

__version__ = '1.0'
__author__ = "RL Pfeiffer & NQN Studios"

from cmp_viewer.utils import KMeansSettings


class ImageViewerUi(QMainWindow):
rawImages = []
fileNameList = []
Expand Down
Loading