Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -30,8 +30,9 @@ import io
|
|
| 30 |
import os
|
| 31 |
import tempfile
|
| 32 |
import zipfile
|
|
|
|
|
|
|
| 33 |
|
| 34 |
-
@st.cache_data
|
| 35 |
def zoom_at(img, x, y, zoom):
|
| 36 |
'''
|
| 37 |
Zoom into an image at a specific location.
|
|
@@ -97,7 +98,30 @@ def apply_enhancements(img, x, y, zoom, contrast, brightness, sharpness):
|
|
| 97 |
enhanced_sharpness = ImageEnhance.Sharpness(enhanced_brightness).enhance(sharpness)
|
| 98 |
return enhanced_sharpness
|
| 99 |
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
def create_zip(processed_img, description, params):
|
| 102 |
'''
|
| 103 |
Create a zip archive containing the processed image and annotations.
|
|
@@ -171,9 +195,9 @@ if uploaded_files:
|
|
| 171 |
with image_col:
|
| 172 |
st.subheader("Processed Image")
|
| 173 |
if 'processed_img' in st.session_state:
|
| 174 |
-
st.image(st.session_state.processed_img, caption="Processed Image")
|
| 175 |
else:
|
| 176 |
-
st.image(img, caption="Processed Image")
|
| 177 |
|
| 178 |
with controls_col:
|
| 179 |
st.subheader("Image Controls")
|
|
@@ -192,7 +216,7 @@ if uploaded_files:
|
|
| 192 |
|
| 193 |
# Display Original Image Below
|
| 194 |
st.subheader("Original Image")
|
| 195 |
-
st.image(img,
|
| 196 |
|
| 197 |
# Save and Export Options
|
| 198 |
st.markdown("---")
|
|
|
|
| 30 |
import os
|
| 31 |
import tempfile
|
| 32 |
import zipfile
|
| 33 |
+
import cv2
|
| 34 |
+
import numpy as np
|
| 35 |
|
|
|
|
| 36 |
def zoom_at(img, x, y, zoom):
|
| 37 |
'''
|
| 38 |
Zoom into an image at a specific location.
|
|
|
|
| 98 |
enhanced_sharpness = ImageEnhance.Sharpness(enhanced_brightness).enhance(sharpness)
|
| 99 |
return enhanced_sharpness
|
| 100 |
|
| 101 |
+
def apply_enhancements_cv(img, x, y, zoom, contrast, brightness, sharpness):
|
| 102 |
+
"""
|
| 103 |
+
Use OpenCV for zoom and enhancements.
|
| 104 |
+
"""
|
| 105 |
+
# Convert PIL to OpenCV format
|
| 106 |
+
img_cv = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)
|
| 107 |
+
h, w = img_cv.shape[:2]
|
| 108 |
+
|
| 109 |
+
# Zoom
|
| 110 |
+
zoom_half = int(zoom / 2)
|
| 111 |
+
left = max(x - w * zoom_half, 0)
|
| 112 |
+
top = max(y - h * zoom_half, 0)
|
| 113 |
+
right = min(x + w * zoom_half, w)
|
| 114 |
+
bottom = min(y + h * zoom_half, h)
|
| 115 |
+
cropped = img_cv[int(top):int(bottom), int(left):int(right)]
|
| 116 |
+
resized = cv2.resize(cropped, (500, 500), interpolation=cv2.INTER_LANCZOS4)
|
| 117 |
+
|
| 118 |
+
# Convert back to PIL for other enhancements
|
| 119 |
+
pil_img = Image.fromarray(cv2.cvtColor(resized, cv2.COLOR_BGR2RGB))
|
| 120 |
+
enhanced_contrast = ImageEnhance.Contrast(pil_img).enhance(contrast)
|
| 121 |
+
enhanced_brightness = ImageEnhance.Brightness(enhanced_contrast).enhance(brightness)
|
| 122 |
+
enhanced_sharpness = ImageEnhance.Sharpness(enhanced_brightness).enhance(sharpness)
|
| 123 |
+
return enhanced_sharpness
|
| 124 |
+
|
| 125 |
def create_zip(processed_img, description, params):
|
| 126 |
'''
|
| 127 |
Create a zip archive containing the processed image and annotations.
|
|
|
|
| 195 |
with image_col:
|
| 196 |
st.subheader("Processed Image")
|
| 197 |
if 'processed_img' in st.session_state:
|
| 198 |
+
st.image(st.session_state.processed_img, use_column_width=True, caption="Processed Image")
|
| 199 |
else:
|
| 200 |
+
st.image(img, use_column_width=True, caption="Processed Image")
|
| 201 |
|
| 202 |
with controls_col:
|
| 203 |
st.subheader("Image Controls")
|
|
|
|
| 216 |
|
| 217 |
# Display Original Image Below
|
| 218 |
st.subheader("Original Image")
|
| 219 |
+
st.image(img, use_column_width=True, caption="Original Image")
|
| 220 |
|
| 221 |
# Save and Export Options
|
| 222 |
st.markdown("---")
|