Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,21 +5,23 @@ from PIL import Image
|
|
5 |
|
6 |
st.title("🎨 Grayscale Image Converter")
|
7 |
|
8 |
-
# Upload image
|
9 |
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
10 |
|
11 |
if uploaded_file is not None:
|
12 |
-
# Read image
|
13 |
image = Image.open(uploaded_file)
|
14 |
-
st.image(image, caption='Original Image', use_column_width=True)
|
15 |
|
16 |
-
# Convert PIL
|
17 |
img_array = np.array(image)
|
18 |
-
if img_array.shape[2] == 4:
|
19 |
img_array = cv2.cvtColor(img_array, cv2.COLOR_RGBA2RGB)
|
20 |
|
21 |
-
# Convert to grayscale
|
22 |
gray_image = cv2.cvtColor(img_array, cv2.COLOR_RGB2GRAY)
|
23 |
|
24 |
-
# Display
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
st.title("🎨 Grayscale Image Converter")
|
7 |
|
|
|
8 |
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
9 |
|
10 |
if uploaded_file is not None:
|
|
|
11 |
image = Image.open(uploaded_file)
|
|
|
12 |
|
13 |
+
# Convert PIL to OpenCV format
|
14 |
img_array = np.array(image)
|
15 |
+
if img_array.shape[2] == 4:
|
16 |
img_array = cv2.cvtColor(img_array, cv2.COLOR_RGBA2RGB)
|
17 |
|
|
|
18 |
gray_image = cv2.cvtColor(img_array, cv2.COLOR_RGB2GRAY)
|
19 |
|
20 |
+
# Display side-by-side in smaller size
|
21 |
+
col1, col2 = st.columns(2)
|
22 |
+
|
23 |
+
with col1:
|
24 |
+
st.image(image, caption="Original", width=250)
|
25 |
+
|
26 |
+
with col2:
|
27 |
+
st.image(gray_image, caption="Grayscale", width=250, channels="GRAY")
|