import streamlit as st import pandas as pd import numpy as np # Custom CSS for styling custom_css = """ """ # Inject the CSS into the app st.markdown("
Introduction to Image Data 📊
", unsafe_allow_html=True) st.markdown( """
What is an Image?
An image is a visual representation of something, such as a person, object, scene, or concept. It can be created using various means and exists in different forms.
The image is a 2D grid like structure where every grid represents a pixel and each pixel has its own features.
The features in a pixel include theinformation like shape, color, pattern etc.
The clarity of an image directly depends on the number of pixels it has.
Every array cannot be an image. An array can be an image only when:
1) It should be in 2D or 3D representation.
2) The datatype should only be an integer.
What are Color Spaces?
Color Space is a technique by which we can represent the colors of an image.
There are 3 types of color spaces namely:
1) Black & White Color Space 2) Grayscale Color Space 3) RGB Color Space
Black & White Color Space
In this Color Space, there are only 2 colors to represent the image which are black & white.
Here, 0 represents black and 1 represents white.
Grayscale Color Space
In this Color Space, we have black, white and multiple shades of gray to represent the image.
Here, 0 represents black, 255 represents white, and 1 to 254 represent various shades of gray.
RGB Color Space
In this Color Space, we create a 3D structure with three 2D channels namely blue, green and red channels where 0 represents absense of color and 255 represents presense of color.
These 3 channels are stacked one after the another like a layered structure.
The blue channel has 0 which represents black, 255 which represents blue and 1 to 254 represent multiple shades of blue.
The green channel has 0 which represents black, 255 which represents green and 1 to 254 represent multiple shades of green.
The red channel has 0 which represents black, 255 which represents red and 1 to 254 represent multiple shades of red.


""", unsafe_allow_html=True, ) if st.button("Next Page: Basic operations on an Image"): st.session_state['page'] = 'image_operations' if page == 'image_operations': st.markdown("
Basic Operations on an Image
", unsafe_allow_html=True) st.markdown( """
Operations on image data
There are 3 major operations which can be performed on an image namely:
1) Reading an image
2) Writing an image
3) Showing an image
Reading an image
For this operation, we have to import cv2 module and use the method imread(). The method imread() is used to convert an image file into a numpy array.
Writing an image
For this operation, we have to import cv2 module and use the method imwrite(). The method imwrite() is used to convert a numpy array back into an image file.
Showing an image
For this operation, we have to import cv2 module and use the method imshow(). The method imshow() is used to display an array in the form of an image by creating a popup window.


""", unsafe_allow_html=True, ) col1, col2 = st.columns(2) with col1: if st.button("Open Jupyter Notebook"): st.session_state['jupyter_clicked'] = True st.session_state['pdf_clicked'] = False with col2: if st.button("Open PDF"): st.session_state['pdf_clicked'] = True st.session_state['jupyter_clicked'] = False if st.session_state['jupyter_clicked']: st.markdown( """
Jupyter Notebook for Basic Operations on an Image
This Jupyter notebook explains the basic operations that can be performed on an image.
""", unsafe_allow_html=True, ) # Embed the converted HTML file for the notebook notebook_html_path = "pages/basic_img_ops.html" with open(notebook_html_path, "r") as f: notebook_html = f.read() st.components.v1.html(notebook_html, height=500, scrolling=True) elif st.session_state['pdf_clicked']: st.markdown( """
PDF file for Basic Operations on an Image
This PDFfile explains the basic operations that can be performed on an image.
""", unsafe_allow_html=True, ) pdf_path = "pages/basic_img_ops.pdf" # Read the PDF file content (binary data) with open(pdf_path, "rb") as file: pdf_data = file.read() # This is the binary data of the PDF file # Display the PDF in an iframe st.markdown( f'', unsafe_allow_html=True, ) # Provide download option for the PDF file st.download_button( label="Download PDF", data=pdf_data, # Provide the binary file data here file_name="basic_img_ops.pdf", # This is the name that will appear when the user downloads the file mime="application/pdf" ) if st.button("Next Page: Working on the Image"): st.session_state['page'] = 'image_working' elif page == 'image_working': st.markdown("
Working on the Image
", unsafe_allow_html=True) st.markdown( """
Understanding split() method
For this operation, we have to import cv2 module and use the method split().

