Skip to content
Snippets Groups Projects
Commit b71f4a16 authored by s224361's avatar s224361
Browse files

Fixed module referencing

parent dc47e981
No related branches found
No related tags found
No related merge requests found
Showing
with 36 additions and 52 deletions
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -5,7 +5,6 @@ from PyQt5.QtWidgets import (
from PyQt5.QtGui import QPixmap, QImage, QShowEvent
from PyQt5.QtCore import Qt
import numpy as np
from mainWindow import MainWindow
from typing import Optional
class AdvancedSettingsWidget(QWidget):
......@@ -14,7 +13,7 @@ class AdvancedSettingsWidget(QWidget):
plus two image previews (contrasted-blurred and cost).
The images maintain aspect ratio upon resize.
"""
def __init__(self, main_window: MainWindow, parent: Optional[QWidget] = None):
def __init__(self, main_window, parent: Optional[QWidget] = None):
"""
Constructor.
"""
......
......@@ -3,12 +3,11 @@ from panZoomGraphicsView import PanZoomGraphicsView
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QMouseEvent, QWheelEvent
from draggableCircleItem import DraggableCircleItem
from circleEditorWidget import CircleEditorWidget
from typing import Optional
# A specialized PanZoomGraphicsView for the circle editor (disk size calibration)
class CircleEditorGraphicsView(PanZoomGraphicsView):
def __init__(self, circle_editor_widget: CircleEditorWidget, parent: Optional[QWidget] = None):
def __init__(self, circle_editor_widget, parent: Optional[QWidget] = None):
"""
Constructor.
"""
......
from skimage.graph import route_through_array
def find_path(cost_image: "numpy.ndarray", points: list) -> list:
"""
Find the optimal path through a cost image between two points.
def find_path(cost_image, points):
Parameters:
cost_image (numpy.ndarray): A 2D array representing the cost of traversing each pixel.
points (list): A list containing two tuples, each representing the
(row, column) coordinates of the seed and target points.
Returns:
list: A list of (row, column) tuples representing the path from the seed to the target point.
Raises:
ValueError: If the points list does not contain exactly two points.
"""
if len(points) != 2:
raise ValueError("Points should be a list of 2 points: seed and target.")
seed_rc, target_rc = points
path_rc, cost = route_through_array(
cost_image,
start=seed_rc,
end=target_rc,
cost_image,
start=seed_rc,
end=target_rc,
fully_connected=True
)
return path_rc
return path_rc
\ No newline at end of file
import math
from scipy.signal import savgol_filter
from PyQt5.QtWidgets import QGraphicsScene, QGraphicsPixmapItem
from PyQt5.QtGui import QPixmap, QColor
from PyQt5.QtCore import Qt, QRectF, QPoint
import math
import numpy as np
from panZoomGraphicsView import PanZoomGraphicsView
from labeledPointItem import LabeledPointItem
......@@ -27,10 +27,10 @@ class ImageGraphicsView(PanZoomGraphicsView):
self.image_item = QGraphicsPixmapItem()
self.scene.addItem(self.image_item)
self.anchor_points = []
self.point_items = []
self.full_path_points = []
self._full_path_xy = []
self.anchor_points = []
self.point_items = []
self.full_path_points = []
self._full_path_xy = []
self.dot_radius = 4
self.path_radius = 1
......@@ -139,7 +139,7 @@ class ImageGraphicsView(PanZoomGraphicsView):
self._rebuild_full_path()
def _insert_anchor_between_subpath(self, x_new: float, y_new: float ):
"""Insert an anchor point between existing anchor points."""
"""Insert an anchor point between existing anchor points.""" # If somehow we have no path yet
# If somehow we have no path yet
if not self._full_path_xy:
self._insert_anchor_point(-1, x_new, y_new)
......@@ -174,23 +174,23 @@ class ImageGraphicsView(PanZoomGraphicsView):
# Walk left
left_anchor_pt = None
i_l = best_idx
while i_l >= 0:
px, py = self._full_path_xy[i_l]
iL = best_idx
while iL >= 0:
px, py = self._full_path_xy[iL]
if is_anchor((px, py)):
left_anchor_pt = (px, py)
break
i_l -= 1
iL -= 1
# Walk right
right_anchor_pt = None
i_r = best_idx
while i_r < len(self._full_path_xy):
px, py = self._full_path_xy[i_r]
iR = best_idx
while iR < len(self._full_path_xy):
px, py = self._full_path_xy[iR]
if is_anchor((px, py)):
right_anchor_pt = (px, py)
break
i_r += 1
iR += 1
# If we can't find distinct anchors on left & right,
# just insert before E.
......@@ -342,7 +342,7 @@ class ImageGraphicsView(PanZoomGraphicsView):
# --------------------------------------------------------------------
# MOUSE EVENTS
# --------------------------------------------------------------------
def mouse_press_event(self, event):
def mousePressEvent(self, event):
"""Handle mouse press events for dragging a point or adding a point."""
if event.button() == Qt.LeftButton:
self._mouse_pressed = True
......@@ -362,9 +362,9 @@ class ImageGraphicsView(PanZoomGraphicsView):
elif event.button() == Qt.RightButton:
self._remove_point_by_click(event.pos())
super().mouse_press_event(event)
super().mousePressEvent(event)
def mouse_move_event(self, event):
def mouseMoveEvent(self, event):
"""Handle mouse move events for dragging a point or dragging the view"""
if self._dragging_idx is not None:
scene_pos = self.mapToScene(event.pos())
......@@ -390,11 +390,11 @@ class ImageGraphicsView(PanZoomGraphicsView):
if dist > self._drag_threshold:
self._was_dragging = True
super().mouse_move_event(event)
super().mouseMoveEvent(event)
def mouse_release_event(self, event):
def mouseReleaseEvent(self, event):
"""Handle mouse release events for dragging a point or adding a point."""
super().mouse_release_event(event)
super().mouseReleaseEvent(event)
if event.button() == Qt.LeftButton and self._mouse_pressed:
self._mouse_pressed = False
self.setCursor(Qt.ArrowCursor)
......@@ -489,4 +489,4 @@ class ImageGraphicsView(PanZoomGraphicsView):
def get_full_path_xy(self):
"""Returns the entire path as a list of (x, y) coordinates."""
return self._full_path_xy
return self._full_path_xy
\ No newline at end of file
......@@ -4,8 +4,7 @@ from PyQt5.QtWidgets import (
QMainWindow, QPushButton, QHBoxLayout,
QVBoxLayout, QWidget, QFileDialog
)
from PyQt5.QtGui import QPixmap, QImage
from PyQt5.QtCore import QCloseEvent
from PyQt5.QtGui import QPixmap, QImage, QCloseEvent
from compute_cost_image import compute_cost_image
from preprocess_image import preprocess_image
from advancedSettingsWidget import AdvancedSettingsWidget
......
......@@ -15,7 +15,7 @@ class PanZoomGraphicsView(QGraphicsView):
# Expands layout
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
def wheel_event(self, event):
def wheelEvent(self, event):
""" Zoom in/out with mouse wheel. """
zoom_in_factor = 1.25
zoom_out_factor = 1 / zoom_in_factor
......@@ -25,25 +25,25 @@ class PanZoomGraphicsView(QGraphicsView):
self.scale(zoom_out_factor, zoom_out_factor)
event.accept()
def mouse_press_event(self, event):
def mousePressEvent(self, event):
""" If left button: Start panning (unless overridden). """
if event.button() == Qt.LeftButton:
self._panning = True
self._pan_start = event.pos()
self.setCursor(Qt.ClosedHandCursor)
super().mouse_press_event(event)
super().mousePressEvent(event)
def mouse_move_event(self, event):
def mouseMoveEvent(self, event):
""" If panning, translate the scene. """
if self._panning and self._pan_start is not None:
delta = event.pos() - self._pan_start
self._pan_start = event.pos()
self.translate(delta.x(), delta.y())
super().mouse_move_event(event)
super().mouseMoveEvent(event)
def mouse_release_event(self, event):
def mouseReleaseEvent(self, event):
""" End panning. """
if event.button() == Qt.LeftButton:
self._panning = False
self.setCursor(Qt.ArrowCursor)
super().mouse_release_event(event)
super().mouseReleaseEvent(event)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment