File size: 1,680 Bytes
b79dba6
86bfdad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b79dba6
86bfdad
 
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
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.")