The split() method is used to separate a multi-channel image into its individual single-channel components.
Understanding merge() method
For this operation, we have to import cv2 module and use the method merge().

The merge() method is used to combine multiple single-channel images into a single multi-channel image.



""", unsafe_allow_html=True, ) col1, col2 = st.columns(2) with col1: if st.button("Open Jupyter Notebook"): st.session_state['jupyter_clicked'] = True st.session_state['pdf_clicked'] = False with col2: if st.button("Open PDF"): st.session_state['pdf_clicked'] = True st.session_state['jupyter_clicked'] = False if st.session_state['jupyter_clicked']: st.markdown( """
Jupyter Notebook for Basic Operations on an Image
This Jupyter notebook explains the split and merge methods that can be performed on an image.
""", unsafe_allow_html=True, ) # Embed the converted HTML file for the notebook notebook_html_path = "pages/working_on_img.html" with open(notebook_html_path, "r") as f: notebook_html = f.read() st.components.v1.html(notebook_html, height=500, scrolling=True) elif st.session_state['pdf_clicked']: st.markdown( """
PDF file for Basic Operations on an Image
This PDF file explains the split and merge methods that can be performed on an image.
""", unsafe_allow_html=True, ) pdf_path = "pages/working_on_img.pdf" # Read the PDF file content (binary data) with open(pdf_path, "rb") as file: pdf_data = file.read() # This is the binary data of the PDF file # Display the PDF in an iframe st.markdown( f'', unsafe_allow_html=True, ) # Provide download option for the PDF file st.download_button( label="Download PDF", data=pdf_data, # Provide the binary file data here file_name="working_on_img.pdf", # This is the name that will appear when the user downloads the file mime="application/pdf" ) if st.button("Next Page: Conversion between Color Spaces"): st.session_state['page'] = 'color_space_conversion_on_img' elif page == 'color_space_conversion_on_img': st.markdown("
Conversion between Color Spaces
", unsafe_allow_html=True) st.markdown( """
How to convert one color space to another?
In the cv2 module, we have an in-built method called cvtColor() along with in-built parameters for each conversion.

1) For converting BGR to Grayscale, We use the parameter COLOR_BGR2GRAY inside the cvtColor() method.

2) For converting Grayscale to BGR, We use the parameter COLOR_GRAY2BGR inside the cvtColor() method.

3) For converting BGR to RGB, We use the parameter COLOR_BGR2RGB inside the cvtColor() method.



""", unsafe_allow_html=True, ) col1, col2 = st.columns(2) with col1: if st.button("Open Jupyter Notebook"): st.session_state['jupyter_clicked'] = True st.session_state['pdf_clicked'] = False with col2: if st.button("Open PDF"): st.session_state['pdf_clicked'] = True st.session_state['jupyter_clicked'] = False if st.session_state['jupyter_clicked']: st.markdown( """
Jupyter Notebook for Basic Operations on an Image
This Jupyter notebook explains the split and merge methods that can be performed on an image.
""", unsafe_allow_html=True, ) # Embed the converted HTML file for the notebook notebook_html_path = "pages/converting_color_spaces.html" with open(notebook_html_path, "r") as f: notebook_html = f.read() st.components.v1.html(notebook_html, height=500, scrolling=True) elif st.session_state['pdf_clicked']: st.markdown( """
PDF file for Basic Operations on an Image
This PDF file explains the split and merge methods that can be performed on an image.
""", unsafe_allow_html=True, ) pdf_path = "pages/converting_color_spaces.pdf" # Read the PDF file content (binary data) with open(pdf_path, "rb") as file: pdf_data = file.read() # This is the binary data of the PDF file # Display the PDF in an iframe st.markdown( f'', unsafe_allow_html=True, ) # Provide download option for the PDF file st.download_button( label="Download PDF", data=pdf_data, # Provide the binary file data here file_name="converting_color_spaces.pdf", # This is the name that will appear when the user downloads the file mime="application/pdf" ) if st.button("Next Page: Affine Transformations on an Image"): st.session_state['page'] = 'affine_transformations' elif page == 'affine_transformations': st.markdown("
Affine Transformations on an Image
", unsafe_allow_html=True) st.markdown( """
What are Affine Transformations?
Affine Transformations are a part of Image augmentation.
Image augmentation is a technique of creating new images from the existing images.
This technique is used to create a balance in the dataset.
For a particular label, ff there are less images compared to the other label, we increase the no. of images in that label using Image augmentation.

