Update app.py
Browse files
app.py
CHANGED
@@ -58,39 +58,8 @@ def simple_threshold_blue(image_bgr):
|
|
58 |
total_pixels = image_bgr.shape[0] * image_bgr.shape[1]
|
59 |
perc_blue = (blue_pixels / total_pixels) * 100
|
60 |
return perc_blue, mask
|
61 |
-
|
62 |
-
"""
|
63 |
-
def advanced_threshold_blue(image_bgr):
|
64 |
-
"""
|
65 |
-
Advanced approach:
|
66 |
-
1) Multiple color ranges for deep & light blues
|
67 |
-
2) Morphological cleaning
|
68 |
-
3) Count ratio of blue pixels
|
69 |
-
"""
|
70 |
-
hsv = cv2.cvtColor(image_bgr, cv2.COLOR_BGR2HSV)
|
71 |
-
|
72 |
-
# Range 1: Deeper/darker blues
|
73 |
-
lower_blue1 = np.array([90, 50, 50], dtype=np.uint8)
|
74 |
-
upper_blue1 = np.array([130, 255, 255], dtype=np.uint8)
|
75 |
-
mask1 = cv2.inRange(hsv, lower_blue1, upper_blue1)
|
76 |
-
|
77 |
-
# Range 2: Lighter or near-cyan
|
78 |
-
lower_blue2 = np.array([80, 30, 50], dtype=np.uint8)
|
79 |
-
upper_blue2 = np.array([100, 255, 255], dtype=np.uint8)
|
80 |
-
mask2 = cv2.inRange(hsv, lower_blue2, upper_blue2)
|
81 |
|
82 |
-
combined_mask = cv2.bitwise_or(mask1, mask2)
|
83 |
|
84 |
-
# Morphological cleaning
|
85 |
-
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3,3))
|
86 |
-
cleaned_mask = cv2.morphologyEx(combined_mask, cv2.MORPH_OPEN, kernel)
|
87 |
-
cleaned_mask = cv2.morphologyEx(cleaned_mask, cv2.MORPH_CLOSE, kernel)
|
88 |
-
|
89 |
-
blue_pixels = cv2.countNonZero(cleaned_mask)
|
90 |
-
total_pixels = image_bgr.shape[0] * image_bgr.shape[1]
|
91 |
-
perc_blue = (blue_pixels / total_pixels) * 100
|
92 |
-
return perc_blue, cleaned_mask
|
93 |
-
"""
|
94 |
|
95 |
def plot_color_histogram(image_bgr):
|
96 |
"""
|
@@ -182,18 +151,7 @@ else:
|
|
182 |
st.image(simple_mask, caption="Simple Mask (white=detected blue)", width=250)
|
183 |
|
184 |
st.markdown("---")
|
185 |
-
|
186 |
-
# Advanced Threshold
|
187 |
-
st.subheader("3) Advanced Threshold Approach")
|
188 |
-
adv_perc_blue, adv_mask = advanced_threshold_blue(img_bgr)
|
189 |
-
|
190 |
-
col5, col6 = st.columns(2)
|
191 |
-
with col5:
|
192 |
-
st.write(f"**Blue Percentage (Advanced):** {adv_perc_blue:.2f}%")
|
193 |
-
st.progress(min(adv_perc_blue/100, 1.0))
|
194 |
-
with col6:
|
195 |
-
st.image(adv_mask, caption="Advanced Mask (white=detected blue)", width=250)
|
196 |
-
"""
|
197 |
st.markdown("""
|
198 |
---
|
199 |
## Relevance to ITC PSPD:
|
|
|
58 |
total_pixels = image_bgr.shape[0] * image_bgr.shape[1]
|
59 |
perc_blue = (blue_pixels / total_pixels) * 100
|
60 |
return perc_blue, mask
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
|
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
def plot_color_histogram(image_bgr):
|
65 |
"""
|
|
|
151 |
st.image(simple_mask, caption="Simple Mask (white=detected blue)", width=250)
|
152 |
|
153 |
st.markdown("---")
|
154 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
st.markdown("""
|
156 |
---
|
157 |
## Relevance to ITC PSPD:
|