Skip to content

Commit 5e9258b

Browse files
Initial commit for image processing and vision project
0 parents  commit 5e9258b

File tree

10 files changed

+3029
-0
lines changed

10 files changed

+3029
-0
lines changed

ipv1.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import streamlit as st
2+
import cv2
3+
import numpy as np
4+
from PIL import Image
5+
6+
st.title("🖼️ Basic Image Enhancer (IPV Project for Beginners)")
7+
8+
# Upload the image
9+
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "png", "jpeg"])
10+
11+
if uploaded_file:
12+
image = Image.open(uploaded_file)
13+
img_np = np.array(image)
14+
st.image(img_np, caption="Original Image")
15+
16+
# Convert to Grayscale
17+
gray = cv2.cvtColor(img_np, cv2.COLOR_BGR2GRAY)
18+
st.image(gray, caption="Grayscale Image", channels="GRAY")
19+
20+
# Apply Gaussian Blur
21+
blur = cv2.GaussianBlur(gray, (5, 5), 0)
22+
st.image(blur, caption="Gaussian Blur", channels="GRAY")
23+
24+
# Apply Median Blur
25+
median = cv2.medianBlur(gray, 5)
26+
st.image(median, caption="Median Blur", channels="GRAY")
27+
28+
# Sobel Edge Detection
29+
sobel_x = cv2.Sobel(gray, cv2.CV_64F, 1, 0)
30+
sobel_y = cv2.Sobel(gray, cv2.CV_64F, 0, 1)
31+
sobel_combined = cv2.magnitude(sobel_x, sobel_y)
32+
st.image(np.uint8(sobel_combined), caption="Sobel Edge Detection", channels="GRAY")
33+
34+
# Canny Edge Detection
35+
canny = cv2.Canny(gray, 100, 200)
36+
st.image(canny, caption="Canny Edge Detection", channels="GRAY")
37+
38+
# Morphological Operations
39+
kernel = np.ones((5, 5), np.uint8)
40+
41+
dilation = cv2.dilate(gray, kernel, iterations=1)
42+
erosion = cv2.erode(gray, kernel, iterations=1)
43+
opening = cv2.morphologyEx(gray, cv2.MORPH_OPEN, kernel)
44+
closing = cv2.morphologyEx(gray, cv2.MORPH_CLOSE, kernel)
45+
46+
st.image(dilation, caption="Dilation", channels="GRAY")
47+
st.image(erosion, caption="Erosion", channels="GRAY")
48+
st.image(opening, caption="Opening", channels="GRAY")
49+
st.image(closing, caption="Closing", channels="GRAY")