Advantages of Affine Transformations include:
1) We convert our imbalanced data into balanced data.
2) We get new images from old ones

Types of Affine Transformations?
There are 5 types of Affine Transformations namely:
1) Translation
2) Rotation
3) Scaling
4) Shearing
5) Cropping

Translation
It is a technique of shifting the image by some bits on the X-axis and the Y-axis.
The extra bits created are replaced with black color or duplicate pixels.
We apply a Translation matrix ( Tm ) for this.
Rotation
It is a technique of rotating the image by at an angle from the specified position.
We apply a Rotation matrix ( Rm ) for this.
We can use a combination of Rotation & Translation in the same Rotation matrix ( Rm )
Scaling
It is a technique of increasing or decreasing the size of the image by a particular scale.
We apply a Scaling matrix ( Sm ) for this.
We can use a combination of Scaling & Translation in the same Scaling matrix ( Sm )
Shearing
It is a technique of stretching the image from its edges by a particular value.
We apply a Shearing matrix ( Shm ) for this.
We can use a combination of Shearing, Scaling & Translation in the same Shearing matrix ( Shm )
Cropping
It is a technique of extracting or cutting a part of the image from the original image.
We don't have a cropping matrix for this technique.
Instead, we have to do it manually using slicing operation on the Numpy array.


""", unsafe_allow_html=True, ) col1, col2 = st.columns(2) with col1: if st.button("Open Jupyter Notebook"): st.session_state['jupyter_clicked'] = True st.session_state['pdf_clicked'] = False with col2: if st.button("Open PDF"): st.session_state['pdf_clicked'] = True st.session_state['jupyter_clicked'] = False if st.session_state['jupyter_clicked']: st.markdown( """
Jupyter Notebook for Basic Operations on an Image
This Jupyter notebook explains all the affine transformations that can be performed on an image.
""", unsafe_allow_html=True, ) # Embed the converted HTML file for the notebook notebook_html_path = "pages/affine_transformations.html" with open(notebook_html_path, "r") as f: notebook_html = f.read() st.components.v1.html(notebook_html, height=500, scrolling=True) elif st.session_state['pdf_clicked']: st.markdown( """
PDF file for Basic Operations on an Image
This PDF file explains all the affine transformations that can be performed on an image.
""", unsafe_allow_html=True, ) pdf_path = "pages/affine_transformations.pdf" # Read the PDF file content (binary data) with open(pdf_path, "rb") as file: pdf_data = file.read() # This is the binary data of the PDF file # Display the PDF in an iframe st.markdown( f'', unsafe_allow_html=True, ) # Provide download option for the PDF file st.download_button( label="Download PDF", data=pdf_data, # Provide the binary file data here file_name="affine_transformations.pdf", # This is the name that will appear when the user downloads the file mime="application/pdf" ) if st.button("Next Page: Handling Video Data"): st.session_state['page'] = 'video_data' elif page == 'video_data': st.markdown("
Handling Video Data
", unsafe_allow_html=True) st.markdown( """
What is a Video?
A video is a sequence of images, called frames, displayed rapidly one after another to create the illusion of motion.

To deal with the video data, we import the cv2 module and use the VideoCapture() method.

