Phaneendrabayi commited on
Commit
79ba264
·
verified ·
1 Parent(s): f6fbb72

Update pages/Life_cycle_of_ML.py

Browse files
Files changed (1) hide show
  1. pages/Life_cycle_of_ML.py +65 -28
pages/Life_cycle_of_ML.py CHANGED
@@ -624,76 +624,113 @@ def More():
624
 
625
  def table():
626
  # Streamlit page title
627
- # Streamlit page title
628
- st.title("Image Processing: Resize and Flatten Multiple Images into Tabular Data")
629
-
630
  # Allow user to upload multiple image files
631
  uploaded_files = st.file_uploader("Choose images...", type=["jpg", "jpeg", "png"], accept_multiple_files=True)
632
-
633
  if uploaded_files:
634
  st.write(f"Found {len(uploaded_files)} images to process.")
635
-
 
 
 
 
 
 
636
  image_data_list = [] # To store the DataFrame for each image
637
-
638
  # Process each uploaded image
639
  for uploaded_file in uploaded_files:
640
  st.write(f"Processing {uploaded_file.name}...")
641
-
642
  # Step 1: Load image using OpenCV
643
  st.write("### Step 1: Load the Image")
644
  st.write("""
645
  In this step, we load the uploaded image using OpenCV. The image is first read as raw bytes,
646
  which are then decoded into an image using OpenCV's `cv2.imdecode()` function.
647
  """)
648
-
649
  # Load the image
650
  image_array = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
651
  image = cv2.imdecode(image_array, cv2.IMREAD_COLOR)
652
-
653
  # Show the original image
654
- st.image(image, caption=f"Original Image: {uploaded_file.name}", channels="BGR", use_column_width=True)
655
-
656
- # Step 2: Resize image to 100x100 pixels using OpenCV
657
- st.write("### Step 2: Resize the Image")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
658
  st.write("""
659
  In this step, we resize the image to a 100x100 resolution using OpenCV's `cv2.resize()` function.
660
  Resizing the image reduces the number of pixels, making it easier to process in further steps.
661
  """)
662
-
663
  # Resize the image
664
- resized_image = cv2.resize(image, (100, 100))
665
-
666
  # Show the resized image
667
- st.image(resized_image, caption=f"Resized Image: {uploaded_file.name}", channels="BGR", use_column_width=True)
668
-
669
- # Step 3: Flatten the image into a 1D array
670
- st.write("### Step 3: Flatten the Image")
671
  st.write("""
672
  After resizing the image, we flatten it into a 1D array. This process involves converting the
673
- 2D matrix of pixels into a single row of values, which can be used for further analysis or modeling.
674
  """)
675
-
676
  # Flatten the resized image
677
  flattened_image = resized_image.flatten()
678
-
679
- # Step 4: Create DataFrame with the flattened image data
680
- st.write("### Step 4: Create DataFrame")
681
  st.write("""
682
  Finally, we convert the flattened image data into a Pandas DataFrame. This allows us to work
683
  with the pixel data in a tabular format, which is useful for further data analysis, machine learning, etc.
684
  """)
685
-
686
  # Create a DataFrame for the flattened image
687
  image_data = pd.DataFrame(flattened_image.reshape(1, -1))
 
 
 
688
  st.dataframe(image_data.head()) # Show the flattened image data
689
-
690
  # Append the image data to the list
691
  image_data_list.append(image_data)
692
-
693
  # Combine all image DataFrames into one
694
  all_image_data = pd.concat(image_data_list, ignore_index=True)
695
  st.write("### Combined DataFrame from All Images")
696
  st.dataframe(all_image_data) # Display the combined DataFrame
 
 
697
 
698
 
699
  if 'page' not in st.session_state:
 
624
 
625
  def table():
626
  # Streamlit page title
627
+ st.title("Image Processing: Convert to Grayscale or Color and Flatten into Tabular Data")
628
+
 
629
  # Allow user to upload multiple image files
630
  uploaded_files = st.file_uploader("Choose images...", type=["jpg", "jpeg", "png"], accept_multiple_files=True)
631
+
632
  if uploaded_files:
633
  st.write(f"Found {len(uploaded_files)} images to process.")
