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("
", 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("
", 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("
", 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("
", 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("
", 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("
", unsafe_allow_html=True) st.markdown("

🚧 Created with ❀️ using Streamlit

", unsafe_allow_html=True)