hari3485 commited on
Commit
93cbbf5
·
verified ·
1 Parent(s): 5b7dab5

Update pages/Data Collection.py

Browse files
Files changed (1) hide show
  1. pages/Data Collection.py +96 -5
pages/Data Collection.py CHANGED
@@ -7,7 +7,7 @@ def subheading(text):
7
 
8
  # Sidebar for navigation
9
  st.sidebar.title("Navigation")
10
- page = st.sidebar.radio("Go to", ["Introduction", "Understanding Images", "Color Spaces", "Basic Operations"])
11
 
12
  # App Title and Description
13
  st.title("Image Processing Fundamentals")
@@ -27,8 +27,6 @@ if page == "Introduction":
27
  - Basic operations on images using Python libraries.
28
  """)
29
 
30
- # Understanding Images Section
31
- elif page == "Understanding Images":
32
  st.header("Understanding Images")
33
 
34
  # Subsections
@@ -50,8 +48,6 @@ elif page == "Understanding Images":
50
  - These grids are also called **image matrices**.
51
  """)
52
 
53
- # Color Spaces Section
54
- elif page == "Color Spaces":
55
  st.header("Color Spaces")
56
 
57
  subheading("1. Black and White")
@@ -150,5 +146,100 @@ elif page == "Basic Operations":
150
  """)
151
 
152
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  if st.button("Go Back"):
154
  st.experimental_set_query_params(page="Introduction")
 
7
 
8
  # Sidebar for navigation
9
  st.sidebar.title("Navigation")
10
+ page = st.sidebar.radio("Go to", ["Introduction", "Basic Operations","Converting Image to BGR & Gray SCale"])
11
 
12
  # App Title and Description
13
  st.title("Image Processing Fundamentals")
 
27
  - Basic operations on images using Python libraries.
28
  """)
29
 
 
 
30
  st.header("Understanding Images")
31
 
32
  # Subsections
 
48
  - These grids are also called **image matrices**.
49
  """)
50
 
 
 
51
  st.header("Color Spaces")
52
 
53
  subheading("1. Black and White")
 
146
  """)
147
 
148
 
149
+ elif page == "Converting Image to BGR & Gray SCale":
150
+
151
+ from PIL import Image
152
+
153
+ # Title of the Streamlit app
154
+ st.title("Image Handling in OpenCV")
155
+ st.write("Explore Grayscale and BGR Image Creation and Display.")
156
+
157
+ # Section 1: Grayscale Image
158
+ st.header("Grayscale Image Creation")
159
+
160
+ # Grayscale image creation
161
+ gray_img = np.full((500, 500), 155, dtype=np.uint8)
162
+ gray_pil = Image.fromarray(gray_img)
163
+
164
+ # Display in Streamlit
165
+ st.image(gray_pil, caption="Gray Image in Streamlit", use_column_width=True)
166
+
167
+ # Button for OpenCV display
168
+ if st.button("Show Gray Image using OpenCV"):
169
+ cv2.imshow("Gray Image", gray_img)
170
+ cv2.waitKey(0)
171
+ cv2.destroyAllWindows()
172
+
173
+ # Section 2: BGR Channels
174
+ st.header("BGR Color Channels")
175
+
176
+ # Creating BGR channels
177
+ blue_channel = cv2.merge([
178
+ np.full((300, 300), 255, dtype=np.uint8), # Blue
179
+ np.zeros((300, 300), dtype=np.uint8), # Green
180
+ np.zeros((300, 300), dtype=np.uint8) # Red
181
+ ])
182
+ green_channel = cv2.merge([
183
+ np.zeros((300, 300), dtype=np.uint8), # Blue
184
+ np.full((300, 300), 255, dtype=np.uint8), # Green
185
+ np.zeros((300, 300), dtype=np.uint8) # Red
186
+ ])
187
+ red_channel = cv2.merge([
188
+ np.zeros((300, 300), dtype=np.uint8), # Blue
189
+ np.zeros((300, 300), dtype=np.uint8), # Green
190
+ np.full((300, 300), 255, dtype=np.uint8) # Red
191
+ ])
192
+
193
+ # Convert for Streamlit
194
+ blue_pil = Image.fromarray(blue_channel)
195
+ green_pil = Image.fromarray(green_channel)
196
+ red_pil = Image.fromarray(red_channel)
197
+
198
+ # Display in Streamlit
199
+ st.subheader("BGR Channels in Streamlit")
200
+ col1, col2, col3 = st.columns(3)
201
+ with col1:
202
+ st.image(blue_pil, caption="Blue Channel", use_column_width=True)
203
+ with col2:
204
+ st.image(green_pil, caption="Green Channel", use_column_width=True)
205
+ with col3:
206
+ st.image(red_pil, caption="Red Channel", use_column_width=True)
207
+
208
+ # Buttons for OpenCV display
209
+ if st.button("Show Blue Channel using OpenCV"):
210
+ cv2.imshow("Blue Channel", blue_channel)
211
+ cv2.waitKey(0)
212
+ cv2.destroyAllWindows()
213
+
214
+ if st.button("Show Green Channel using OpenCV"):
215
+ cv2.imshow("Green Channel", green_channel)
216
+ cv2.waitKey(0)
217
+ cv2.destroyAllWindows()
218
+
219
+ if st.button("Show Red Channel using OpenCV"):
220
+ cv2.imshow("Red Channel", red_channel)
221
+ cv2.waitKey(0)
222
+ cv2.destroyAllWindows()
223
+
224
+ # Section 3: Read and Display an Image
225
+ st.header("Read and Display an Image")
226
+
227
+ # Image upload
228
+ uploaded_file = st.file_uploader("Upload an image to display", type=["png", "jpg", "jpeg"])
229
+ if uploaded_file:
230
+ # Convert to OpenCV format
231
+ file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
232
+ img = cv2.imdecode(file_bytes, cv2.IMREAD_GRAYSCALE) # Read as grayscale for example
233
+ st.image(img, caption="Uploaded Image in Grayscale", use_column_width=True)
234
+
235
+ # Button to display using OpenCV
236
+ if st.button("Show Uploaded Image using OpenCV"):
237
+ cv2.imshow("Uploaded Image", img)
238
+ cv2.waitKey(0)
239
+ cv2.destroyAllWindows()
240
+
241
+
242
+
243
+
244
  if st.button("Go Back"):
245
  st.experimental_set_query_params(page="Introduction")