634
+
635
+ # Option to choose processing type
636
+ processing_option = st.selectbox(
637
+ "Choose the processing option:",
638
+ ("Convert to Grayscale and Tabular Data", "Keep as Color and Tabular Data")
639
+ )
640
+
641
  image_data_list = [] # To store the DataFrame for each image
642
+
643
  # Process each uploaded image
644
  for uploaded_file in uploaded_files:
645
  st.write(f"Processing {uploaded_file.name}...")
646
+
647
  # Step 1: Load image using OpenCV
648
  st.write("### Step 1: Load the Image")
649
  st.write("""
650
  In this step, we load the uploaded image using OpenCV. The image is first read as raw bytes,
651
  which are then decoded into an image using OpenCV's `cv2.imdecode()` function.
652
  """)
653
+
654
  # Load the image
655
  image_array = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
656
  image = cv2.imdecode(image_array, cv2.IMREAD_COLOR)
657
+
658
  # Show the original image
659
+ st.image(image, caption=f"Original Image: {uploaded_file.name}", use_column_width=True, channels="BGR")
660
+
661
+ # Step 2: Convert image based on the selected option
662
+ if processing_option == "Convert to Grayscale and Tabular Data":
663
+ st.write("### Step 2: Convert to Grayscale")
664
+ st.write("""
665
+ In this step, the image is converted to grayscale using OpenCV's `cv2.cvtColor()` function.
666
+ Grayscale images have a single channel, making them simpler to process.
667
+ """)
668
+
669
+ # Convert to grayscale
670
+ processed_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
671
+
672
+ # Show the grayscale image
673
+ st.image(processed_image, caption=f"Grayscale Image: {uploaded_file.name}", use_column_width=True)
674
+
675
+ else:
676
+ st.write("### Step 2: Keep as Color")
677
+ st.write("""
678
+ In this step, the image is kept in its original color format (BGR). Color images have three channels,
679
+ representing blue, green, and red pixel values.
680
+ """)
681
+
682
+ # Keep the original color image
683
+ processed_image = image
684
+
685
+ # Show the color image
686
+ st.image(processed_image, caption=f"Color Image: {uploaded_file.name}", use_column_width=True, channels="BGR")
687
+
688
+ # Step 3: Resize image to 100x100 pixels using OpenCV
689
+ st.write("### Step 3: Resize the Image")
690
  st.write("""
691
  In this step, we resize the image to a 100x100 resolution using OpenCV's `cv2.resize()` function.
692
  Resizing the image reduces the number of pixels, making it easier to process in further steps.
693
  """)
694
+
695
  # Resize the image
696
+ resized_image = cv2.resize(processed_image, (100, 100))
697
+
698
  # Show the resized image
699
+ st.image(resized_image, caption=f"Resized Image: {uploaded_file.name}", use_column_width=True, channels="BGR" if len(resized_image.shape) == 3 else None)
700
+
701
+ # Step 4: Flatten the image into a 1D array
702
+ st.write("### Step 4: Flatten the Image")
703
  st.write("""
704
  After resizing the image, we flatten it into a 1D array. This process involves converting the
705
+ 2D matrix (and channels if color) of pixels into a single row of values, which can be used for further analysis or modeling.
706
  """)
707
+
708
  # Flatten the resized image
709
  flattened_image = resized_image.flatten()
710
+
711
+ # Step 5: Create DataFrame with the flattened image data
712
+ st.write("### Step 5: Create DataFrame")
713
  st.write("""
714
  Finally, we convert the flattened image data into a Pandas DataFrame. This allows us to work
715
  with the pixel data in a tabular format, which is useful for further data analysis, machine learning, etc.
716
  """)
717
+
718
  # Create a DataFrame for the flattened image
719
  image_data = pd.DataFrame(flattened_image.reshape(1, -1))
720
+
721
+ # Add a column to indicate grayscale or color
722
+ image_data['Processing_Type'] = "Grayscale" if processing_option == "Convert to Grayscale and Tabular Data" else "Color"
723
  st.dataframe(image_data.head()) # Show the flattened image data
724
+
725
  # Append the image data to the list
726
  image_data_list.append(image_data)
727
+
728
  # Combine all image DataFrames into one
729
  all_image_data = pd.concat(image_data_list, ignore_index=True)
730
  st.write("### Combined DataFrame from All Images")
731
  st.dataframe(all_image_data) # Display the combined DataFrame
732
+
733
+
734
 
735
 
736
  if 'page' not in st.session_state: