LakshmiHarika commited on
Commit
da286be
·
verified ·
1 Parent(s): f7e74b6

Update pages/Data Collection.py

Browse files
Files changed (1) hide show
  1. pages/Data Collection.py +34 -21
pages/Data Collection.py CHANGED
@@ -462,33 +462,46 @@ elif st.session_state.current_page == "explore_images_video":
462
  RGB is the most common color space used in digital imaging and is ideal for screens and devices that emit light.
463
  """)
464
 
 
 
465
  st.subheader("Visualization of RGB Channels")
466
 
467
- # Load an example image (you can use any image)
468
- uploaded_file = st.file_uploader("Upload an Image", type=["jpg", "png"])
469
- if uploaded_file:
 
 
470
  img = Image.open(uploaded_file)
471
  img_array = np.array(img)
472
 
473
- # Split into channels
474
- red_channel = img_array[:, :, 0]
475
- green_channel = img_array[:, :, 1]
476
- blue_channel = img_array[:, :, 2]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
477
 
478
- # Plot the channels
479
- fig, ax = plt.subplots(1, 4, figsize=(12, 4))
480
- ax[0].imshow(img)
481
- ax[0].set_title("Original Image")
482
- ax[1].imshow(red_channel, cmap="Reds")
483
- ax[1].set_title("Red Channel")
484
- ax[2].imshow(green_channel, cmap="Greens")
485
- ax[2].set_title("Green Channel")
486
- ax[3].imshow(blue_channel, cmap="Blues")
487
- ax[3].set_title("Blue Channel")
488
- for a in ax:
489
- a.axis("off")
490
- st.pyplot(fig)
491
-
492
 
493
 
494
  # Go Back Button
 
462
  RGB is the most common color space used in digital imaging and is ideal for screens and devices that emit light.
463
  """)
464
 
465
+
466
+ # Subheader for the section
467
  st.subheader("Visualization of RGB Channels")
468
 
469
+ # File uploader for the user to upload an image
470
+ uploaded_file = st.file_uploader("Upload an Image (JPG or PNG):", type=["jpg", "png"])
471
+
472
+ if uploaded_file is not None:
473
+ # Open the uploaded image
474
  img = Image.open(uploaded_file)
475
  img_array = np.array(img)
476
 
477
+ # Ensure the image has three channels (for RGB visualization)
478
+ if img_array.shape[-1] == 3:
479
+ # Split the image into its RGB channels
480
+ red_channel = img_array[:, :, 0]
481
+ green_channel = img_array[:, :, 1]
482
+ blue_channel = img_array[:, :, 2]
483
+
484
+ # Plot the original image and the three channels
485
+ fig, ax = plt.subplots(1, 4, figsize=(15, 5))
486
+ ax[0].imshow(img)
487
+ ax[0].set_title("Original Image")
488
+ ax[1].imshow(red_channel, cmap="Reds")
489
+ ax[1].set_title("Red Channel")
490
+ ax[2].imshow(green_channel, cmap="Greens")
491
+ ax[2].set_title("Green Channel")
492
+ ax[3].imshow(blue_channel, cmap="Blues")
493
+ ax[3].set_title("Blue Channel")
494
+
495
+ # Remove axis labels and ticks
496
+ for a in ax:
497
+ a.axis("off")
498
+
499
+ # Render the plot in Streamlit
500
+ st.pyplot(fig)
501
+ else:
502
+ st.error("The uploaded image does not have 3 color channels (RGB). Please upload an RGB image.")
503
+
504
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
505
 
506
 
507
  # Go Back Button