-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
49 lines (38 loc) · 1.57 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Import required libraries
import streamlit as st
from PIL import Image, ImageEnhance
# Streamlit app title
st.title('Image Enhancement App')
# Upload image through file uploader with a default value
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
if uploaded_file is None:
uploaded_file = 'Tolkien Fanart.png'
# Function to display the uploaded image
def display_image(image):
st.image(image, caption='Uploaded Image.')
st.write("")
return image
# Check if an image has been uploaded
if uploaded_file is not None:
# Read the image using PIL
image = Image.open(uploaded_file)
# Display the uploaded image
uploaded_image = display_image(image)
# Image enhancement options
st.subheader("Image Enhancement Options")
brightness = st.slider("Brightness", 0.0, 2.0, 1.0)
contrast = st.slider("Contrast", 0.0, 2.0, 1.0)
saturation = st.slider("Saturation", 0.0, 2.0, 1.0)
grayscale = st.checkbox("Convert to Black & White")
# Apply enhancements to the image
enhanced_image = ImageEnhance.Brightness(uploaded_image).enhance(brightness)
enhanced_image = ImageEnhance.Contrast(enhanced_image).enhance(contrast)
enhanced_image = ImageEnhance.Color(enhanced_image).enhance(saturation)
# Convert to black and white if the checkbox is selected
if grayscale:
enhanced_image = enhanced_image.convert("L")
# Display the enhanced image with zoom
st.subheader("Enhanced Image")
st.image(enhanced_image, caption='Enhanced Image.')
else:
st.write("Please upload an image.")