Phaneendrabayi commited on
Commit
073e87d
·
verified ·
1 Parent(s): cab452e

Update pages/Life_cycle_of_ML.py

Browse files
Files changed (1) hide show
  1. pages/Life_cycle_of_ML.py +55 -70
pages/Life_cycle_of_ML.py CHANGED
@@ -571,92 +571,77 @@ def More():
571
 
572
  def table():
573
  # Streamlit page title
574
- st.title("Image Processing: Resize and Flatten to Tabular Data")
 
575
 
576
- # Upload image
577
- uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"], accept_multiple_files=True)
578
 
579
- if uploaded_file is not None:
580
- # Step 1: Load image using OpenCV
581
- st.write("### Step 1: Load the Image")
582
- st.write("""
583
- In this step, we load the uploaded image using OpenCV. The image is first read as raw bytes,
584
- which are then decoded into an image using OpenCV's `cv2.imdecode()` function.
585
- """)
586
-
587
- # Show the code for loading the image
588
- st.code("""
589
- import numpy as np
590
- import cv2
591
 
592
- # Load the uploaded image
593
- image_array = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
594
- image = cv2.imdecode(image_array, cv2.IMREAD_COLOR)
595
- """, language='python')
596
 
597
- # Load and display the image
598
- image_array = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
599
- image = cv2.imdecode(image_array, cv2.IMREAD_COLOR)
600
 
601
- # Show the original image
602
- st.image(image, caption="Original Image", channels="BGR")
 
 
 
 
603
 
604
- # Step 2: Resize image to 100x100 pixels using OpenCV
605
- st.write("### Step 2: Resize the Image")
606
- st.write("""
607
- In this step, we resize the image to a 100x100 resolution using OpenCV's `cv2.resize()` function.
608
- Resizing the image reduces the number of pixels, making it easier to process in further steps.
609
- """)
610
 
611
- # Show the code for resizing the image
612
- st.code("""
613
- # Resize the image to 100x100 pixels
614
- resized_image = cv2.resize(image, (100, 100))
615
- """, language='python')
616
 
617
- # Resize and display the resized image
618
- resized_image = cv2.resize(image, (100, 100))
 
 
 
 
619
 
620
- # Step 3: Flatten the image into a 1D array
621
- st.write("### Step 3: Flatten the Image")
622
- st.write("""
623
- After resizing the image, we flatten it into a 1D array. This process involves converting the
624
- 2D matrix of pixels into a single row of values, which can be used for further analysis or modeling.
625
- """)
626
 
627
- # Show the code for flattening the image
628
- st.code("""
629
- # Flatten the resized image into a 1D array
630
- flattened_image = resized_image.flatten()
631
- """, language='python')
632
 
633
- # Flatten the resized image
634
- flattened_image = resized_image.flatten()
 
 
 
 
635
 
636
- # Step 4: Create a DataFrame with the flattened image data
637
- st.write("### Step 4: Create DataFrame")
638
- st.write("""
639
- Finally, we convert the flattened image data into a Pandas DataFrame. This allows us to work
640
- with the pixel data in a tabular format, which is useful for further data analysis, machine learning, etc.
641
- """)
642
 
643
- # Show the code for creating the DataFrame
644
- st.code("""
645
- # Create a DataFrame to store the flattened image data
646
- image_data = pd.DataFrame(flattened_image.reshape(1, -1))
647
- """, language='python')
 
648
 
649
- # Convert the flattened image to DataFrame
650
- image_data = pd.DataFrame(flattened_image.reshape(1, -1))
 
651
 
652
- # Display the resized image and its pixel data
653
- st.write(f"Resized Image Shape: {resized_image.shape}")
654
- st.write("Flattened Image Data (first few pixels):")
655
- st.dataframe(image_data.head()) # Displaying the first few pixels
 
 
 
656
 
657
- # Optional: Show resized image
658
- st.image(resized_image, caption="Resized Image (100x100)", channels="BGR")
659
-
660
 
661
  if 'page' not in st.session_state:
662
  st.session_state.page = 'main'
 
571
 
572
  def table():
573
  # Streamlit page title
574
+ # Streamlit page title
575
+ st.title("Image Processing: Resize and Flatten Multiple Images into Tabular Data")
576
 
577
+ # Allow user to upload multiple image files
578
+ uploaded_files = st.file_uploader("Choose images...", type=["jpg", "jpeg", "png"], accept_multiple_files=True)
579
 
580
+ if uploaded_files:
581
+ st.write(f"Found {len(uploaded_files)} images to process.")
 
 
 
 
 
 
 
 
 
 
582
 
583
+ image_data_list = [] # To store the DataFrame for each image
 
 
 
584
 
585
+ # Process each uploaded image
586
+ for uploaded_file in uploaded_files:
587
+ st.write(f"Processing {uploaded_file.name}...")
588
 
589
+ # Step 1: Load image using OpenCV
590
+ st.write("### Step 1: Load the Image")
591
+ st.write("""
592
+ In this step, we load the uploaded image using OpenCV. The image is first read as raw bytes,
593
+ which are then decoded into an image using OpenCV's `cv2.imdecode()` function.
594
+ """)
595
 
596
+ # Load the image
597
+ image_array = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
598
+ image = cv2.imdecode(image_array, cv2.IMREAD_COLOR)
 
 
 
599
 
600
+ # Show the original image
601
+ st.image(image, caption=f"Original Image: {uploaded_file.name}", channels="BGR", use_column_width=True)
 
 
 
602
 
603
+ # Step 2: Resize image to 100x100 pixels using OpenCV
604
+ st.write("### Step 2: Resize the Image")
605
+ st.write("""
606
+ In this step, we resize the image to a 100x100 resolution using OpenCV's `cv2.resize()` function.
607
+ Resizing the image reduces the number of pixels, making it easier to process in further steps.
608
+ """)
609
 
610
+ # Resize the image
611
+ resized_image = cv2.resize(image, (100, 100))
 
 
 
 
612
 
613
+ # Show the resized image
614
+ st.image(resized_image, caption=f"Resized Image: {uploaded_file.name}", channels="BGR", use_column_width=True)
 
 
 
615
 
616
+ # Step 3: Flatten the image into a 1D array
617
+ st.write("### Step 3: Flatten the Image")
618
+ st.write("""
619
+ After resizing the image, we flatten it into a 1D array. This process involves converting the
620
+ 2D matrix of pixels into a single row of values, which can be used for further analysis or modeling.
621
+ """)
622
 
623
+ # Flatten the resized image
624
+ flattened_image = resized_image.flatten()
 
 
 
 
625
 
626
+ # Step 4: Create DataFrame with the flattened image data
627
+ st.write("### Step 4: Create DataFrame")
628
+ st.write("""
629
+ Finally, we convert the flattened image data into a Pandas DataFrame. This allows us to work
630
+ with the pixel data in a tabular format, which is useful for further data analysis, machine learning, etc.
631
+ """)
632
 
633
+ # Create a DataFrame for the flattened image
634
+ image_data = pd.DataFrame(flattened_image.reshape(1, -1))
635
+ st.dataframe(image_data.head()) # Show the flattened image data
636
 
637
+ # Append the image data to the list
638
+ image_data_list.append(image_data)
639
+
640
+ # Combine all image DataFrames into one
641
+ all_image_data = pd.concat(image_data_list, ignore_index=True)
642
+ st.write("### Combined DataFrame from All Images")
643
+ st.dataframe(all_image_data) # Display the combined DataFrame
644
 
 
 
 
645
 
646
  if 'page' not in st.session_state:
647
  st.session_state.page = 'main'