Update pages/LIFE_CYCLE_OF_MACHINE_LEARNING.py
Browse files
pages/LIFE_CYCLE_OF_MACHINE_LEARNING.py
CHANGED
@@ -635,86 +635,89 @@ This explanation provides both the purpose and practical use cases of `cv2.Video
|
|
635 |
# ----- AFFINE TRANSFORMATION MATRIX -----
|
636 |
|
637 |
|
638 |
-
import streamlit as st
|
639 |
|
640 |
-
|
641 |
-
|
|
|
642 |
|
643 |
-
# Description of Affine Transformation
|
644 |
-
st.markdown("""
|
645 |
-
An **Affine Transformation** is a linear mapping method that preserves points, straight lines, and planes. In other words, it maintains the structure of the original object while allowing for operations like translation, scaling, rotation, reflection, and shearing. Affine transformations are widely used in computer graphics, computer vision, image processing, and geometry.
|
646 |
|
647 |
-
Affine transformations can be represented by a **transformation matrix** of the following form:
|
648 |
|
649 |
-
\\[
|
650 |
-
T(x, y) = \\begin{bmatrix} a & b & tx \\\\ c & d & ty \\\\ 0 & 0 & 1 \\end{bmatrix} \\begin{bmatrix} x \\\\ y \\\\ 1 \\end{bmatrix}
|
651 |
-
\\]
|
652 |
|
653 |
-
- The **matrix elements (a, b, c, d)** control the linear transformation (scaling, rotation, and shearing).
|
654 |
-
- The elements **tx and ty** represent translation (shifting the coordinates).
|
655 |
|
656 |
-
### How the Transformation Works
|
657 |
-
Given a point \\((x, y)\\), applying an affine transformation produces a new point \\((x', y')\\) calculated as:
|
658 |
|
659 |
-
\\[
|
660 |
-
\\begin{bmatrix} x' \\\\ y' \\\\ 1 \\end{bmatrix} = \\begin{bmatrix} a & b & tx \\\\ c & d & ty \\\\ 0 & 0 & 1 \\end{bmatrix} \\begin{bmatrix} x \\\\ y \\\\ 1 \\end{bmatrix}
|
661 |
-
\\]
|
662 |
|
663 |
-
This means:
|
664 |
-
- \\(x' = a \\cdot x + b \\cdot y + tx\\)
|
665 |
-
- \\(y' = c \\cdot x + d \\cdot y + ty\\)
|
666 |
|
667 |
-
Affine transformations can be visualized as applying a series of transformations to geometric shapes.
|
668 |
-
""")
|
669 |
|
670 |
-
# Key Points Section
|
671 |
-
st.header("Key Points of Affine Transformations")
|
672 |
|
673 |
-
st.markdown("""
|
674 |
-
### 1. **Preserves Collinearity**
|
675 |
-
- Points that lie on a straight line before transformation remain on a straight line after transformation.
|
676 |
-
|
677 |
-
### 2. **Preserves Ratios of Distances**
|
678 |
-
- The ratio of distances between points on a line remains unchanged after transformation.
|
679 |
-
|
680 |
-
### 3. **Common Operations**
|
681 |
-
Affine transformations can perform the following operations:
|
682 |
-
- **Translation**: Moves the object along the x and y axes.
|
683 |
-
- **Scaling**: Changes the size of the object (uniform or non-uniform).
|
684 |
-
- **Rotation**: Rotates the object around a specific point (usually the origin).
|
685 |
-
- **Shearing**: Skews the object along one or both axes.
|
686 |
-
- **Reflection**: Mirrors the object about a specific axis (e.g., x-axis or y-axis).
|
687 |
-
|
688 |
-
### 4. **2D Affine Transformation Matrix**
|
689 |
-
The general 2D affine transformation matrix can be expressed as:
|
690 |
-
|
691 |
-
\\[
|
692 |
-
\\begin{bmatrix} a & b & tx \\\\ c & d & ty \\\\ 0 & 0 & 1 \\end{bmatrix}
|
693 |
-
\\]
|
694 |
-
|
695 |
-
Where:
|
696 |
-
- \\(a, b, c, d\\) represent the linear transformations (scaling, rotation, shearing).
|
697 |
-
- \\(tx, ty\\) represent translation.
|
698 |
-
|
699 |
-
### 5. **Combining Transformations**
|
700 |
-
- Multiple affine transformations can be combined by multiplying their matrices.
|
701 |
-
- **Order Matters**: The order in which transformations are applied affects the final result (matrix multiplication is non-commutative).
|
702 |
-
|
703 |
-
### 6. **Applications of Affine Transformations**
|
704 |
-
- **Computer Graphics**: Transforming and rendering shapes and images.
|
705 |
-
- **Image Processing**: Geometric operations like rotation, scaling, and shearing of images.
|
706 |
-
- **Computer Vision**: Object detection, pattern recognition, and image alignment.
|
707 |
-
- **Robotics**: Coordinate transformations for motion planning and navigation.
|
708 |
-
- **Geographical Information Systems (GIS)**: Map projection and alignment.
|
709 |
-
|
710 |
-
### 7. **Homogeneous Coordinates**
|
711 |
-
Using homogeneous coordinates \\((x, y, 1)\\) allows us to unify translation with linear transformations in a single matrix operation. This simplifies the combination and chaining of multiple transformations.
|
712 |
-
""")
|
713 |
|
714 |
-
# Navigation Button
|
715 |
-
if st.button("Back to Data Collection"):
|
716 |
-
|
717 |
|
|
|
|
|
|
|
718 |
|
719 |
|
720 |
|
|
|
635 |
# ----- AFFINE TRANSFORMATION MATRIX -----
|
636 |
|
637 |
|
|
|
638 |
|
639 |
+
def affine_transformation_matrix():
|
640 |
+
# Header for Affine Transformation Matrix
|
641 |
+
st.header("Affine Transformation Matrix")
|
642 |
|
643 |
+
# Description of Affine Transformation
|
644 |
+
st.markdown("""
|
645 |
+
An **Affine Transformation** is a linear mapping method that preserves points, straight lines, and planes. In other words, it maintains the structure of the original object while allowing for operations like translation, scaling, rotation, reflection, and shearing. Affine transformations are widely used in computer graphics, computer vision, image processing, and geometry.
|
646 |
|
647 |
+
Affine transformations can be represented by a **transformation matrix** of the following form:
|
648 |
|
649 |
+
\\[
|
650 |
+
T(x, y) = \\begin{bmatrix} a & b & tx \\\\ c & d & ty \\\\ 0 & 0 & 1 \\end{bmatrix} \\begin{bmatrix} x \\\\ y \\\\ 1 \\end{bmatrix}
|
651 |
+
\\]
|
652 |
|
653 |
+
- The **matrix elements (a, b, c, d)** control the linear transformation (scaling, rotation, and shearing).
|
654 |
+
- The elements **tx and ty** represent translation (shifting the coordinates).
|
655 |
|
656 |
+
### How the Transformation Works
|
657 |
+
Given a point \\((x, y)\\), applying an affine transformation produces a new point \\((x', y')\\) calculated as:
|
658 |
|
659 |
+
\\[
|
660 |
+
\\begin{bmatrix} x' \\\\ y' \\\\ 1 \\end{bmatrix} = \\begin{bmatrix} a & b & tx \\\\ c & d & ty \\\\ 0 & 0 & 1 \\end{bmatrix} \\begin{bmatrix} x \\\\ y \\\\ 1 \\end{bmatrix}
|
661 |
+
\\]
|
662 |
|
663 |
+
This means:
|
664 |
+
- \\(x' = a \\cdot x + b \\cdot y + tx\\)
|
665 |
+
- \\(y' = c \\cdot x + d \\cdot y + ty\\)
|
666 |
|
667 |
+
Affine transformations can be visualized as applying a series of transformations to geometric shapes.
|
668 |
+
""")
|
669 |
|
670 |
+
# Key Points Section
|
671 |
+
st.header("Key Points of Affine Transformations")
|
672 |
|
673 |
+
st.markdown("""
|
674 |
+
### 1. **Preserves Collinearity**
|
675 |
+
- Points that lie on a straight line before transformation remain on a straight line after transformation.
|
676 |
+
|
677 |
+
### 2. **Preserves Ratios of Distances**
|
678 |
+
- The ratio of distances between points on a line remains unchanged after transformation.
|
679 |
+
|
680 |
+
### 3. **Common Operations**
|
681 |
+
Affine transformations can perform the following operations:
|
682 |
+
- **Translation**: Moves the object along the x and y axes.
|
683 |
+
- **Scaling**: Changes the size of the object (uniform or non-uniform).
|
684 |
+
- **Rotation**: Rotates the object around a specific point (usually the origin).
|
685 |
+
- **Shearing**: Skews the object along one or both axes.
|
686 |
+
- **Reflection**: Mirrors the object about a specific axis (e.g., x-axis or y-axis).
|
687 |
+
|
688 |
+
### 4. **2D Affine Transformation Matrix**
|
689 |
+
The general 2D affine transformation matrix can be expressed as:
|
690 |
+
|
691 |
+
\\[
|
692 |
+
\\begin{bmatrix} a & b & tx \\\\ c & d & ty \\\\ 0 & 0 & 1 \\end{bmatrix}
|
693 |
+
\\]
|
694 |
+
|
695 |
+
Where:
|
696 |
+
- \\(a, b, c, d\\) represent the linear transformations (scaling, rotation, shearing).
|
697 |
+
- \\(tx, ty\\) represent translation.
|
698 |
+
|
699 |
+
### 5. **Combining Transformations**
|
700 |
+
- Multiple affine transformations can be combined by multiplying their matrices.
|
701 |
+
- **Order Matters**: The order in which transformations are applied affects the final result (matrix multiplication is non-commutative).
|
702 |
+
|
703 |
+
### 6. **Applications of Affine Transformations**
|
704 |
+
- **Computer Graphics**: Transforming and rendering shapes and images.
|
705 |
+
- **Image Processing**: Geometric operations like rotation, scaling, and shearing of images.
|
706 |
+
- **Computer Vision**: Object detection, pattern recognition, and image alignment.
|
707 |
+
- **Robotics**: Coordinate transformations for motion planning and navigation.
|
708 |
+
- **Geographical Information Systems (GIS)**: Map projection and alignment.
|
709 |
+
|
710 |
+
### 7. **Homogeneous Coordinates**
|
711 |
+
Using homogeneous coordinates \\((x, y, 1)\\) allows us to unify translation with linear transformations in a single matrix operation. This simplifies the combination and chaining of multiple transformations.
|
712 |
+
""")
|
713 |
|
714 |
+
# Navigation Button
|
715 |
+
if st.button("Back to Data Collection"):
|
716 |
+
st.session_state.page = "data_collection"
|
717 |
|
718 |
+
# Call the function
|
719 |
+
if __name__ == "__main__":
|
720 |
+
affine_transformation_matrix()
|
721 |
|
722 |
|
723 |
|