Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,12 @@
|
|
1 |
import gradio as gr
|
2 |
import cv2
|
3 |
import numpy as np
|
|
|
4 |
|
5 |
-
def exposure_fusion(
|
6 |
try:
|
7 |
-
#
|
8 |
-
images_cv = [cv2.cvtColor(np.array(
|
9 |
|
10 |
# Align images using AlignMTB
|
11 |
align_mtb = cv2.createAlignMTB()
|
@@ -23,10 +24,10 @@ def exposure_fusion(images):
|
|
23 |
except Exception as e:
|
24 |
return f"Error: {e}"
|
25 |
|
26 |
-
def stabilize_crop_and_exposure_fusion(
|
27 |
try:
|
28 |
-
#
|
29 |
-
images_cv = [cv2.cvtColor(np.array(
|
30 |
|
31 |
# Align images using AlignMTB
|
32 |
align_mtb = cv2.createAlignMTB()
|
@@ -37,7 +38,6 @@ def stabilize_crop_and_exposure_fusion(images):
|
|
37 |
bounding_rects = []
|
38 |
for img in aligned_images:
|
39 |
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
40 |
-
# Pixels above a small threshold are considered valid
|
41 |
_, mask = cv2.threshold(gray, 10, 255, cv2.THRESH_BINARY)
|
42 |
coords = cv2.findNonZero(mask)
|
43 |
if coords is not None:
|
@@ -72,14 +72,13 @@ def stabilize_crop_and_exposure_fusion(images):
|
|
72 |
except Exception as e:
|
73 |
return f"Error: {e}"
|
74 |
|
75 |
-
def process_images(
|
76 |
-
if not
|
77 |
return None
|
78 |
-
# If advanced option is selected, use stabilization & cropping before fusion.
|
79 |
if advanced:
|
80 |
-
return stabilize_crop_and_exposure_fusion(
|
81 |
else:
|
82 |
-
return exposure_fusion(
|
83 |
|
84 |
# Gradio Interface: Upload multiple images and choose the processing method.
|
85 |
inputs = [
|
|
|
1 |
import gradio as gr
|
2 |
import cv2
|
3 |
import numpy as np
|
4 |
+
from PIL import Image
|
5 |
|
6 |
+
def exposure_fusion(image_paths):
|
7 |
try:
|
8 |
+
# Open images from filepaths and convert to OpenCV format (BGR)
|
9 |
+
images_cv = [cv2.cvtColor(np.array(Image.open(path)), cv2.COLOR_RGB2BGR) for path in image_paths]
|
10 |
|
11 |
# Align images using AlignMTB
|
12 |
align_mtb = cv2.createAlignMTB()
|
|
|
24 |
except Exception as e:
|
25 |
return f"Error: {e}"
|
26 |
|
27 |
+
def stabilize_crop_and_exposure_fusion(image_paths):
|
28 |
try:
|
29 |
+
# Open images from filepaths and convert to OpenCV format (BGR)
|
30 |
+
images_cv = [cv2.cvtColor(np.array(Image.open(path)), cv2.COLOR_RGB2BGR) for path in image_paths]
|
31 |
|
32 |
# Align images using AlignMTB
|
33 |
align_mtb = cv2.createAlignMTB()
|
|
|
38 |
bounding_rects = []
|
39 |
for img in aligned_images:
|
40 |
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
|
|
41 |
_, mask = cv2.threshold(gray, 10, 255, cv2.THRESH_BINARY)
|
42 |
coords = cv2.findNonZero(mask)
|
43 |
if coords is not None:
|
|
|
72 |
except Exception as e:
|
73 |
return f"Error: {e}"
|
74 |
|
75 |
+
def process_images(image_paths, advanced):
|
76 |
+
if not image_paths:
|
77 |
return None
|
|
|
78 |
if advanced:
|
79 |
+
return stabilize_crop_and_exposure_fusion(image_paths)
|
80 |
else:
|
81 |
+
return exposure_fusion(image_paths)
|
82 |
|
83 |
# Gradio Interface: Upload multiple images and choose the processing method.
|
84 |
inputs = [
|