Professional Documents
Culture Documents
Submitted by
degree of
BACHELOR OF ENGINEERING
in
BIOMEDICAL ENGINEERING
BONAFIDE CERTIFICATE
Certified that this project report “IMAGE EROSION AND DILATION USING
PYTHON” is the bonafide work of ASLAM PACKIR K who carried out the
project work under my supervision.
1
TABLE OF CONTENTS
CHAPTER TITLE PAGE NO
NO
1 Introduction 5
1.1 Image processing 5
1.2 Python 5
1.3 Anaconda 7
1.4 Spyder 7
1.5 Morphological operations 8
1.5.1 Dilation 8
1.5.2 Erosion 9
1.5.3 Opening 10
1.5.4 Closing 10
2 Methodologies 11
2.1 Required libraries to perform Preprocessing 11
2.2Installation 11
2.3 Loading the Original Image 12
2.4 Resizing the Original Image 12
2.5 Erosion Function 12
2.6 Dilation Function 12
4 Conclusion 15
5 References 16
6 Appendix 17
2
LIST OF FIGURES
3
LIST OF ABBREVIATIONS
OS Operating System
4
CHAPTER 1
INTRODCUTION
1.1 Image processing
Information of an image can be obtained with the help of the technique known as Image Processing.
It is the core part of computer vision which plays a crucial role in many real-world examples like
robotics, self-driving cars, and object detection. Image processing allows us to transform and
manipulate thousands of images at a time and extract useful insights from them. It has a wide range
of applications in almost every field.
Python is one of the widely used programming languages for this purpose. Its amazing libraries and
tools help in achieving the task of image processing very efficiently. Image processing means
processing the image and this may include many different techniques until we reach our goal. The
final output can be either in the form of an image or a corresponding feature of that image. This can
be used for further analysis and decision making.
An image can be represented as a 2D function F(x,y) where x and y are spatial coordinates. The
amplitude of F at a particular value of x,y is known as the intensity of an image at that point. If x,y,
and the amplitude value is finite then we call it a digital image. It is an array of pixels arranged in
columns and rows. Pixels are the elements of an image that contain information about intensity and
colour. An image can also be represented in 3D where x,y, and z become spatial coordinates. Pixels
are arranged in the form of a matrix. This is known as an RGB image.
RGB image: It contains three layers of 2D image, these layers are Red, Green, and Blue channels.
Grayscale image: These images contain shades of black and white and contain only a single channel.
1.2 Python
5
available under the GNU General Public License (GPL). Python becomes an apt choice for such
Image processing tasks. This is due to its growing popularity as a scientific programming language
and the free availability of many State of Art Image Processing tools in its ecosystem.
OpenCV − Image processing library mainly focused on real-time computer vision with
application in wide-range of areas like 2D and 3D feature toolkits, facial & gesture
recognition, Human-computer interaction, Mobile robotics, Object identification and others.
Numpy and Scipy libraries − For image manipulation and processing.
Python Imaging Library (PIL) − To perform basic operations on images like create
thumbnails, resize, rotation, convert between different file formats etc.
Skimage - Provides lots of algorithms for image processing which includes algorithms
for segmentation, geometric transformations, colour space manipulation, analysis, filtering,
morphology, feature detection, and more. It is designed to interoperate with the Python
numerical and scientific libraries NumPy and SciPy.
Matplotlib -Matplotlib is an amazing visualization library in Python for 2D plots of arrays.
Matplotlib is a multi-platform data visualization library built on NumPy arrays and
designed to work with the broader SciPy stack. It was introduced by John Hunter in the year
2002.One of the greatest benefits of visualization is that it allows us visual access to huge
amounts of data in easily digestible visuals. Matplotlib consists of several plots like line,
bar, scatter, histogram etc.
6
1.3 Anaconda
The world’s most popular open-source Python distribution platform that can be used for projects
in any field, from data visualization to robotics.One can easily search and install packages and
create, load, and switch between environments.
The packages are securely hosted and artifacts are methodically tested and regularly updated. Its
repository features over 8,000 open-source data science and machine learning packages,
Anaconda-built and compiled for all major operating systems and architectures. Conda is an
open-source package and environment management system that runs on Windows, macOS, and
Linux.
Conda quickly installs, runs, and updates packages and their dependencies. It also easily creates,
saves, loads, and switches between environments on your local computer. It was created for
Python programs, but it can package and distribute software for any language. Anaconda
Navigator
let the user to easily manage integrated applications, packages, and environments without using
the command line. Anaconda Nucleus securely stores the user’s local environments in the cloud.
Anaconda Distribution equips individuals to easily search and install thousands of Python/R
packages and access a vast library of community content and support.
1.4 Spyder
Spyder is an open-source cross-platform IDE. The Python Spyder IDE is written completely in
Python. It is designed by scientists and is exclusively for scientists, data analysts, and engineers. It
is also known as the Scientific Python Development IDE and has a huge set of remarkable
features.
7
Availability of breakpoints (debugging and conditional breakpoints)
Interactive execution which allows you to run line, file, cell, etc.
Navigation through cells, functions, blocks, etc can be achieved through the Outline Explorer
It provides real-time code introspection (The ability to examine what functions, keywords,
and classes are, what they are doing and what information they contain)
Also provides features such as help, file explorer, find files, etc
Morphology is a broad set of image processing operations that process images based on shapes.
Morphological operations apply a structuring element to an input image, creating an output
image of the same size. In a morphological operation, the value of each pixel in the output image
is based on a comparison of the corresponding pixel in the input image with its neighbours.
1.5.1 DILATION
Morphological dilation makes objects more visible and fills in small holes in objects. Lines
appear thicker, and filled shapes appear larger.
8
Fig 1.5.1.1 dilated image
In figure 1.5.1.1 the value of the output pixel is the maximum value of all pixels in the
neighbourhood. In a binary image, a pixel is set to 1 if any of the neighbouring pixels have the
value 1.
1.5.2 EROSION
Morphological erosion removes floating pixels and thin lines so that only substantive objects
remain. Remaining lines appear thinner and shapes appear smaller.
In figure 1.5.1.2 the value of the output pixel is the minimum value of all pixels in the
neighbourhood. a pixel is set to 0 if any of the neighbouring pixels have the value 0.
9
1.5.3 OPENING
Opening is a process in which first erosion operation is performed and then dilation operation
is performed. It eliminates the thin protrusions of the obtained image. Opening is used for
removing internal noise of the obtained image
In figure 1.5.3.1 f is the input image, B is the structuring element, f⊖B is the eroded image f∘B
is the opened image where dilation is done to The eroded image.
1.5.4 CLOSING
Closing is a process in which first dilation operation is performed and then erosion operation is
performed. It eliminates the small holes from the obtained image. Closing is used for
smoothening of contour and fusing of narrow breaks.
Closing is represented by:-
A •B=(A⊕B) ⊖B
10
CHAPTER-2
METHODOLOGIES
2.1Required Libraries to Perform Preprocessing
Opencv
Numpy
2.2 Installation
The figure 2.2.1 shows the message from anaconda terminal that it is already existed.
The figure 2.2.2 confirms that cv2 library is successfully installed and its version is displayed in
the console.
The figure 2.2.3 shows that NumPy package was successfully installed and also its version is
displayed in the console.
11
2.3 Loading the original image
The figure 2.4 shows the code snippet to load an RGB and Grayscale images through Opencv
library.
2.4 Resizing the original image
The figure 2.4.1 shows the code snippet to resize the original image to 400*400 pixel image
The Fig 2.5 shows the code to apply erosion function to the image. The parameters inside the
erosion function are image which we given as input and kernel is structuring element .
The figure 2.6.1 shows the dilation function that is applied to that image.
CHAPTER-3
12
RESULTS AND DISCUSSION
3.1 ORIGINAL IMAGE
13
3.3 DILATED IMAGE
14
CHAPTER 4
CONCLUSION
15
CHAPTER - 5
REFERENCES
1. https://www.mathworks.com/help/images/morphological-dilation-and-erosion.html
2. https://www.geeksforgeeks.org/difference-between-opening-and-closing-in-digital-
image-processing/
3. https://towardsdatascience.com/image-processing-part-3-dbf103622909
4. mailto:1. https://medium.com/@ami25480/morphological-image-processing-
operations-dilation-erosion-opening-and-closing-with-and-without-c95475468fca
16
CHAPTER – 6
APPENDIX
17