ipv2.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import streamlit as st
2+
import cv2
3+
import numpy as np
4+
from PIL import Image
5+
6+
st.set_page_config(page_title="Best Image Enhancer", layout="wide")
7+
st.title("🌟 Best Image Enhancer (Beginner IPV Project)")
8+
st.markdown("""
9+
<div style='background-color:#f0f8ff; padding:20px; border-radius:10px'>
10+
<h3 style='color:#2e86de'>Upload an image and apply powerful image processing tools!</h3>
11+
</div>
12+
""", unsafe_allow_html=True)
13+
14+
uploaded_file = st.file_uploader("📤 Upload your image", type=["jpg", "png", "jpeg"])
15+
16+
if uploaded_file:
17+
col1, col2 = st.columns(2)
18+
image = Image.open(uploaded_file)
19+
img_np = np.array(image)
20+
with col1:
21+
st.image(img_np, caption="🖼️ Original Image", use_container_width=True)
22+
23+
# Convert to Grayscale
24+
gray = cv2.cvtColor(img_np, cv2.COLOR_BGR2GRAY)
25+
with col2:
26+
st.image(gray, caption="🖤 Grayscale Image", use_container_width=True, channels="GRAY")
27+
28+
st.markdown("---")
29+
st.subheader("✨ Apply Filters and Morphological Operations")
30+
31+
kernel_size = st.slider("🔧 Kernel Size (odd only)", min_value=3, max_value=11, step=2, value=5)
32+
kernel = np.ones((kernel_size, kernel_size), np.uint8)
33+
34+
col3, col4 = st.columns(2)
35+
36+
# Gaussian Blur
37+
blur = cv2.GaussianBlur(gray, (kernel_size, kernel_size), 0)
38+
# Median Blur
39+
median = cv2.medianBlur(gray, kernel_size)
40+
41+
with col3:
42+
st.image(blur, caption="🌫️ Gaussian Blur", use_container_width=True, channels="GRAY")
43+
st.image(median, caption="🎯 Median Blur", use_container_width=True, channels="GRAY")
44+
45+
# Sobel
46+
sobel_x = cv2.Sobel(gray, cv2.CV_64F, 1, 0)
47+
sobel_y = cv2.Sobel(gray, cv2.CV_64F, 0, 1)
48+
sobel_combined = cv2.magnitude(sobel_x, sobel_y)
49+
50+
# Canny
51+
canny = cv2.Canny(gray, 100, 200)
52+
53+
with col4:
54+
st.image(np.uint8(sobel_combined), caption="⚡ Sobel Edge Detection", use_container_width=True, channels="GRAY")
55+
st.image(canny, caption="🧠 Canny Edge Detection", use_container_width=True, channels="GRAY")
56+
57+
st.markdown("---")
58+
st.subheader("🧱 Morphological Operations")
59+
60+
col5, col6 = st.columns(2)
61+
dilation = cv2.dilate(gray, kernel, iterations=1)
62+
erosion = cv2.erode(gray, kernel, iterations=1)
63+
opening = cv2.morphologyEx(gray, cv2.MORPH_OPEN, kernel)
64+
closing = cv2.morphologyEx(gray, cv2.MORPH_CLOSE, kernel)
65+
66+
with col5:
67+
st.image(dilation, caption="🚀 Dilation", use_container_width=True, channels="GRAY")
68+
st.image(erosion, caption="⛏️ Erosion", use_container_width=True, channels="GRAY")
69+
70+
with col6:
71+
st.image(opening, caption="🔓 Opening", use_container_width=True, channels="GRAY")
72+
st.image(closing, caption="🔒 Closing", use_container_width=True, channels="GRAY")

