Spaces:
Sleeping
Sleeping
Create shadow_map.py
Browse files- shadow_map.py +19 -0
shadow_map.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import cv2, numpy as np
|
| 2 |
+
from PIL import Image
|
| 3 |
+
|
| 4 |
+
def analyze_uv_exposure(image_path):
|
| 5 |
+
img = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
|
| 6 |
+
blur = cv2.GaussianBlur(img, (11,11), 0)
|
| 7 |
+
_, mask = cv2.threshold(blur, 100, 255, cv2.THRESH_BINARY)
|
| 8 |
+
coverage = np.count_nonzero(mask) / mask.size * 100
|
| 9 |
+
|
| 10 |
+
overlay = Image.open(image_path).convert("RGBA")
|
| 11 |
+
pixels = overlay.load()
|
| 12 |
+
for y in range(overlay.height):
|
| 13 |
+
for x in range(overlay.width):
|
| 14 |
+
if mask[y, x] == 0:
|
| 15 |
+
pixels[x, y] = (255, 0, 0, 125)
|
| 16 |
+
|
| 17 |
+
annotated_path = f"annotated_{image_path.split('/')[-1]}"
|
| 18 |
+
overlay.save(annotated_path)
|
| 19 |
+
return round(coverage, 2), annotated_path
|