Spaces:
Sleeping
Sleeping
Update pages/Data Collection.py
Browse files- pages/Data Collection.py +92 -52
pages/Data Collection.py
CHANGED
|
@@ -1,71 +1,111 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
-
#
|
| 4 |
-
st.title("
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
- Unlike XML, HTML does not allow creating custom tags freely.
|
| 13 |
-
- Not all HTML content can be converted into dataframes, especially paragraph text or unstructured data.
|
| 14 |
-
- Typically, only table-related elements (`<table>`, `<tr>`, `<th>`, `<td>`) can be converted into dataframes.
|
| 15 |
-
""")
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
st.header("
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
-
st.
|
| 22 |
-
import pandas as pd
|
| 23 |
-
tables = pd.read_html(path_or_buffer)
|
| 24 |
-
""", language="python")
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
- Extracts all tables and returns them as a list of dataframes.
|
| 29 |
-
""")
|
| 30 |
|
| 31 |
-
|
| 32 |
-
st.
|
| 33 |
-
|
| 34 |
-
table = tables[0]
|
| 35 |
-
""", language="python")
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
st.write("""
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
| 46 |
""")
|
| 47 |
|
| 48 |
-
|
| 49 |
-
st.
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
""",
|
|
|
|
|
|
|
|
|
|
| 53 |
|
|
|
|
|
|
|
|
|
|
| 54 |
st.write("""
|
| 55 |
-
-
|
| 56 |
-
-
|
| 57 |
""")
|
| 58 |
|
| 59 |
-
#
|
| 60 |
-
st.
|
| 61 |
|
| 62 |
-
|
| 63 |
-
st.
|
| 64 |
-
|
| 65 |
-
df.to_html("output.html")
|
| 66 |
-
""", language="python")
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
""")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
+
# Title
|
| 4 |
+
st.title("πΈ Understanding Images and How to Handle Them")
|
| 5 |
|
| 6 |
+
# Helper function to style text with HTML
|
| 7 |
+
def colored_subheader(text, color):
|
| 8 |
+
st.markdown(f"<h3 style='color:{color};'>{text}</h3>", unsafe_allow_html=True)
|
| 9 |
|
| 10 |
+
# What is an Image?
|
| 11 |
+
st.header("What is an Image? πΌοΈ")
|
| 12 |
+
st.write("An image is a **2D representation of the visible light spectrum**. It is created when light reflects off objects and is captured by a device like a camera or our eyes.")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
# How is an Image Formed?
|
| 15 |
+
st.header("How is an Image Formed? ππΈ")
|
| 16 |
+
colored_subheader("1. Source of Light π", "blue")
|
| 17 |
+
st.write("- Light comes from sources like the **sun**, **moon**, or **stars**.")
|
| 18 |
|
| 19 |
+
colored_subheader("2. Reflection π", "green")
|
| 20 |
+
st.write("- Light hits an object and **bounces back** (this is called reflection).")
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
colored_subheader("3. Capture πΈ", "orange")
|
| 23 |
+
st.write("- The reflected light is captured by a camera or eyes, forming an image.")
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
colored_subheader("4. Visible Light Only π", "purple")
|
| 26 |
+
st.write("- Not all light can create images (e.g., gamma rays or X-rays are invisible).")
|
| 27 |
+
st.write("- **Visible light** is required to see and capture images.")
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
# Images and Pixels
|
| 30 |
+
st.header("Images and Pixels π¦β¬")
|
| 31 |
+
colored_subheader("What are Pixels? π", "red")
|
| 32 |
+
st.write("- Pixels are tiny squares that make up an image.")
|
| 33 |
+
st.write("- Each pixel contains information about color and brightness.")
|
| 34 |
+
|
| 35 |
+
colored_subheader("Resolution π", "darkblue")
|
| 36 |
+
st.write("- The number of pixels in an image determines its resolution.")
|
| 37 |
+
st.write("- **More pixels = Clearer image = More details.**")
|
| 38 |
+
|
| 39 |
+
# Why are Images Like a Grid?
|
| 40 |
+
st.header("Why are Images Like a Grid? π³")
|
| 41 |
+
colored_subheader("Grid Structure π§©", "darkgreen")
|
| 42 |
+
st.write("- Images are stored as grids because they are made of pixels, each representing a feature like color or brightness.")
|
| 43 |
|
| 44 |
+
colored_subheader("Difference from Tabular Data π", "teal")
|
| 45 |
+
st.write("- Tabular data has rows as data points and columns as features.")
|
| 46 |
+
st.write("- In images, the entire grid represents a **single data point**, with each pixel as a feature.")
|
| 47 |
+
|
| 48 |
+
# How Are Images Represented in Python?
|
| 49 |
+
st.header("How Are Images Represented in Python? π")
|
| 50 |
+
colored_subheader("Using NumPy Arrays π", "maroon")
|
| 51 |
+
st.write("- Images are converted into arrays of numbers for computers to process.")
|
| 52 |
+
st.write("- Example: A black-and-white image is represented as a 2D array.")
|
| 53 |
+
|
| 54 |
+
# Color Spaces in Images
|
| 55 |
+
st.header("Color Spaces in Images π")
|
| 56 |
+
|
| 57 |
+
# Black and White
|
| 58 |
+
colored_subheader("1. Black and White π΄", "black")
|
| 59 |
+
st.write("- Represents two colors: **Black (0)** and **White (255)**.")
|
| 60 |
+
st.write("- **Demerit**: Cannot preserve other colors like red, blue, or green.")
|
| 61 |
+
|
| 62 |
+
# Grayscale
|
| 63 |
+
colored_subheader("2. Grayscale π€", "gray")
|
| 64 |
+
st.write("- Preserves **256 shades of gray** (from 0 to 255).")
|
| 65 |
+
st.write("- **Demerit**: Cannot handle colored images (like red, green, blue).")
|
| 66 |
+
|
| 67 |
+
# RGB
|
| 68 |
+
colored_subheader("3. RGB (Red, Green, Blue) π", "blue")
|
| 69 |
+
st.write("- Most common color space.")
|
| 70 |
+
st.write("- Colors are created by mixing **Red**, **Green**, and **Blue** intensities.")
|
| 71 |
+
st.write("- Each channel has values ranging from **0 to 255**.")
|
| 72 |
+
st.write("- **Advantages**: Can represent up to **16 million colors**.")
|
| 73 |
+
|
| 74 |
+
# How Images are Converted to Arrays
|
| 75 |
+
st.header("How Images are Converted to Arrays π©")
|
| 76 |
+
colored_subheader("Steps to Convert Images π οΈ", "brown")
|
| 77 |
st.write("""
|
| 78 |
+
1. **Step 1: Convert the Image to Numbers**: Each pixelβs color and brightness are stored as numbers.
|
| 79 |
+
2. **Step 2: Create Arrays**:
|
| 80 |
+
- A black-and-white image becomes a **2D array** (rows and columns).
|
| 81 |
+
- A colored image (RGB) becomes a **3D array** with separate layers for red, green, and blue.
|
| 82 |
+
3. **Step 3: Process the Array**: The computer processes these arrays to analyze or modify the image.
|
| 83 |
""")
|
| 84 |
|
| 85 |
+
# Differences Between 2D and 3D Arrays in Images
|
| 86 |
+
st.header("Differences Between 2D and 3D Arrays in Images π")
|
| 87 |
+
colored_subheader("Comparison π", "indigo")
|
| 88 |
+
st.table({
|
| 89 |
+
"Type": ["2D Array (Grayscale)", "3D Array (RGB)"],
|
| 90 |
+
"Explanation": ["Used for grayscale images (shades of gray).", "Used for RGB images (multiple channels)."],
|
| 91 |
+
"Values": ["0β255", "(R, G, B) values, each 0β255"]
|
| 92 |
+
})
|
| 93 |
|
| 94 |
+
# Notes
|
| 95 |
+
st.header("Notes π")
|
| 96 |
+
colored_subheader("Key Points βοΈ", "gold")
|
| 97 |
st.write("""
|
| 98 |
+
- **Color Spaces**: Essential to represent and preserve the colors in an image.
|
| 99 |
+
- **Numpy Library**: Widely used in Python for processing images as arrays.
|
| 100 |
""")
|
| 101 |
|
| 102 |
+
# Buttons
|
| 103 |
+
col1, col2 = st.columns(2)
|
| 104 |
|
| 105 |
+
with col1:
|
| 106 |
+
if st.button("π Basic Operations Using OpenCV"):
|
| 107 |
+
st.write("Redirecting to the next section: Basic Operations Using OpenCV...")
|
|
|
|
|
|
|
| 108 |
|
| 109 |
+
with col2:
|
| 110 |
+
if st.button("π Back"):
|
| 111 |
+
st.write("Going back to the previous section...")
|
|
|