ipv3.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import streamlit as st
2+
import cv2
3+
import numpy as np
4+
from PIL import Image
5+
6+
st.set_page_config(page_title="Best Image Enhancer", layout="wide")
7+
st.title("🌟 Best Image Enhancer (Beginner IPV Project)")
8+
9+
st.markdown("""
10+
<div style='background-color:#f0f8ff; padding:20px; border-radius:10px'>
11+
<h3 style='color:#2e86de'>Upload an image and choose what operation you'd like to apply!</h3>
12+
</div>
13+
""", unsafe_allow_html=True)
14+
15+
uploaded_file = st.file_uploader("📤 Upload your image", type=["jpg", "png", "jpeg"])
16+
17+
if uploaded_file:
18+
image = Image.open(uploaded_file)
19+
img_np = np.array(image)
20+
st.image(img_np, caption="🖼️ Original Image", use_container_width=True)
21+
22+
# Convert to Grayscale
23+
gray = cv2.cvtColor(img_np, cv2.COLOR_BGR2GRAY)
24+
25+
# Select Operation
26+
st.markdown("---")
27+
operation = st.selectbox("🔍 Choose an Operation", [
28+
"Grayscale",
29+
"Gaussian Blur",
30+
"Median Blur",
31+
"Sobel Edge Detection",
32+
"Canny Edge Detection",
33+
"Dilation",
34+
"Erosion",
35+
"Opening",
36+
"Closing"
37+
])
38+
39+
kernel_size = st.slider("🔧 Kernel Size (odd only)", min_value=3, max_value=11, step=2, value=5)
40+
kernel = np.ones((kernel_size, kernel_size), np.uint8)
41+
42+
if operation == "Grayscale":
43+
st.image(gray, caption="🖤 Grayscale Image", use_container_width=True, channels="GRAY")
44+
45+
elif operation == "Gaussian Blur":
46+
blur = cv2.GaussianBlur(gray, (kernel_size, kernel_size), 0)
47+
st.image(blur, caption="🌫️ Gaussian Blur", use_container_width=True, channels="GRAY")
48+
49+
elif operation == "Median Blur":
50+
median = cv2.medianBlur(gray, kernel_size)
51+
st.image(median, caption="🎯 Median Blur", use_container_width=True, channels="GRAY")
52+
53+
elif operation == "Sobel Edge Detection":
54+
sobel_x = cv2.Sobel(gray, cv2.CV_64F, 1, 0)
55+
sobel_y = cv2.Sobel(gray, cv2.CV_64F, 0, 1)
56+
sobel_combined = cv2.magnitude(sobel_x, sobel_y)
57+
st.image(np.uint8(sobel_combined), caption="⚡ Sobel Edge Detection", use_container_width=True, channels="GRAY")
58+
59+
elif operation == "Canny Edge Detection":
60+
canny = cv2.Canny(gray, 100, 200)
61+
st.image(canny, caption="🧠 Canny Edge Detection", use_container_width=True, channels="GRAY")
62+
63+
elif operation == "Dilation":
64+
dilation = cv2.dilate(gray, kernel, iterations=1)
65+
st.image(dilation, caption="🚀 Dilation", use_container_width=True, channels="GRAY")
66+
67+
elif operation == "Erosion":
68+
erosion = cv2.erode(gray, kernel, iterations=1)
69+
st.image(erosion, caption="⛏️ Erosion", use_container_width=True, channels="GRAY")
70+
71+
elif operation == "Opening":
72+
opening = cv2.morphologyEx(gray, cv2.MORPH_OPEN, kernel)
73+
st.image(opening, caption="🔓 Opening", use_container_width=True, channels="GRAY")
74+
75+
elif operation == "Closing":
76+
closing = cv2.morphologyEx(gray, cv2.MORPH_CLOSE, kernel)
77+
st.image(closing, caption="🔒 Closing", use_container_width=True, channels="GRAY")
78+
79+
st.success(f"✅ Operation Applied: {operation}")