VideoCapture() method is used to converts a video into list of frames.

Playing the Video
If we specify a path inside VideoCapture() method, it reads the particular video.

Live Video capturing
If we assign 0 inside the VideoCapture() method, it open the Web camera for live video capturing.



""", unsafe_allow_html=True, ) col1, col2 = st.columns(2) with col1: if st.button("Open Jupyter Notebook"): st.session_state['jupyter_clicked'] = True st.session_state['pdf_clicked'] = False with col2: if st.button("Open PDF"): st.session_state['pdf_clicked'] = True st.session_state['jupyter_clicked'] = False if st.session_state['jupyter_clicked']: st.markdown( """
Jupyter Notebook for Basic Operations on an Image
This Jupyter notebook explains how to handle video data.
""", unsafe_allow_html=True, ) # Embed the converted HTML file for the notebook notebook_html_path = "pages/handling_video_data.html" with open(notebook_html_path, "r") as f: notebook_html = f.read() st.components.v1.html(notebook_html, height=500, scrolling=True) elif st.session_state['pdf_clicked']: st.markdown( """
PDF file for Basic Operations on an Image
This PDF file explains how to handle video data.
""", unsafe_allow_html=True, ) pdf_path = "pages/handling_video_data.pdf" # Read the PDF file content (binary data) with open(pdf_path, "rb") as file: pdf_data = file.read() # This is the binary data of the PDF file # Display the PDF in an iframe st.markdown( f'', unsafe_allow_html=True, ) # Provide download option for the PDF file st.download_button( label="Download PDF", data=pdf_data, # Provide the binary file data here file_name="handling_video_data.pdf", # This is the name that will appear when the user downloads the file mime="application/pdf" ) if st.button("Next Page: Interesting projects on Image & Video data"): st.session_state['page'] = 'projects' elif page == 'projects': st.markdown("
🎥✨ Interesting Projects on Image & Video Data 🌟🖼️
", unsafe_allow_html=True) st.markdown( """
Converting an Image into Tabular data
This amazing project explains how we can convert an image into tabular data. Check this out below 👇

""", unsafe_allow_html=True, ) if st.button("Go to Project 1"): js = "window.open('https://github.com/ChaitanyaSubhakar/Handling-Image-and-Video/blob/main/converting_image_into_tabular_data.ipynb')" st.components.v1.html(f"", height=0) st.markdown( """
Converting a Video into Tabular data
This amazing project explains how we can convert a video into tabular data. Check this out below 👇

""", unsafe_allow_html=True, ) if st.button("Go to Project 2"): js = "window.open('https://github.com/ChaitanyaSubhakar/Handling-Image-and-Video/blob/main/converting_videos_into_tabular_data.ipynb')" st.components.v1.html(f"", height=0) st.markdown( """
Animation Project
This amazing project explains how we can create interesting Animation videos using OpenCV package. Check this out below 👇

""", unsafe_allow_html=True, ) if st.button("Go to Project 3"): js = "window.open('https://github.com/ChaitanyaSubhakar/Handling-Image-and-Video/blob/main/animation_project_opencv.ipynb')" st.components.v1.html(f"", height=0) st.markdown( """
GIF Project
This amazing project explains how we can create an interesting GIF using OpenCV package. Check this out below 👇

""", unsafe_allow_html=True, ) if st.button("Go to Project 4"): js = "window.open('https://github.com/ChaitanyaSubhakar/Handling-Image-and-Video/blob/main/GIF_project.ipynb')" st.components.v1.html(f"", height=0) st.markdown( """
Cropping Tool
This amazing project explains how we can create an interesting GIF using OpenCV package. Check this out below 👇

""", unsafe_allow_html=True, ) if st.button("Go to Project 5"): js = "window.open('https://github.com/ChaitanyaSubhakar/Handling-Image-and-Video/blob/main/cropping_tool.ipynb')" st.components.v1.html(f"", height=0) if st.button("Return to main page.."): st.session_state['page'] = 'unstructured_data'