Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,23 +5,24 @@ from PIL import Image
|
|
| 5 |
|
| 6 |
st.title("Image to Grayscale Converter")
|
| 7 |
|
| 8 |
-
# File uploader
|
| 9 |
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
| 10 |
|
| 11 |
if uploaded_file is not None:
|
| 12 |
-
#
|
| 13 |
image = Image.open(uploaded_file)
|
| 14 |
-
|
| 15 |
-
# Convert the image to a format OpenCV can use (numpy array)
|
| 16 |
image_np = np.array(image)
|
| 17 |
|
| 18 |
-
# Convert to grayscale
|
| 19 |
gray_image = cv2.cvtColor(image_np, cv2.COLOR_RGB2GRAY)
|
| 20 |
|
| 21 |
-
# Display
|
| 22 |
-
st.
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
| 5 |
|
| 6 |
st.title("Image to Grayscale Converter")
|
| 7 |
|
| 8 |
+
# File uploader
|
| 9 |
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
| 10 |
|
| 11 |
if uploaded_file is not None:
|
| 12 |
+
# Load image with PIL and convert to numpy array
|
| 13 |
image = Image.open(uploaded_file)
|
|
|
|
|
|
|
| 14 |
image_np = np.array(image)
|
| 15 |
|
| 16 |
+
# Convert to grayscale
|
| 17 |
gray_image = cv2.cvtColor(image_np, cv2.COLOR_RGB2GRAY)
|
| 18 |
|
| 19 |
+
# Display side-by-side images
|
| 20 |
+
col1, col2 = st.columns(2)
|
| 21 |
+
|
| 22 |
+
with col1:
|
| 23 |
+
st.subheader("Original")
|
| 24 |
+
st.image(image, width=250)
|
| 25 |
|
| 26 |
+
with col2:
|
| 27 |
+
st.subheader("Grayscale")
|
| 28 |
+
st.image(gray_image, width=250, clamp=True, channels="GRAY")
|