ipv4.py

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
import streamlit as st
2+
import cv2
3+
import numpy as np
4+
from PIL import Image
5+
6+
st.set_page_config(page_title="Ultimate Image Enhancer", layout="wide")
7+
st.title("🎨 Ultimate Image Enhancer – Beginner Friendly Image Processing App")
8+
9+
st.markdown("""
10+
<div style='background-color:#f0f8ff; padding:20px; border-radius:10px'>
11+
<h3 style='color:#2e86de'>Upload an image and apply a wide range of filters and operations!</h3>
12+
</div>
13+
""", unsafe_allow_html=True)
14+
15+
uploaded_file = st.file_uploader("📤 Upload your image", type=["jpg", "png", "jpeg"])
16+
17+
if uploaded_file:
18+
image = Image.open(uploaded_file)
19+
img_np = np.array(image)
20+
21+
st.image(img_np, caption="🖼️ Original Image", use_container_width=True)
22+
23+
gray = cv2.cvtColor(img_np, cv2.COLOR_BGR2GRAY)
24+
operation = st.selectbox("🛠️ Choose an Operation", [
25+
"Grayscale",
26+
"Gaussian Blur",
27+
"Median Blur",
28+
"Bilateral Filter",
29+
"Sobel Edge Detection",
30+
"Canny Edge Detection",
31+
"Histogram Equalization",
32+
"Thresholding",
33+
"Adaptive Thresholding",
34+
"Brightness & Contrast",
35+
"Sharpening",
36+
"Rotation",
37+
"Flip",
38+
"Dilation",
39+
"Erosion",
40+
"Opening",
41+
"Closing",
42+
"Gradient",
43+
"Top Hat",
44+
"Black Hat"
45+
])
46+
47+
kernel_size = st.slider("🧩 Kernel Size (odd only)", 3, 11, step=2, value=5)
48+
kernel = np.ones((kernel_size, kernel_size), np.uint8)
49+
50+
result = None
51+
52+
if operation == "Grayscale":
53+
result = gray
54+
55+
elif operation == "Gaussian Blur":
56+
result = cv2.GaussianBlur(img_np, (kernel_size, kernel_size), 0)
57+
58+
elif operation == "Median Blur":
59+
result = cv2.medianBlur(img_np, kernel_size)
60+
61+
elif operation == "Bilateral Filter":
62+
result = cv2.bilateralFilter(img_np, 9, 75, 75)
63+
64+
elif operation == "Sobel Edge Detection":
65+
sobel_x = cv2.Sobel(gray, cv2.CV_64F, 1, 0)
66+
sobel_y = cv2.Sobel(gray, cv2.CV_64F, 0, 1)
67+
sobel = cv2.magnitude(sobel_x, sobel_y)
68+
result = np.uint8(sobel)
69+
70+
elif operation == "Canny Edge Detection":
71+
result = cv2.Canny(gray, 100, 200)
72+
73+
elif operation == "Histogram Equalization":
74+
result = cv2.equalizeHist(gray)
75+
76+
elif operation == "Thresholding":
77+
_, result = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY)
78+
79+
elif operation == "Adaptive Thresholding":
80+
result = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C,
81+
cv2.THRESH_BINARY, kernel_size, 5)
82+
83+
elif operation == "Brightness & Contrast":
84+
brightness = st.slider("🔆 Brightness", -100, 100, 0)
85+
contrast = st.slider("🎚️ Contrast", -100, 100, 0)
86+
result = cv2.convertScaleAbs(img_np, alpha=1 + contrast / 100.0, beta=brightness)
87+
88+
elif operation == "Sharpening":
89+
sharp_kernel = np.array([[0, -1, 0],
90+
[-1, 5, -1],
91+
[0, -1, 0]])
92+
result = cv2.filter2D(img_np, -1, sharp_kernel)
93+
94+
elif operation == "Rotation":
95+
angle = st.slider("🔁 Rotate Angle", -180, 180, 0)
96+
(h, w) = img_np.shape[:2]
97+
center = (w // 2, h // 2)
98+
M = cv2.getRotationMatrix2D(center, angle, 1.0)
99+
result = cv2.warpAffine(img_np, M, (w, h))
100+
101+
elif operation == "Flip":
102+
flip_code = st.radio("↔️ Flip Mode", ["Horizontal", "Vertical"])
103+
result = cv2.flip(img_np, 1 if flip_code == "Horizontal" else 0)
104+
105+
elif operation == "Dilation":
106+
result = cv2.dilate(gray, kernel, iterations=1)
107+
108+
elif operation == "Erosion":
109+
result = cv2.erode(gray, kernel, iterations=1)
110+
111+
elif operation == "Opening":
112+
result = cv2.morphologyEx(gray, cv2.MORPH_OPEN, kernel)
113+
114+
elif operation == "Closing":
115+
result = cv2.morphologyEx(gray, cv2.MORPH_CLOSE, kernel)
116+
117+
elif operation == "Gradient":
118+
result = cv2.morphologyEx(gray, cv2.MORPH_GRADIENT, kernel)
119+
120+
elif operation == "Top Hat":
121+
result = cv2.morphologyEx(gray, cv2.MORPH_TOPHAT, kernel)
122+
123+
elif operation == "Black Hat":
124+
result = cv2.morphologyEx(gray, cv2.MORPH_BLACKHAT, kernel)
125+
126+
if result is not None:
127+
st.markdown("---")
128+
st.image(result, caption=f"✨ Result: {operation}", use_container_width=True,
129+
channels="GRAY" if len(result.shape) == 2 else "BGR")
130+
st.success("✅ Operation Applied Successfully!")

0 commit comments

Comments
 (0)