hari3485 commited on
Commit
c3795d0
·
verified ·
1 Parent(s): 7b820ea

Update pages/Data Collection.py

Browse files
Files changed (1) hide show
  1. pages/Data Collection.py +56 -62
pages/Data Collection.py CHANGED
@@ -148,32 +148,61 @@ elif page == "Basic Operations":
148
 
149
 
150
  elif page =="Converting Image to Black&White ,BGR & Gray SCale":
151
-
152
  from PIL import Image
153
 
154
- # Title of the Streamlit app
155
- st.title("Image Handling in OpenCV")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
  st.write("Explore Grayscale and BGR Image Creation and Display.")
157
 
158
  # Section 1: Grayscale Image
159
  st.header("Grayscale Image Creation")
160
-
161
  # Grayscale image creation
162
  gray_img = np.full((500, 500), 155, dtype=np.uint8)
163
  gray_pil = Image.fromarray(gray_img)
164
 
165
- # Display in Streamlit
166
- st.image(gray_pil, caption="Gray Image in Streamlit", use_column_width=True)
167
-
168
- # Button for OpenCV display
169
- if st.button("Show Gray Image using OpenCV"):
170
- cv2.imshow("Gray Image", gray_img)
171
- cv2.waitKey(0)
172
- cv2.destroyAllWindows()
173
 
174
  # Section 2: BGR Channels
175
  st.header("BGR Color Channels")
176
-
177
  # Creating BGR channels
178
  blue_channel = cv2.merge([
179
  np.full((300, 300), 255, dtype=np.uint8), # Blue
@@ -190,57 +219,22 @@ elif page =="Converting Image to Black&White ,BGR & Gray SCale":
190
  np.zeros((300, 300), dtype=np.uint8), # Green
191
  np.full((300, 300), 255, dtype=np.uint8) # Red
192
  ])
 
193
 
194
- # Convert for Streamlit
195
- blue_pil = Image.fromarray(blue_channel)
196
- green_pil = Image.fromarray(green_channel)
197
- red_pil = Image.fromarray(red_channel)
198
-
199
- # Display in Streamlit
200
- st.subheader("BGR Channels in Streamlit")
201
- col1, col2, col3 = st.columns(3)
202
- with col1:
203
- st.image(blue_pil, caption="Blue Channel", use_column_width=True)
204
- with col2:
205
- st.image(green_pil, caption="Green Channel", use_column_width=True)
206
- with col3:
207
- st.image(red_pil, caption="Red Channel", use_column_width=True)
208
-
209
- # Buttons for OpenCV display
210
- if st.button("Show Blue Channel using OpenCV"):
211
- cv2.imshow("Blue Channel", blue_channel)
212
- cv2.waitKey(0)
213
- cv2.destroyAllWindows()
214
-
215
- if st.button("Show Green Channel using OpenCV"):
216
- cv2.imshow("Green Channel", green_channel)
217
- cv2.waitKey(0)
218
- cv2.destroyAllWindows()
219
-
220
- if st.button("Show Red Channel using OpenCV"):
221
- cv2.imshow("Red Channel", red_channel)
222
- cv2.waitKey(0)
223
- cv2.destroyAllWindows()
224
-
225
- # Section 3: Read and Display an Image
226
- st.header("Read and Display an Image")
227
-
228
- # Image upload
229
- uploaded_file = st.file_uploader("Upload an image to display", type=["png", "jpg", "jpeg"])
230
- if uploaded_file:
231
- # Convert to OpenCV format
232
- file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
233
- img = cv2.imdecode(file_bytes, cv2.IMREAD_GRAYSCALE) # Read as grayscale for example
234
- st.image(img, caption="Uploaded Image in Grayscale", use_column_width=True)
235
-
236
- # Button to display using OpenCV
237
- if st.button("Show Uploaded Image using OpenCV"):
238
- cv2.imshow("Uploaded Image", img)
239
- cv2.waitKey(0)
240
- cv2.destroyAllWindows()
241
 
242
-
 
 
 
 
 
 
 
243
 
244
-
245
  if st.button("Go Back"):
246
  st.experimental_set_query_params(page="Introduction")
 
148
 
149
 
150
  elif page =="Converting Image to Black&White ,BGR & Gray SCale":
151
+
152
  from PIL import Image
153
 
154
+ # Title of the app
155
+ st.header("Black & White Images")
156
+
157
+ # Display the code
158
+ st.subheader("Code to Create and Display Black & White Images")
159
+ code = """
160
+ import numpy as np
161
+ import streamlit as st
162
+
163
+ # Create images
164
+ white_img = np.full((500, 500), 255, dtype=np.uint8) # White image
165
+ black_img = np.zeros((500, 500), dtype=np.uint8) # Black image
166
+
167
+ # Display images in Streamlit
168
+ st.subheader("White Image")
169
+ st.image(white_img, caption="White Image", use_column_width=True)
170
+
171
+ st.subheader("Black Image")
172
+ st.image(black_img, caption="Black Image", use_column_width=True)
173
+ """
174
+ st.code(code, language="python")
175
+
176
+ # Create images
177
+ white_img = np.full((500, 500), 255, dtype=np.uint8) # White image
178
+ black_img = np.zeros((500, 500), dtype=np.uint8) # Black image
179
+
180
+ # Display images in Streamlit
181
+ st.subheader("White Image")
182
+ st.image(white_img, caption="White Image", use_column_width=True)
183
+
184
+ st.subheader("Black Image")
185
+ st.image(black_img, caption="Black Image", use_column_width=True)
186
+
187
+ st.header("Image Handling in OpenCV")
188
  st.write("Explore Grayscale and BGR Image Creation and Display.")
189
 
190
  # Section 1: Grayscale Image
191
  st.header("Grayscale Image Creation")
192
+ st.code("""
193
  # Grayscale image creation
194
  gray_img = np.full((500, 500), 155, dtype=np.uint8)
195
  gray_pil = Image.fromarray(gray_img)
196
 
197
+ # Display in OpenCV
198
+ cv2.imshow("Gray Image", gray_img)
199
+ cv2.waitKey(0)
200
+ cv2.destroyAllWindows()
201
+ """, language="python")
 
 
 
202
 
203
  # Section 2: BGR Channels
204
  st.header("BGR Color Channels")
205
+ st.code("""
206
  # Creating BGR channels
207
  blue_channel = cv2.merge([
208
  np.full((300, 300), 255, dtype=np.uint8), # Blue
 
219
  np.zeros((300, 300), dtype=np.uint8), # Green
220
  np.full((300, 300), 255, dtype=np.uint8) # Red
221
  ])
222
+ """, language="python")
223
 
224
+ st.code("""
225
+ # Display in OpenCV
226
+ cv2.imshow("Blue Channel", blue_channel)
227
+ cv2.waitKey(0)
228
+ cv2.destroyAllWindows()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
229
 
230
+ cv2.imshow("Green Channel", green_channel)
231
+ cv2.waitKey(0)
232
+ cv2.destroyAllWindows()
233
+
234
+ cv2.imshow("Red Channel", red_channel)
235
+ cv2.waitKey(0)
236
+ cv2.destroyAllWindows()
237
+ """, language="python")
238
 
 
239
  if st.button("Go Back"):
240
  st.experimental_set_query_params(page="Introduction")