Update app.py
Browse files
app.py
CHANGED
|
@@ -100,20 +100,19 @@ class ImageAnalyzer:
|
|
| 100 |
])
|
| 101 |
|
| 102 |
def preprocess_image(self, image: Image.Image) -> Dict[str, Any]:
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
}
|
| 117 |
|
| 118 |
# Edge detection for crack analysis
|
| 119 |
gray = cv2.cvtColor(img_array, cv2.COLOR_RGB2GRAY)
|
|
@@ -134,7 +133,7 @@ class ImageAnalyzer:
|
|
| 134 |
"edges": edges,
|
| 135 |
"rust_mask": rust_mask
|
| 136 |
}
|
| 137 |
-
|
| 138 |
logger.error(f"Preprocessing error: {e}")
|
| 139 |
return None
|
| 140 |
|
|
|
|
| 100 |
])
|
| 101 |
|
| 102 |
def preprocess_image(self, image: Image.Image) -> Dict[str, Any]:
|
| 103 |
+
"""Enhanced image preprocessing with multiple analyses"""
|
| 104 |
+
try:
|
| 105 |
+
# Convert to RGB if necessary
|
| 106 |
+
if image.mode != 'RGB':
|
| 107 |
+
image = image.convert('RGB')
|
| 108 |
+
# Basic image statistics
|
| 109 |
+
img_array = np.array(image)
|
| 110 |
+
stats = {
|
| 111 |
+
"mean_brightness": np.mean(img_array),
|
| 112 |
+
"std_brightness": np.std(img_array),
|
| 113 |
+
"size": image.size,
|
| 114 |
+
"aspect_ratio": image.size[0] / image.size[1]
|
| 115 |
+
}
|
|
|
|
| 116 |
|
| 117 |
# Edge detection for crack analysis
|
| 118 |
gray = cv2.cvtColor(img_array, cv2.COLOR_RGB2GRAY)
|
|
|
|
| 133 |
"edges": edges,
|
| 134 |
"rust_mask": rust_mask
|
| 135 |
}
|
| 136 |
+
except Exception as e:
|
| 137 |
logger.error(f"Preprocessing error: {e}")
|
| 138 |
return None
|
| 139 |
|