HeshamAI commited on
Commit
7339e86
·
verified ·
1 Parent(s): 8543088

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -55
app.py CHANGED
@@ -69,7 +69,7 @@ class DicomAnalyzer:
69
  dtype=cv2.CV_8U
70
  )
71
  if len(normalized.shape) == 2:
72
- normalized = cv2.cvtColor(normalized, cv2.COLOR_GRAY2BGR)
73
  return normalized
74
  except Exception as e:
75
  print(f"Error normalizing image: {str(e)}")
@@ -171,63 +171,69 @@ class DicomAnalyzer:
171
  return self.display_image, f"Error analyzing ROI: {str(e)}"
172
 
173
  def update_display(self):
174
- try:
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)
181
-
182
- # Create zoomed image
183
- zoomed = cv2.resize(self.original_display, (new_width, new_height),
184
- interpolation=cv2.INTER_CUBIC)
185
-
186
- # Draw marks
187
- for x, y, diameter in self.marks:
188
- zoomed_x = int(x * 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,
196
- (0, 255, 255), # BGR: Yellow
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
204
- point_x = int(zoomed_x + (zoomed_diameter/2) * np.cos(angle))
205
- point_y = int(zoomed_y + (zoomed_diameter/2) * np.sin(angle))
206
- cv2.circle(zoomed,
207
- (point_x, point_y),
208
- 1,
209
- (0, 255, 255), # BGR: Yellow
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:
229
- print(f"Error updating display: {str(e)}")
230
- return self.original_display
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
 
232
  def format_results(self):
233
  if not self.results:
 
69
  dtype=cv2.CV_8U
70
  )
71
  if len(normalized.shape) == 2:
72
+ normalized = cv2.cvtColor(normalized, cv2.COLOR_GRAY2RGB)
73
  return normalized
74
  except Exception as e:
75
  print(f"Error normalizing image: {str(e)}")
 
171
  return self.display_image, f"Error analyzing ROI: {str(e)}"
172
 
173
  def update_display(self):
174
+ try:
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)
181
+
182
+ # Create zoomed image
183
+ zoomed = cv2.resize(self.original_display, (new_width, new_height),
184
+ interpolation=cv2.INTER_CUBIC)
185
+
186
+ # Convert to BGR for drawing
187
+ zoomed_bgr = cv2.cvtColor(zoomed, cv2.COLOR_RGB2BGR)
188
+
189
+ # Draw marks
190
+ for x, y, diameter in self.marks:
191
+ zoomed_x = int(x * self.zoom_factor)
192
+ zoomed_y = int(y * self.zoom_factor)
193
+ zoomed_diameter = int(diameter * self.zoom_factor)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
194
 
195
+ # Draw main circle in BGR color space
196
+ cv2.circle(zoomed_bgr,
197
+ (zoomed_x, zoomed_y),
198
+ zoomed_diameter // 2,
199
+ (0, 255, 255), # BGR: Yellow
200
+ 1,
201
+ lineType=cv2.LINE_AA)
202
 
203
+ # Draw dots on circle
204
+ num_points = 8
205
+ for i in range(num_points):
206
+ angle = 2 * np.pi * i / num_points
207
+ point_x = int(zoomed_x + (zoomed_diameter/2) * np.cos(angle))
208
+ point_y = int(zoomed_y + (zoomed_diameter/2) * np.sin(angle))
209
+ cv2.circle(zoomed_bgr,
210
+ (point_x, point_y),
211
+ 1,
212
+ (0, 255, 255), # BGR: Yellow
213
+ -1,
214
+ lineType=cv2.LINE_AA)
215
 
216
+ # Convert back to RGB for display
217
+ zoomed = cv2.cvtColor(zoomed_bgr, cv2.COLOR_BGR2RGB)
218
+
219
+ # Calculate pan limits
220
+ self.max_pan_x = max(0, new_width - width)
221
+ self.max_pan_y = max(0, new_height - height)
222
+
223
+ # Ensure pan values are within bounds
224
+ self.pan_x = min(max(0, self.pan_x), self.max_pan_x)
225
+ self.pan_y = min(max(0, self.pan_y), self.max_pan_y)
226
+
227
+ # Extract visible portion
228
+ visible = zoomed[
229
+ int(self.pan_y):int(self.pan_y + height),
230
+ int(self.pan_x):int(self.pan_x + width)
231
+ ]
232
+
233
+ return visible
234
+ except Exception as e:
235
+ print(f"Error updating display: {str(e)}")
236
+ return self.original_display
237
 
238
  def format_results(self):
239
  if not self.results: