File size: 7,140 Bytes
0680886
 
a2117d9
 
0680886
a2117d9
 
0680886
a2117d9
b0e6cc8
a2117d9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78df14f
eab2aad
78df14f
 
 
 
 
eab2aad
0cebdf6
78df14f
eab2aad
78df14f
eab2aad
 
 
78df14f
 
 
 
 
 
 
 
 
 
 
 
0cebdf6
e8f7c04
 
 
78df14f
 
 
 
e8f7c04
78df14f
 
e8f7c04
a000c45
78df14f
 
 
 
 
 
 
 
 
 
a000c45
 
 
0f3289a
6905936
 
42980c2
78df14f
 
 
 
7e76b45
78df14f
 
7e76b45
 
78df14f
 
 
 
 
 
 
 
7e76b45
 
 
1309a5e
78df14f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1309a5e
78df14f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1309a5e
78df14f
42980c2
 
78df14f
 
 
 
 
 
 
2c93cdc
 
78df14f
 
 
 
 
 
 
 
 
 
 
 
 
 
2c93cdc
 
 
6b3ac51
4bb9622
fa7bc60
4bb9622
6b3ac51
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import streamlit as st

if "page" not in st.session_state:
    st.session_state.page = "Home"

def navigate_to(page_name):
    st.session_state.page = page_name

if st.session_state.page == "Home":
    st.title("   :red[Image Augmentation]  ")
    st.header("What is Augmented Image")
    st.markdown(""" It is a techinque by using which we can apply a geometrical transform to create a **Augmented Image**
                    **Image Augmentation** is a technique used in computer vision and deep learning to artificially expand the size and diversity of a training dataset by applying various transformations to existing images. 
                    This helps improve the robustness and generalization ability of models, especially when the amount of labeled data is limited.""")
    st.markdown("""
    - Transformation are of two types:
    1. Affine Transformation
    2. Non-Affine Transformation.
    """)
    st.header("πŸ” Why Use Image Augmentation?")
    st.markdown("""
    - **Prevents overfitting** by exposing the model to varied inputs.
    - Improves generalization to unseen data.
    - Simulates real-world variability (e.g., rotation, lighting changes, noise).
    """)
    st.header("πŸŒ€πŸ“πŸ”€ What is Affine Transformation")
    st.markdown(""" 
    - Preserved parallelsim between the lines.
    - Sometimes the angles are preserved.
    """)
    st.header(":red[Types Of Affine Transformation]")

    descriptions = {
        '1.Translation(Shifting)': "**Translation** : Shifts the image along x or y axis.",
        '2.Rotating': "**Rotating** : Rotates the image by a certain angle.",
        '3.Scaling': "**Scaling** : Zooming in or out.",
        '4.Cropping': "**Cropping** : Random or center cropping.",
        '5.Stretching(shearing)': "**Stretching** : Vertical shearing slants the image along the y-axis,Horizontal shearing slants the image along the x-axis."
    }

    step = st.selectbox("Select the type of affine transformation :", list(descriptions.keys()))
    st.write(descriptions[step])

    if step == '1.Translation(Shifting)':
        if st.button("Learn More About Translation"):
            navigate_to("Translation")
    if step == '2.Rotating':
        if st.button("Learn More About Rotating"):
            navigate_to("Rotating")
    if step == '3.Scaling':
        if st.button("Learn More About Scaling"):
            navigate_to("Scaling")
    if step == '4.Cropping':
        if st.button("Learn More About Cropping"):
            navigate_to("Cropping")
    if step == '5.Stretching(shearing)':
        if st.button("Learn More About Shearing"):
            navigate_to("Shearing")

elif st.session_state.page == "Translation":
    st.title("1. 🚚 Translation (Shifting)")
    st.write('''
        Definition:
        Translation moves the entire image (or object in it) left, right, up, or down without rotating or changing its size or shape.
    ''')
    st.image("Images/translationform.jpg", caption="Mathmetical Form", width=500)
    st.write('''Example:
        Moving an image 10 pixels to the right and 5 pixels down.
    ''')
    st.subheader("Code:")
    st.code("""
import cv2
import numpy as np
tx = -50
ty = -50
tm = np.array([[1, 0, tx], [0, 1, ty]], dtype=np.float32)
trans_img = cv2.warpAffine(img, tm, dsize=(500, 700))
cv2.imshow("originalimg", img)
cv2.imshow("translateimg", trans_img)
cv2.waitKey()
cv2.destroyAllWindows()""", language="python")
    st.markdown("<hr>", unsafe_allow_html=True)
    if st.button("Back to Home Page"):
        navigate_to("Home")

