HeshamAI commited on
Commit
1a153fd
·
verified ·
1 Parent(s): 080faf9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -42
app.py CHANGED
@@ -14,9 +14,6 @@ class DicomAnalyzer:
14
  self.image_display1 = None
15
  self.dicom_data1 = None
16
  self.marks1 = []
17
- self.zoom_factor = 1.0
18
- self.offset_x = 0
19
- self.offset_y = 0
20
 
21
  def load_dicom(self, file):
22
  try:
@@ -48,10 +45,6 @@ class DicomAnalyzer:
48
 
49
  def analyze_point(self, image, dicom_data, x, y):
50
  try:
51
- # Map coordinates to original image
52
- x = int((x - self.offset_x) / self.zoom_factor)
53
- y = int((y - self.offset_y) / self.zoom_factor)
54
-
55
  # Create a circular mask
56
  mask = np.zeros_like(image, dtype=np.uint8)
57
  y_indices, x_indices = np.ogrid[:image.shape[0], :image.shape[1]]
@@ -85,23 +78,29 @@ class DicomAnalyzer:
85
  try:
86
  image_copy = image.copy()
87
 
88
- # Map coordinates to original image
89
- x = int((x - self.offset_x) / self.zoom_factor)
90
- y = int((y - self.offset_y) / self.zoom_factor)
91
-
92
  # Draw all previous marks
93
  for mark_x, mark_y in self.marks1:
94
  cv2.circle(image_copy,
95
- (int(mark_x * self.zoom_factor + self.offset_x), int(mark_y * self.zoom_factor + self.offset_y)),
96
- int(self.circle_diameter / 2 * self.zoom_factor),
97
- (255, 255, 0), 1, # Thinner yellow outline
 
 
 
 
 
98
  lineType=cv2.LINE_AA)
99
 
100
  # Draw the new mark
101
  cv2.circle(image_copy,
102
- (int(x * self.zoom_factor + self.offset_x), int(y * self.zoom_factor + self.offset_y)),
103
- int(self.circle_diameter / 2 * self.zoom_factor),
104
- (255, 255, 0), 1, # Thinner yellow outline
 
 
 
 
 
105
  lineType=cv2.LINE_AA)
106
 
107
  # Store the new mark
@@ -187,16 +186,6 @@ class DicomAnalyzer:
187
  self.circle_diameter = value
188
  return f"Circle diameter set to {value}"
189
 
190
- def update_zoom(self, zoom_factor):
191
- self.zoom_factor = zoom_factor
192
- if self.current_image1 is not None:
193
- height, width = self.current_image1.shape
194
- resized = cv2.resize(self.image_display1, None, fx=self.zoom_factor, fy=self.zoom_factor, interpolation=cv2.INTER_LINEAR)
195
- self.offset_x = (resized.shape[1] - width * self.zoom_factor) // 2
196
- self.offset_y = (resized.shape[0] - height * self.zoom_factor) // 2
197
- return resized
198
- return self.image_display1
199
-
200
  def save_results(self):
201
  try:
202
  if not self.results:
@@ -237,14 +226,6 @@ def create_interface():
237
  label="Circle Diameter"
238
  )
239
 
240
- zoom_slider = gr.Slider(
241
- minimum=1.0,
242
- maximum=5.0,
243
- value=1.0,
244
- step=0.1,
245
- label="Zoom Factor"
246
- )
247
-
248
  with gr.Row():
249
  clear_btn = gr.Button("Clear Results")
250
  blank_row_btn = gr.Button("Add Blank Row")
@@ -263,12 +244,6 @@ def create_interface():
263
  outputs=status
264
  )
265
 
266
- zoom_slider.change(
267
- fn=analyzer.update_zoom,
268
- inputs=zoom_slider,
269
- outputs=image1
270
- )
271
-
272
  image1.select(
273
  fn=analyzer.handle_click,
274
  outputs=[image1, results]
@@ -303,4 +278,4 @@ def create_interface():
303
 
304
  if __name__ == "__main__":
305
  interface = create_interface()
306
- interface.launch()
 
14
  self.image_display1 = None
15
  self.dicom_data1 = None
16
  self.marks1 = []
 
 
 
17
 
18
  def load_dicom(self, file):
19
  try:
 
45
 
46
  def analyze_point(self, image, dicom_data, x, y):
47
  try:
 
 
 
 
48
  # Create a circular mask
49
  mask = np.zeros_like(image, dtype=np.uint8)
50
  y_indices, x_indices = np.ogrid[:image.shape[0], :image.shape[1]]
 
78
  try:
79
  image_copy = image.copy()
80
 
 
 
 
 
81
  # Draw all previous marks
82
  for mark_x, mark_y in self.marks1:
83
  cv2.circle(image_copy,
84
+ (int(mark_x), int(mark_y)),
85
+ int(self.circle_diameter / 2),
86
+ (255, 255, 0), 1, # Yellow outer ring (thin)
87
+ lineType=cv2.LINE_AA)
88
+ cv2.circle(image_copy,
89
+ (int(mark_x), int(mark_y)),
90
+ int(self.circle_diameter / 2) - 1,
91
+ (255, 255, 255), 1, # White inner ring (thin)
92
  lineType=cv2.LINE_AA)
93
 
94
  # Draw the new mark
95
  cv2.circle(image_copy,
96
+ (int(x), int(y)),
97
+ int(self.circle_diameter / 2),
98
+ (255, 255, 0), 1, # Yellow outer ring (thin)
99
+ lineType=cv2.LINE_AA)
100
+ cv2.circle(image_copy,
101
+ (int(x), int(y)),
102
+ int(self.circle_diameter / 2) - 1,
103
+ (255, 255, 255), 1, # White inner ring (thin)
104
  lineType=cv2.LINE_AA)
105
 
106
  # Store the new mark
 
186
  self.circle_diameter = value
187
  return f"Circle diameter set to {value}"
188
 
 
 
 
 
 
 
 
 
 
 
189
  def save_results(self):
190
  try:
191
  if not self.results:
 
226
  label="Circle Diameter"
227
  )
228
 
 
 
 
 
 
 
 
 
229
  with gr.Row():
230
  clear_btn = gr.Button("Clear Results")
231
  blank_row_btn = gr.Button("Add Blank Row")
 
244
  outputs=status
245
  )
246
 
 
 
 
 
 
 
247
  image1.select(
248
  fn=analyzer.handle_click,
249
  outputs=[image1, results]
 
278
 
279
  if __name__ == "__main__":
280
  interface = create_interface()
281
+ interface.launch()