Image_Processing_1 / src /streamlit_app.py
billusanda007's picture
Update src/streamlit_app.py
86bfdad verified
import streamlit as st
import numpy as np
import cv2
import matplotlib.pyplot as plt
st.set_page_config(page_title="Image Processing App", layout="centered")
st.title("🖼️ Image Processing & Analysis")
st.write("Histogram • Box Plot • Grayscale • Brightness & Contrast")
uploaded_file = st.file_uploader(
"Upload an image", type=["png", "jpg", "jpeg"]
)
if uploaded_file is not None:
# Read image
file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
img_bgr = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)
img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
st.subheader("Original Image")
st.image(img_rgb, use_container_width=True)
gray = cv2.cvtColor(img_rgb, cv2.COLOR_RGB2GRAY)
st.subheader("Grayscale Image")
st.image(gray, clamp=True, use_container_width=True)
st.subheader("Brightness & Contrast Adjustment")
contrast = st.slider("Contrast", 0.1, 3.0, 1.0, 0.1)
brightness = st.slider("Brightness", -100, 100, 0, 5)
adjusted = np.clip(
contrast * img_rgb + brightness, 0, 255
).astype(np.uint8)
st.image(adjusted, caption="Adjusted Image", use_container_width=True)
st.subheader("Histogram of Grayscale Image")
fig_hist, ax_hist = plt.subplots()
ax_hist.hist(gray.ravel(), bins=256)
ax_hist.set_xlabel("Pixel Intensity")
ax_hist.set_ylabel("Frequency")
st.pyplot(fig_hist)
st.subheader("Box Plot of Pixel Intensities")
fig_box, ax_box = plt.subplots()
ax_box.boxplot(gray.ravel(), vert=False)
ax_box.set_xlabel("Pixel Intensity")
st.pyplot(fig_box)
else:
st.info("⬆️ Upload an image to get started.")