elif st.session_state.page == "Rotating":
    st.title("2. πŸ”„ Rotation")
    st.write('''
        Definition:
        Rotation turns the image around a fixed center point (usually the center of the image) by a certain angle.
    ''')
    st.image("Images/RotationForm.jpg.png", caption="Mathmetical Form", width=500)
    st.write('''Example:
        Rotating an image 45Β° counterclockwise.
    ''')
    st.subheader("Code:")
    st.code("""
import cv2
import numpy as np
rm = cv2.getRotationMatrix2D((img.shape[0]//2, img.shape[1]//2), 90, 1)
rimg = cv2.warpAffine(img, rm, (480, 640))
cv2.imshow("originalimg", img)
cv2.imshow("Rotationimg", rimg)
cv2.waitKey()
cv2.destroyAllWindows()""", language="python")
    st.markdown("<hr>", unsafe_allow_html=True)
    if st.button("Back to Home Page"):
        navigate_to("Home")

elif st.session_state.page == "Scaling":
    st.title("3.πŸ” Scaling")
    st.write('''
        Definition:
        Scaling resizes the image, either enlarging or shrinking it, along x and/or y axes.
    ''')
    st.image("Images/ScalingForm.jpg", caption="Mathmetical Form", width=500)
    st.write('''Example:
        Zooming in by a factor of 1.2 (i.e., 120% of original size).
    ''')
    st.subheader("Code:")
    st.code("""
import cv2
import numpy as np
sx = 2
sy = 2
tx = 50
ty = 50
sm = np.array([[sx, 0, tx], [0, sy, ty]], dtype=np.float32)
img1 = cv2.warpAffine(img, sm, (2*480, 2*640))
cv2.imshow("originalimg", img)
cv2.imshow("Scaling", img1)
cv2.waitKey()
cv2.destroyAllWindows()""", language="python")
    st.markdown("<hr>", unsafe_allow_html=True)
    if st.button("Back to Home Page"):
        navigate_to("Home")

elif st.session_state.page == "Cropping":
    st.title("4βœ‚οΈ Cropping")
    st.write('''
        Definition:
        Cropping selects a smaller rectangular region from the original image and removes the rest.
    ''')
    st.image("Images/Croppingform.jpg", caption="Mathmetical Form", width=500)
    st.write('''Example:
        Extracting a 100Γ—100 pixel region from the center of a 256Γ—256 image.
    ''')
    st.subheader("Code:")
    st.code("""
import cv2
import numpy as np
img1 = img[40:450, 50:400]
cv2.imshow("originalimg", img)
cv2.imshow("Croppingimg", img1)
cv2.waitKey()
cv2.destroyAllWindows()""", language="python")
    st.markdown("<hr>", unsafe_allow_html=True)
    if st.button("Back to Home Page"):
        navigate_to("Home")

elif st.session_state.page == "Shearing":
    st.title("5. πŸ“Shearing (or stretching)")
    st.write('''
        Definition:
        Shearing transforms an image such that:
        - Vertical shearing slants the image along the y-axis.
        - Horizontal shearing slants the image along the x-axis.
        It changes the angles of the object but preserves parallel lines.
    ''')
    st.image("Images/Shearingform.jpg", caption="Mathmetical Form", width=500)
    st.subheader("Code:")
    st.code("""
import cv2
import numpy as np
sx = 1
sy = 1
tx = 0
ty = 0
shx = 1
shy = 0
shm = np.array([[sx, shx, tx], [shy, sy, ty]], dtype=np.float32)
img1 = cv2.warpAffine(img, shm, (480, 640))
cv2.imshow("originalimg", img)
cv2.imshow("Shearingimg", img1)
cv2.waitKey()
cv2.destroyAllWindows()""", language="python")
    st.markdown("<hr>", unsafe_allow_html=True)
    if st.button("Back to Home Page"):
        navigate_to("Home")

if st.button("Next Page"):
    st.switch_page("pages/Transforming_the_images.py")

st.markdown("<hr>", unsafe_allow_html=True)
st.markdown("<p style='text-align: center;'>🚧 Created with ❀️ using Streamlit</p>", unsafe_allow_html=True)