| import streamlit as st |
| import cv2 |
| import numpy as np |
| from PIL import Image |
| import io |
|
|
| |
| st.set_page_config( |
| page_title="AI Image Enhancement Tool", |
| page_icon="🖼️", |
| layout="wide" |
| ) |
|
|
| st.title("🖼️ AI Based Image Enhancement Application") |
| st.markdown("Enhance brightness, contrast and remove noise from your images in real-time.") |
|
|
| |
| st.sidebar.header("Enhancement Controls") |
|
|
| brightness = st.sidebar.slider("Brightness (Beta)", 0, 100, 50) |
| contrast = st.sidebar.slider("Contrast (Alpha)", 1.0, 3.0, 1.5) |
| blur = st.sidebar.slider("Noise Reduction (Gaussian Blur)", 1, 15, 5, step=2) |
|
|
| uploaded_file = st.file_uploader("Upload an Image", type=["jpg","jpeg","png"]) |
|
|
| def enhance_image(image, alpha, beta, blur_value): |
| image_np = np.array(image) |
| image_np = cv2.cvtColor(image_np, cv2.COLOR_RGB2BGR) |
|
|
| enhanced = cv2.convertScaleAbs(image_np, alpha=alpha, beta=beta) |
| denoised = cv2.GaussianBlur(enhanced, (blur_value, blur_value), 0) |
|
|
| final = cv2.cvtColor(denoised, cv2.COLOR_BGR2RGB) |
| return final |
|
|
| if uploaded_file is not None: |
|
|
| image = Image.open(uploaded_file) |
|
|
| col1, col2 = st.columns(2) |
|
|
| with col1: |
| st.subheader("Original Image") |
| st.image(image, use_column_width=True) |
|
|
| processed = enhance_image(image, contrast, brightness, blur) |
|
|
| with col2: |
| st.subheader("Enhanced Image") |
| st.image(processed, use_column_width=True) |
|
|
| result = Image.fromarray(processed) |
|
|
| buf = io.BytesIO() |
| result.save(buf, format="PNG") |
| byte_im = buf.getvalue() |
|
|
| st.download_button( |
| label="📥 Download Enhanced Image", |
| data=byte_im, |
| file_name="enhanced_image.png", |
| mime="image/png" |
| ) |
|
|
| st.markdown("---") |
| st.markdown("Built using Streamlit + OpenCV") |