HeshamAI commited on
Commit
020f6f6
·
verified ·
1 Parent(s): bfb3785

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -21
app.py CHANGED
@@ -96,21 +96,25 @@ class DicomAnalyzer:
96
  def handle_keyboard(self, key):
97
  try:
98
  print(f"Handling key press: {key}")
99
- # Smaller pan amount for smoother movement
100
- pan_amount = int(5 * self.zoom_factor)
 
 
101
 
102
  if key == 'ArrowLeft':
103
  self.pan_x = max(0, self.pan_x - pan_amount)
104
- print(f"Pan X: {self.pan_x}")
105
  elif key == 'ArrowRight':
106
  self.pan_x = min(self.max_pan_x, self.pan_x + pan_amount)
107
- print(f"Pan X: {self.pan_x}")
108
  elif key == 'ArrowUp':
109
  self.pan_y = max(0, self.pan_y - pan_amount)
110
- print(f"Pan Y: {self.pan_y}")
111
  elif key == 'ArrowDown':
112
  self.pan_y = min(self.max_pan_y, self.pan_y + pan_amount)
113
- print(f"Pan Y: {self.pan_y}")
 
 
 
 
 
114
 
115
  return self.update_display()
116
  except Exception as e:
@@ -171,7 +175,6 @@ class DicomAnalyzer:
171
  if self.original_display is None:
172
  return None
173
 
174
- # Calculate zoomed size
175
  height, width = self.original_display.shape[:2]
176
  new_height = int(height * self.zoom_factor)
177
  new_width = int(width * self.zoom_factor)
@@ -186,7 +189,7 @@ class DicomAnalyzer:
186
  zoomed_y = int(y * self.zoom_factor)
187
  zoomed_diameter = int(diameter * self.zoom_factor)
188
 
189
- # Draw yellow circle (BGR format)
190
  cv2.circle(zoomed,
191
  (zoomed_x, zoomed_y),
192
  zoomed_diameter // 2,
@@ -194,7 +197,7 @@ class DicomAnalyzer:
194
  1,
195
  lineType=cv2.LINE_AA)
196
 
197
- # Draw yellow dots
198
  num_points = 8
199
  for i in range(num_points):
200
  angle = 2 * np.pi * i / num_points
@@ -207,23 +210,19 @@ class DicomAnalyzer:
207
  -1,
208
  lineType=cv2.LINE_AA)
209
 
210
- # Extract visible portion
211
- visible_height = min(height, new_height)
212
- visible_width = min(width, new_width)
213
-
214
- # Update max pan values
215
- self.max_pan_x = new_width - width
216
- self.max_pan_y = new_height - height
217
 
218
  # Ensure pan values are within bounds
219
  self.pan_x = min(max(0, self.pan_x), self.max_pan_x)
220
  self.pan_y = min(max(0, self.pan_y), self.max_pan_y)
221
 
222
- # Extract visible portion with pan
223
- start_y = int(self.pan_y)
224
- start_x = int(self.pan_x)
225
- visible = zoomed[start_y:start_y + visible_height,
226
- start_x:start_x + visible_width]
227
 
228
  return visible
229
  except Exception as e:
 
96
  def handle_keyboard(self, key):
97
  try:
98
  print(f"Handling key press: {key}")
99
+ pan_amount = int(5 * self.zoom_factor) # Reduced pan amount for smoother movement
100
+
101
+ original_pan_x = self.pan_x
102
+ original_pan_y = self.pan_y
103
 
104
  if key == 'ArrowLeft':
105
  self.pan_x = max(0, self.pan_x - pan_amount)
 
106
  elif key == 'ArrowRight':
107
  self.pan_x = min(self.max_pan_x, self.pan_x + pan_amount)
 
108
  elif key == 'ArrowUp':
109
  self.pan_y = max(0, self.pan_y - pan_amount)
 
110
  elif key == 'ArrowDown':
111
  self.pan_y = min(self.max_pan_y, self.pan_y + pan_amount)
112
+
113
+ # Print debug info
114
+ print(f"Pan X: {self.pan_x} (was {original_pan_x})")
115
+ print(f"Pan Y: {self.pan_y} (was {original_pan_y})")
116
+ print(f"Max Pan X: {self.max_pan_x}")
117
+ print(f"Max Pan Y: {self.max_pan_y}")
118
 
119
  return self.update_display()
120
  except Exception as e:
 
175
  if self.original_display is None:
176
  return None
177
 
 
178
  height, width = self.original_display.shape[:2]
179
  new_height = int(height * self.zoom_factor)
180
  new_width = int(width * self.zoom_factor)
 
189
  zoomed_y = int(y * self.zoom_factor)
190
  zoomed_diameter = int(diameter * self.zoom_factor)
191
 
192
+ # Draw main circle
193
  cv2.circle(zoomed,
194
  (zoomed_x, zoomed_y),
195
  zoomed_diameter // 2,
 
197
  1,
198
  lineType=cv2.LINE_AA)
199
 
200
+ # Draw dots on circle
201
  num_points = 8
202
  for i in range(num_points):
203
  angle = 2 * np.pi * i / num_points
 
210
  -1,
211
  lineType=cv2.LINE_AA)
212
 
213
+ # Calculate pan limits
214
+ self.max_pan_x = max(0, new_width - width)
215
+ self.max_pan_y = max(0, new_height - height)
 
 
 
 
216
 
217
  # Ensure pan values are within bounds
218
  self.pan_x = min(max(0, self.pan_x), self.max_pan_x)
219
  self.pan_y = min(max(0, self.pan_y), self.max_pan_y)
220
 
221
+ # Extract visible portion
222
+ visible = zoomed[
223
+ int(self.pan_y):int(self.pan_y + height),
224
+ int(self.pan_x):int(self.pan_x + width)
225
+ ]
226
 
227
  return visible
228
  except Exception as e: