File size: 3,388 Bytes
53e2356
c0f0bf4
53e2356
 
 
c0f0bf4
53e2356
 
 
 
 
 
 
 
 
62e80fe
53e2356
c0f0bf4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43e82ff
 
 
 
 
 
 
c0f0bf4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import streamlit as st
from PIL import Image, ImageEnhance, ImageFilter
import numpy as np

# Title of the app
st.title("Image Enhancer and Filter Application")

# File uploader to upload the image
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])

if uploaded_file is not None:
    # Open the image
    image = Image.open(uploaded_file)
    
    # Display the original image
    st.image(image, caption='Original Image', use_container_width=True)

    # Sidebar options for filters
    st.sidebar.header("Select Filter")
    filter_option = st.sidebar.selectbox("Choose a filter:", 
                                          ["None", "Enhance", "Grayscale", "Colorize", "Blur", "Sharpen", "Edge Enhance"])

    # Enhancement options
    if filter_option == "Enhance":
        st.sidebar.header("Adjust Brightness and Contrast")
        brightness = st.sidebar.slider("Brightness", 0.0, 2.0, 1.0)
        contrast = st.sidebar.slider("Contrast", 0.0, 2.0, 1.0)
        
        # Enhance brightness and contrast
        enhancer_brightness = ImageEnhance.Brightness(image)
        enhanced_image_brightness = enhancer_brightness.enhance(brightness)
        enhancer_contrast = ImageEnhance.Contrast(enhanced_image_brightness)
        enhanced_image = enhancer_contrast.enhance(contrast)
        
        st.image(enhanced_image, caption='Enhanced Image', use_container_width=True)

    elif filter_option == "Grayscale":
        # Convert to grayscale
        gray_image = image.convert("L")
        st.image(gray_image, caption='Grayscale Image', use_container_width=True)

    elif filter_option == "Colorize":
        # Ensure the uploaded image is in grayscale for colorization
        if image.convert('L') == image:
            colorizer = DeOldify()
            colorized_image = colorizer.colorize(image)
            st.image(colorized_image, caption='Colorized Image', use_container_width=True)
        else:
            st.sidebar.warning("Please upload a black and white image for colorization.")

    elif filter_option == "Blur":
        # Apply a blur filter
        blurred_image = image.filter(ImageFilter.BLUR)
        st.image(blurred_image, caption='Blurred Image', use_container_width=True)

    elif filter_option == "Sharpen":
        # Apply a sharpen filter
        sharpened_image = image.filter(ImageFilter.SHARPEN)
        st.image(sharpened_image, caption='Sharpened Image', use_container_width=True)

    elif filter_option == "Edge Enhance":
        # Apply an edge enhancement filter
        edge_enhanced_image = image.filter(ImageFilter.EDGE_ENHANCE)
        st.image(edge_enhanced_image, caption='Edge Enhanced Image', use_container_width=True)

    # Option to download the processed image
    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

    if processed_image:
        st.sidebar.download_button("Download Processed Image", 
                                     data=np.array(processed_image).tobytes(), 
                                     file_name="processed_image.png", 
                                     mime="image/png")