Spaces:
Runtime error
Runtime error
Commit
·
155378b
1
Parent(s):
02a138c
Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,58 @@
|
|
1 |
import gradio as gr
|
2 |
import cv2
|
3 |
import numpy as np
|
4 |
-
|
5 |
# Define a function that performs the image operation
|
6 |
-
def perform_image_operation(image1, image2):
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
# Convert the result image to PIL format for Gradio display
|
12 |
-
|
13 |
-
|
14 |
|
15 |
# Define the Gradio interface
|
16 |
iface = gr.Interface(
|
17 |
fn=perform_image_operation,
|
18 |
inputs=[
|
19 |
gr.inputs.Image(label="Input Image 1"),
|
20 |
-
gr.inputs.Image(label="Input Image 2")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
],
|
22 |
outputs=gr.outputs.Image(type="pil", label="Blended Image")
|
23 |
)
|
|
|
1 |
import gradio as gr
|
2 |
import cv2
|
3 |
import numpy as np
|
4 |
+
from Utils.Image_stitching import *
|
5 |
# Define a function that performs the image operation
|
6 |
+
def perform_image_operation(image1, image2,image3,image4,image5,image6,image7,image8,image9):
|
7 |
+
for dataset_name, img_files_dataset in dataset_img_files.items():
|
8 |
+
# Retrieve the batch size for the current dataset
|
9 |
+
batch_size = 9
|
10 |
+
|
11 |
+
subfolder_paths = dataset_subfolder_paths[dataset_name]
|
12 |
+
visual_subfolder, analysis_subfolder, preprocess_subfolder, segmented_subfolder, stitched_subfolder, dataframe = subfolder_paths
|
13 |
+
|
14 |
+
# Your existing code here for reading, processing, and saving images
|
15 |
+
|
16 |
+
# Loop through the images in analysis_subfolder and perform image stitching
|
17 |
+
analysis_images = [] # Create an empty list to store image paths from the analysis_folder
|
18 |
+
for root, _, filenames in os.walk(analysis_subfolder):
|
19 |
+
for filename in filenames:
|
20 |
+
if filename.endswith(".png"): # You can adjust the file extension if needed
|
21 |
+
image_path = os.path.join(root, filename)
|
22 |
+
analysis_images.append(image_path)
|
23 |
+
|
24 |
+
num_batches = len(analysis_images) // batch_size
|
25 |
+
|
26 |
+
for batch_idx in range(num_batches):
|
27 |
+
start_idx = batch_idx * batch_size
|
28 |
+
end_idx = start_idx + batch_size
|
29 |
+
batch_img_indices = analysis_images[start_idx:end_idx] # Use images from analysis_folder
|
30 |
+
|
31 |
+
# Call the image_stitching function with the batch of image paths
|
32 |
+
stitched_batch = image_stitching(batch_img_indices)
|
33 |
+
|
34 |
+
# Save the stitched batch image
|
35 |
+
batch_filename = '{}_batch_{}.png'.format(dataset_name, batch_idx) # Include a unique identifier for the batch
|
36 |
+
stitched_batch_img = Image.fromarray(np.uint8(stitched_batch))
|
37 |
+
|
38 |
|
39 |
# Convert the result image to PIL format for Gradio display
|
40 |
+
result_pil_image = cv2.cvtColor(stitched_batch_img, cv2.COLOR_BGR2RGB)
|
41 |
+
return result_pil_image
|
42 |
|
43 |
# Define the Gradio interface
|
44 |
iface = gr.Interface(
|
45 |
fn=perform_image_operation,
|
46 |
inputs=[
|
47 |
gr.inputs.Image(label="Input Image 1"),
|
48 |
+
gr.inputs.Image(label="Input Image 2"),
|
49 |
+
gr.inputs.Image(label="Input Image 3"),
|
50 |
+
gr.inputs.Image(label="Input Image 4"),
|
51 |
+
gr.inputs.Image(label="Input Image 5"),
|
52 |
+
gr.inputs.Image(label="Input Image 6"),
|
53 |
+
gr.inputs.Image(label="Input Image 7"),
|
54 |
+
gr.inputs.Image(label="Input Image 8"),
|
55 |
+
gr.inputs.Image(label="Input Image 9")
|
56 |
],
|
57 |
outputs=gr.outputs.Image(type="pil", label="Blended Image")
|
58 |
)
|