File size: 1,324 Bytes
6a72bd2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import cv2
import numpy as np
from PIL import Image

st.title("🖼️ Image Quality Enhancer")

# Upload image
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "png", "jpeg"])

def enhance_image(image):
    # Convert to OpenCV format
    img = np.array(image)

    # Convert to BGR (for OpenCV)
    img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)

    # 1. Denoising
    denoised = cv2.fastNlMeansDenoisingColored(img, None, 10, 10, 7, 21)

    # 2. Sharpening
    kernel = np.array([[0, -1, 0],
                       [-1, 5,-1],
                       [0, -1, 0]])
    sharpened = cv2.filter2D(denoised, -1, kernel)

    # 3. Convert back to RGB
    final = cv2.cvtColor(sharpened, cv2.COLOR_BGR2RGB)

    return final

if uploaded_file is not None:
    image = Image.open(uploaded_file)

    st.subheader("Original Image")
    st.image(image, use_column_width=True)

    if st.button("Enhance Image"):
        enhanced = enhance_image(image)

        st.subheader("Enhanced Image")
        st.image(enhanced, use_column_width=True)

        # Download option
        result = Image.fromarray(enhanced)
        st.download_button(
            label="Download Enhanced Image",
            data=result.tobytes(),
            file_name="enhanced.png",
            mime="image/png"
        )