hari3485 commited on
Commit
35bec80
Β·
verified Β·
1 Parent(s): c214a99

Update pages/Data Collection.py

Browse files
Files changed (1) hide show
  1. pages/Data Collection.py +85 -104
pages/Data Collection.py CHANGED
@@ -1,111 +1,92 @@
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...")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
 
3
+ # Helper function for subheadings
4
+ def subheading(text):
5
+ """Displays a subheader with consistent styling."""
6
+ st.markdown(f"<h3 style='color:teal;'>{text}</h3>", unsafe_allow_html=True)
7
 
8
+ # Sidebar for navigation
9
+ st.sidebar.title("Navigation")
10
+ page = st.sidebar.radio("Go to", ["Introduction", "Understanding Images", "Color Spaces", "Basic Operations"])
11
 
12
+ # App Title and Description
13
+ st.title("Image Processing Fundamentals")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  st.write("""
15
+ This app introduces the basics of image processing, helping you understand how images are formed, represented, and handled programmatically.
16
+ It's designed for beginners exploring computer vision concepts.
17
  """)
18
 
19
+ # Introduction Section
20
+ if page == "Introduction":
21
+ st.header("Introduction")
22
+ st.write("""
23
+ Images play a crucial role in various fields, including art, science, and technology.
24
+ In this app, you will learn:
25
+ - How images are captured and represented.
26
+ - Different color spaces and their applications.
27
+ - Basic operations on images using Python libraries.
28
+ """)
29
+
30
+ # Understanding Images Section
31
+ elif page == "Understanding Images":
32
+ st.header("Understanding Images")
33
+
34
+ # Subsections
35
+ subheading("What is an Image?")
36
+ st.write("""
37
+ An image is a **2D representation of light**, created when light reflects off an object and is captured by a camera or our eyes.
38
+ """)
39
+
40
+ subheading("How is an Image Formed?")
41
+ st.write("""
42
+ - **Light Source**: Light from sources like the sun or a bulb hits an object.
43
+ - **Reflection**: Light bounces off the object's surface.
44
+ - **Capture**: The reflected light is recorded by a camera sensor or the human eye.
45
+ """)
46
+
47
+ subheading("Why is an Image Represented as a Grid?")
48
+ st.write("""
49
+ - Images are stored as grids of **pixels**, where each pixel represents a single point of color and brightness.
50
+ - These grids are also called **image matrices**.
51
+ """)
52
+
53
+ # Color Spaces Section
54
+ elif page == "Color Spaces":
55
+ st.header("Color Spaces")
56
+
57
+ subheading("1. Black and White")
58
+ st.write("""
59
+ - Represents two colors: **Black (0)** and **White (255)**.
60
+ - Used for simple image processing tasks where color isn't essential.
61
+ """)
62
+
63
+ subheading("2. Grayscale")
64
+ st.write("""
65
+ - Extends black and white to include **256 shades of gray**.
66
+ - Preserves brightness details but loses color information.
67
+ """)
68
+
69
+ subheading("3. RGB (Red, Green, Blue)")
70
+ st.write("""
71
+ - Combines three color channels: **Red**, **Green**, and **Blue**.
72
+ - Most commonly used for colored images, capable of representing over **16 million colors**.
73
+ """)
74
+
75
+ # Basic Operations Section
76
+ elif page == "Basic Operations":
77
+ st.header("Basic Operations Using OpenCV")
78
+ st.write("""
79
+ OpenCV is a powerful library for image processing. Here are some basic operations you can perform:
80
+ - Load and display images.
81
+ - Convert between color spaces (e.g., RGB to Grayscale).
82
+ - Resize and crop images.
83
+ - Apply filters and transformations.
84
+ """)
85
+
86
+ if st.button("Go Back"):
87
+ st.experimental_set_query_params(page="Introduction")
88
+
89
+ # Footer
90
+ st.sidebar.markdown("---")
91
+ st.sidebar.write("**Created by a 22-year-old enthusiast exploring Streamlit!**")
92
+ st.sidebar.write("[GitHub](https://github.com/your-repo) | [LinkedIn](https://linkedin.com/in/your-profile)")