Update pages/Life_cycle_of_ML.py
Browse files- 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 |
-
|
|
|
|
| 575 |
|
| 576 |
-
#
|
| 577 |
-
|
| 578 |
|
| 579 |
-
if
|
| 580 |
-
|
| 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 |
-
|
| 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 |
-
#
|
| 598 |
-
|
| 599 |
-
|
| 600 |
|
| 601 |
-
|
| 602 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 603 |
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 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 |
-
|
| 612 |
-
|
| 613 |
-
# Resize the image to 100x100 pixels
|
| 614 |
-
resized_image = cv2.resize(image, (100, 100))
|
| 615 |
-
""", language='python')
|
| 616 |
|
| 617 |
-
|
| 618 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 619 |
|
| 620 |
-
|
| 621 |
-
|
| 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 |
-
|
| 628 |
-
|
| 629 |
-
# Flatten the resized image into a 1D array
|
| 630 |
-
flattened_image = resized_image.flatten()
|
| 631 |
-
""", language='python')
|
| 632 |
|
| 633 |
-
|
| 634 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 635 |
|
| 636 |
-
|
| 637 |
-
|
| 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 |
-
|
| 644 |
-
|
| 645 |
-
|
| 646 |
-
|
| 647 |
-
|
|
|
|
| 648 |
|
| 649 |
-
|
| 650 |
-
|
|
|
|
| 651 |
|
| 652 |
-
|
| 653 |
-
|
| 654 |
-
|
| 655 |
-
|
|
|
|
|
|
|
|
|
|
| 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'
|