imagestreamlit / app.py
tharu22's picture
add
6abb5d9
import streamlit as st
import cv2
import numpy as np
from PIL import Image, ImageEnhance
st.title("Image Processing ")
# Upload image
uploaded_file = st.file_uploader("Upload an Image", type=["png", "jpg", "jpeg"])
if uploaded_file is not None:
image = Image.open(uploaded_file)
st.image(image, caption="Original Image", use_container_width=True)
# Convert PIL image to OpenCV format
img_array = np.array(image)
# Convert to Grayscale
if st.button("Convert to Grayscale"):
gray_image = cv2.cvtColor(img_array, cv2.COLOR_RGB2GRAY)
st.image(gray_image, caption="Grayscale Image", use_container_width=True, channels="GRAY")
# Rotate Image
angle = st.slider("Select Rotation Angle", -180, 180, 0)
if st.button("Rotate Image"):
(h, w) = img_array.shape[:2]
center = (w // 2, h // 2)
matrix = cv2.getRotationMatrix2D(center, angle, 1.0)
rotated_image = cv2.warpAffine(img_array, matrix, (w, h))
st.image(rotated_image, caption=f"Rotated by {angle}°", use_container_width=True)
# Adjust Brightness
brightness = st.slider("Adjust Brightness", 0.1, 3.0, 1.0)
if st.button("Apply Brightness"):
enhancer = ImageEnhance.Brightness(image)
bright_image = enhancer.enhance(brightness)
st.image(bright_image, caption="Brightness Adjusted", use_container_width=True)
# Adjust Sharpness
sharpness = st.slider("Adjust Sharpness", 0.1, 3.0, 1.0)
if st.button("Apply Sharpness"):
enhancer = ImageEnhance.Sharpness(image)
sharp_image = enhancer.enhance(sharpness)
st.image(sharp_image, caption="Sharpness Adjusted", use_container_width=True)