Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -37,15 +37,19 @@ def allowed_file(filename):
|
|
| 37 |
def preprocess_image(image_path):
|
| 38 |
"""Preprocess image for CNN model (32x32 grayscale)"""
|
| 39 |
try:
|
| 40 |
-
# Read image
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
if img is None:
|
| 44 |
raise ValueError("Could not read image")
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
print(f"Original image shape: {img.shape}")
|
| 47 |
|
| 48 |
-
# Resize to 32x32
|
| 49 |
img_resized = cv2.resize(img, (32, 32))
|
| 50 |
|
| 51 |
# Apply histogram equalization
|
|
@@ -59,9 +63,6 @@ def preprocess_image(image_path):
|
|
| 59 |
|
| 60 |
print(f"Model input shape: {img_input.shape}")
|
| 61 |
|
| 62 |
-
# For display - convert to RGB
|
| 63 |
-
img_display = cv2.cvtColor(img_resized, cv2.COLOR_GRAY2RGB)
|
| 64 |
-
|
| 65 |
return img_input, img_display
|
| 66 |
|
| 67 |
except Exception as e:
|
|
|
|
| 37 |
def preprocess_image(image_path):
|
| 38 |
"""Preprocess image for CNN model (32x32 grayscale)"""
|
| 39 |
try:
|
| 40 |
+
# Read original image for display
|
| 41 |
+
img_original = cv2.imread(image_path)
|
| 42 |
+
if img_original is None:
|
|
|
|
| 43 |
raise ValueError("Could not read image")
|
| 44 |
|
| 45 |
+
# Convert to RGB for display
|
| 46 |
+
img_display = cv2.cvtColor(img_original, cv2.COLOR_BGR2RGB)
|
| 47 |
+
|
| 48 |
+
# Read as grayscale for model
|
| 49 |
+
img = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
|
| 50 |
print(f"Original image shape: {img.shape}")
|
| 51 |
|
| 52 |
+
# Resize to 32x32 for model
|
| 53 |
img_resized = cv2.resize(img, (32, 32))
|
| 54 |
|
| 55 |
# Apply histogram equalization
|
|
|
|
| 63 |
|
| 64 |
print(f"Model input shape: {img_input.shape}")
|
| 65 |
|
|
|
|
|
|
|
|
|
|
| 66 |
return img_input, img_display
|
| 67 |
|
| 68 |
except Exception as e:
|