Synch both image zoomsé
Browse files
app.py
CHANGED
@@ -279,26 +279,22 @@ def gradio_interface():
|
|
279 |
)
|
280 |
|
281 |
|
282 |
-
def handle_zoom(current_image, zoomed_state_input, original_image, event: gr.SelectData):
|
283 |
"""Toggle between zoomed and original image based on click events."""
|
284 |
|
285 |
-
#
|
286 |
-
if isinstance(zoomed_state_input, gr.State)
|
287 |
-
zoomed_state = zoomed_state_input.value
|
288 |
-
else:
|
289 |
-
zoomed_state = zoomed_state_input
|
290 |
|
291 |
if zoomed_state:
|
292 |
-
return
|
293 |
-
value=original_image,
|
294 |
-
|
295 |
-
width=image_width,
|
296 |
-
|
297 |
-
)
|
298 |
|
299 |
start_row, start_col = event.index[1], event.index[0]
|
300 |
zoom_size = max(10, min(current_image.shape[:2]) // 10)
|
301 |
-
|
302 |
row_start, row_end = max(start_row - zoom_size, 0), min(start_row + zoom_size, current_image.shape[0])
|
303 |
col_start, col_end = max(start_col - zoom_size, 0), min(start_col + zoom_size, current_image.shape[1])
|
304 |
|
@@ -327,10 +323,18 @@ def gradio_interface():
|
|
327 |
output_image[row_start_upscaled:row_end_upscaled, col_start_upscaled:col_end_upscaled] = \
|
328 |
zoomed_area_upscaled[row_start_zoomed:row_end_zoomed, col_start_zoomed:col_end_zoomed]
|
329 |
|
330 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
331 |
|
332 |
-
image_a.select(handle_zoom, [image_a, zoomed_state_a, state_segmented_a], [image_a, zoomed_state_a])
|
333 |
-
image_b.select(handle_zoom, [image_b, zoomed_state_b, state_segmented_b], [image_b, zoomed_state_b])
|
334 |
|
335 |
with gr.Tab("🏆 Leaderboard", id=1) as leaderboard_tab:
|
336 |
rankings_table = gr.Dataframe(
|
|
|
279 |
)
|
280 |
|
281 |
|
282 |
+
def handle_zoom(current_image, zoomed_state_input, original_image, other_image, event: gr.SelectData):
|
283 |
"""Toggle between zoomed and original image based on click events."""
|
284 |
|
285 |
+
# Determine the current zoom state
|
286 |
+
zoomed_state = zoomed_state_input.value if isinstance(zoomed_state_input, gr.State) else zoomed_state_input
|
|
|
|
|
|
|
287 |
|
288 |
if zoomed_state:
|
289 |
+
return (
|
290 |
+
gr.Image(value=original_image, label="Image", width=image_width, height=image_height),
|
291 |
+
False,
|
292 |
+
gr.Image(value=other_image, label="Image", width=image_width, height=image_height),
|
293 |
+
False
|
294 |
+
)
|
295 |
|
296 |
start_row, start_col = event.index[1], event.index[0]
|
297 |
zoom_size = max(10, min(current_image.shape[:2]) // 10)
|
|
|
298 |
row_start, row_end = max(start_row - zoom_size, 0), min(start_row + zoom_size, current_image.shape[0])
|
299 |
col_start, col_end = max(start_col - zoom_size, 0), min(start_col + zoom_size, current_image.shape[1])
|
300 |
|
|
|
323 |
output_image[row_start_upscaled:row_end_upscaled, col_start_upscaled:col_end_upscaled] = \
|
324 |
zoomed_area_upscaled[row_start_zoomed:row_end_zoomed, col_start_zoomed:col_end_zoomed]
|
325 |
|
326 |
+
# Apply the same zoom to the other image
|
327 |
+
other_output_image = grey_image.copy()
|
328 |
+
other_zoomed_area = other_image[row_start:row_end, col_start:col_end]
|
329 |
+
other_zoomed_area_upscaled = np.kron(other_zoomed_area, np.ones((upscale_factor, upscale_factor, 1)))
|
330 |
+
|
331 |
+
other_output_image[row_start_upscaled:row_end_upscaled, col_start_upscaled:col_end_upscaled] = \
|
332 |
+
other_zoomed_area_upscaled[row_start_zoomed:row_end_zoomed, col_start_zoomed:col_end_zoomed]
|
333 |
+
|
334 |
+
return output_image, True, other_output_image, True
|
335 |
|
336 |
+
image_a.select(handle_zoom, [image_a, zoomed_state_a, state_segmented_a, state_segmented_b], [image_a, zoomed_state_a, image_b, zoomed_state_b])
|
337 |
+
image_b.select(handle_zoom, [image_b, zoomed_state_b, state_segmented_b, state_segmented_a], [image_b, zoomed_state_b, image_a, zoomed_state_a])
|
338 |
|
339 |
with gr.Tab("🏆 Leaderboard", id=1) as leaderboard_tab:
|
340 |
rankings_table = gr.Dataframe(
|