Update app.py
Browse files
app.py
CHANGED
|
@@ -83,7 +83,6 @@ class DicomAnalyzer:
|
|
| 83 |
return self.update_display()
|
| 84 |
|
| 85 |
def update_display(self):
|
| 86 |
-
"""Update display with current zoom and pan"""
|
| 87 |
try:
|
| 88 |
if self.original_display is None:
|
| 89 |
return None
|
|
@@ -93,33 +92,35 @@ class DicomAnalyzer:
|
|
| 93 |
new_height = int(height * self.zoom_factor)
|
| 94 |
new_width = int(width * self.zoom_factor)
|
| 95 |
|
| 96 |
-
# Update max pan values
|
| 97 |
-
self.max_pan_x = max(0, new_width - width)
|
| 98 |
-
self.max_pan_y = max(0, new_height - height)
|
| 99 |
-
|
| 100 |
# Create zoomed image
|
| 101 |
zoomed = cv2.resize(self.original_display, (new_width, new_height),
|
| 102 |
interpolation=cv2.INTER_CUBIC)
|
| 103 |
|
| 104 |
-
# Draw marks
|
| 105 |
for x, y, diameter in self.marks:
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
|
|
|
| 109 |
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
2, # Increased thickness
|
| 117 |
-
lineType=cv2.LINE_AA)
|
| 118 |
|
| 119 |
-
# Extract visible portion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
visible = zoomed[
|
| 121 |
-
self.pan_y:self.pan_y +
|
| 122 |
-
self.pan_x:self.pan_x +
|
| 123 |
]
|
| 124 |
|
| 125 |
return visible
|
|
@@ -131,8 +132,8 @@ class DicomAnalyzer:
|
|
| 131 |
"""Handle keyboard inputs for pan"""
|
| 132 |
try:
|
| 133 |
print(f"Handling key press: {key}") # Debug print
|
| 134 |
-
#
|
| 135 |
-
pan_amount = int(
|
| 136 |
|
| 137 |
if key == 'ArrowLeft':
|
| 138 |
self.pan_x = max(0, self.pan_x - pan_amount)
|
|
@@ -147,8 +148,7 @@ class DicomAnalyzer:
|
|
| 147 |
except Exception as e:
|
| 148 |
print(f"Error handling keyboard input: {str(e)}")
|
| 149 |
return self.display_image
|
| 150 |
-
|
| 151 |
-
def analyze_roi(self, evt: gr.SelectData):
|
| 152 |
try:
|
| 153 |
if self.current_image is None:
|
| 154 |
return None, "No image loaded"
|
|
@@ -275,7 +275,7 @@ def create_interface():
|
|
| 275 |
|
| 276 |
results_display = gr.Textbox(label="Results", interactive=False)
|
| 277 |
file_output = gr.File(label="Download Results")
|
| 278 |
-
key_press = gr.Textbox(visible=False, elem_id="key_press")
|
| 279 |
|
| 280 |
# Instructions
|
| 281 |
gr.Markdown("""
|
|
@@ -368,11 +368,4 @@ def create_interface():
|
|
| 368 |
}
|
| 369 |
}
|
| 370 |
});
|
| 371 |
-
</script
|
| 372 |
-
""")
|
| 373 |
-
|
| 374 |
-
return interface
|
| 375 |
-
|
| 376 |
-
if __name__ == "__main__":
|
| 377 |
-
interface = create_interface()
|
| 378 |
-
interface.launch()
|
|
|
|
| 83 |
return self.update_display()
|
| 84 |
|
| 85 |
def update_display(self):
|
|
|
|
| 86 |
try:
|
| 87 |
if self.original_display is None:
|
| 88 |
return None
|
|
|
|
| 92 |
new_height = int(height * self.zoom_factor)
|
| 93 |
new_width = int(width * self.zoom_factor)
|
| 94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
# Create zoomed image
|
| 96 |
zoomed = cv2.resize(self.original_display, (new_width, new_height),
|
| 97 |
interpolation=cv2.INTER_CUBIC)
|
| 98 |
|
| 99 |
+
# Draw marks on the zoomed image
|
| 100 |
for x, y, diameter in self.marks:
|
| 101 |
+
# Calculate zoomed coordinates
|
| 102 |
+
zoomed_x = int(x * self.zoom_factor)
|
| 103 |
+
zoomed_y = int(y * self.zoom_factor)
|
| 104 |
+
zoomed_diameter = int(diameter * self.zoom_factor)
|
| 105 |
|
| 106 |
+
cv2.circle(zoomed,
|
| 107 |
+
(zoomed_x, zoomed_y),
|
| 108 |
+
zoomed_diameter // 2,
|
| 109 |
+
(255, 255, 0), # BGR: Yellow
|
| 110 |
+
2,
|
| 111 |
+
lineType=cv2.LINE_AA)
|
|
|
|
|
|
|
| 112 |
|
| 113 |
+
# Extract visible portion considering pan
|
| 114 |
+
visible_height = min(height, new_height)
|
| 115 |
+
visible_width = min(width, new_width)
|
| 116 |
+
|
| 117 |
+
# Ensure pan values don't exceed bounds
|
| 118 |
+
self.pan_x = min(self.pan_x, max(0, new_width - width))
|
| 119 |
+
self.pan_y = min(self.pan_y, max(0, new_height - height))
|
| 120 |
+
|
| 121 |
visible = zoomed[
|
| 122 |
+
self.pan_y:self.pan_y + visible_height,
|
| 123 |
+
self.pan_x:self.pan_x + visible_width
|
| 124 |
]
|
| 125 |
|
| 126 |
return visible
|
|
|
|
| 132 |
"""Handle keyboard inputs for pan"""
|
| 133 |
try:
|
| 134 |
print(f"Handling key press: {key}") # Debug print
|
| 135 |
+
# Reduce pan amount for finer control
|
| 136 |
+
pan_amount = int(10 * self.zoom_factor)
|
| 137 |
|
| 138 |
if key == 'ArrowLeft':
|
| 139 |
self.pan_x = max(0, self.pan_x - pan_amount)
|
|
|
|
| 148 |
except Exception as e:
|
| 149 |
print(f"Error handling keyboard input: {str(e)}")
|
| 150 |
return self.display_image
|
| 151 |
+
def analyze_roi(self, evt: gr.SelectData):
|
|
|
|
| 152 |
try:
|
| 153 |
if self.current_image is None:
|
| 154 |
return None, "No image loaded"
|
|
|
|
| 275 |
|
| 276 |
results_display = gr.Textbox(label="Results", interactive=False)
|
| 277 |
file_output = gr.File(label="Download Results")
|
| 278 |
+
key_press = gr.Textbox(visible=False, elem_id="key_press")
|
| 279 |
|
| 280 |
# Instructions
|
| 281 |
gr.Markdown("""
|
|
|
|
| 368 |
}
|
| 369 |
}
|
| 370 |
});
|
| 371 |
+
</script><span class="ml-2" /><span class="inline-block w-3 h-3 rounded-full bg-neutral-a12 align-middle mb-[0.1rem]" />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|