Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,9 @@
|
|
1 |
import streamlit as st
|
2 |
-
from PIL import Image, ImageEnhance
|
3 |
import numpy as np
|
4 |
-
from deoldify import DeOldify
|
5 |
|
6 |
# Title of the app
|
7 |
-
st.title("Image Enhancer and
|
8 |
|
9 |
# File uploader to upload the image
|
10 |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
@@ -16,24 +15,32 @@ if uploaded_file is not None:
|
|
16 |
# Display the original image
|
17 |
st.image(image, caption='Original Image', use_container_width=True)
|
18 |
|
19 |
-
#
|
20 |
-
st.sidebar.header("
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
if image.convert('L') == image:
|
38 |
colorizer = DeOldify()
|
39 |
colorized_image = colorizer.colorize(image)
|
@@ -41,8 +48,26 @@ if uploaded_file is not None:
|
|
41 |
else:
|
42 |
st.sidebar.warning("Please upload a black and white image for colorization.")
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
from PIL import Image, ImageEnhance, ImageFilter
|
3 |
import numpy as np
|
|
|
4 |
|
5 |
# Title of the app
|
6 |
+
st.title("Image Enhancer and Filter Application")
|
7 |
|
8 |
# File uploader to upload the image
|
9 |
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
|
|
15 |
# Display the original image
|
16 |
st.image(image, caption='Original Image', use_container_width=True)
|
17 |
|
18 |
+
# Sidebar options for filters
|
19 |
+
st.sidebar.header("Select Filter")
|
20 |
+
filter_option = st.sidebar.selectbox("Choose a filter:",
|
21 |
+
["None", "Enhance", "Grayscale", "Colorize", "Blur", "Sharpen", "Edge Enhance"])
|
22 |
+
|
23 |
+
# Enhancement options
|
24 |
+
if filter_option == "Enhance":
|
25 |
+
st.sidebar.header("Adjust Brightness and Contrast")
|
26 |
+
brightness = st.sidebar.slider("Brightness", 0.0, 2.0, 1.0)
|
27 |
+
contrast = st.sidebar.slider("Contrast", 0.0, 2.0, 1.0)
|
28 |
+
|
29 |
+
# Enhance brightness and contrast
|
30 |
+
enhancer_brightness = ImageEnhance.Brightness(image)
|
31 |
+
enhanced_image_brightness = enhancer_brightness.enhance(brightness)
|
32 |
+
enhancer_contrast = ImageEnhance.Contrast(enhanced_image_brightness)
|
33 |
+
enhanced_image = enhancer_contrast.enhance(contrast)
|
34 |
+
|
35 |
+
st.image(enhanced_image, caption='Enhanced Image', use_container_width=True)
|
36 |
+
|
37 |
+
elif filter_option == "Grayscale":
|
38 |
+
# Convert to grayscale
|
39 |
+
gray_image = image.convert("L")
|
40 |
+
st.image(gray_image, caption='Grayscale Image', use_container_width=True)
|
41 |
+
|
42 |
+
elif filter_option == "Colorize":
|
43 |
+
# Ensure the uploaded image is in grayscale for colorization
|
44 |
if image.convert('L') == image:
|
45 |
colorizer = DeOldify()
|
46 |
colorized_image = colorizer.colorize(image)
|
|
|
48 |
else:
|
49 |
st.sidebar.warning("Please upload a black and white image for colorization.")
|
50 |
|
51 |
+
elif filter_option == "Blur":
|
52 |
+
# Apply a blur filter
|
53 |
+
blurred_image = image.filter(ImageFilter.BLUR)
|
54 |
+
st.image(blurred_image, caption='Blurred Image', use_container_width=True)
|
55 |
+
|
56 |
+
elif filter_option == "Sharpen":
|
57 |
+
# Apply a sharpen filter
|
58 |
+
sharpened_image = image.filter(ImageFilter.SHARPEN)
|
59 |
+
st.image(sharpened_image, caption='Sharpened Image', use_container_width=True)
|
60 |
+
|
61 |
+
elif filter_option == "Edge Enhance":
|
62 |
+
# Apply an edge enhancement filter
|
63 |
+
edge_enhanced_image = image.filter(ImageFilter.EDGE_ENHANCE)
|
64 |
+
st.image(edge_enhanced_image, caption='Edge Enhanced Image', use_container_width=True)
|
65 |
+
|
66 |
+
# Option to download the processed image
|
67 |
+
processed_image = enhanced_image if filter_option == "Enhance" else gray_image if filter_option == "Grayscale" else colorized_image if filter_option == "Colorize" else blurred_image if filter_option == "Blur" else sharpened_image if filter_option == "Sharpen" else edge_enhanced_image if filter_option == "Edge Enhance" else None
|
68 |
+
|
69 |
+
if processed_image:
|
70 |
+
st.sidebar.download_button("Download Processed Image",
|
71 |
+
data=np.array(processed_image).tobytes(),
|
72 |
+
file_name="processed_image.png",
|
73 |
+
mime="image/png")
|