Bakht11 commited on
Commit
c0f0bf4
·
verified ·
1 Parent(s): d6584d5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -26
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 Colorizer")
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
- # Brightness adjustment
20
- st.sidebar.header("Adjust Brightness")
21
- brightness = st.sidebar.slider("Brightness", 0.0, 2.0, 1.0)
22
- enhancer_brightness = ImageEnhance.Brightness(image)
23
- enhanced_image_brightness = enhancer_brightness.enhance(brightness)
24
-
25
- # Contrast adjustment
26
- st.sidebar.header("Adjust Contrast")
27
- contrast = st.sidebar.slider("Contrast", 0.0, 2.0, 1.0)
28
- enhancer_contrast = ImageEnhance.Contrast(enhanced_image_brightness)
29
- enhanced_image_contrast = enhancer_contrast.enhance(contrast)
30
-
31
- # Show the enhanced image
32
- st.image(enhanced_image_contrast, caption='Enhanced Image', use_container_width=True)
33
-
34
- # Colorization
35
- if st.sidebar.button("Colorize Image"):
36
- # Ensure the uploaded image is in grayscale
 
 
 
 
 
 
 
 
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
- # Option to download the enhanced image
45
- st.sidebar.download_button("Download Enhanced Image",
46
- data=np.array(enhanced_image_contrast).tobytes(),
47
- file_name="enhanced_image.png",
48
- mime="image/png")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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")