Ram
Ram
Faculty of Science
Project Report
IMAGE PROCESSING USING PYTHON TO IDENTIFY OBJECTS IN IMAGES
( IMAGE MODIFICATION DETECTION AND IMAGE SIMILARITY)
Supervisor
DR. MAGDALIENE NYAMSI
May 2023
DECLARATION
This report has been written by me and has not received any previous academic credit at
this or any other institution.
i
CERTIFICATION
This is to certify that this report entitled “IMAGE PROCESSING USING PYTHON TO
IDENTIFY OBJECTS IN IMAGES ( IMAGE MODIFICATION AND IMAGE
SIMILARITY DETECTION )” is the original work of RAMSEY IBE BENDE NDIVE
with Registration Number SC20C121, student at the Department of Computer Science at
the University of Buea. All borrowed ideas and materials have been duly acknowledged by
means of references and citations. The report was supervised in accordance with the
procedures laid down by the University of Buea. It has been read and approved by:
(supervisor)
ii
ACKNOWLEDGEMENT
I would like to thank my supervisor, DR. MAGDALIENE NYAMSI for her patience,
discipline, and guidance through this project. Without her help, this project would not have
been possible.
iii
Abstract
The increasing prevalence of image manipulation techniques and the ease of modifying
digital images has led to a rise in the production of fake or modified images. This is an
important issue in various applications, including forensics analysis, image based
attendance systems, where the authenticity and accuracy of images are critical. Detecting
image modification then solves this problem.
This project will develop a system for image modification and image similarity
detection. The system will use a combination of image processing techniques and machine
learning algorithms. This system will be able to detect modified images and images that
are similar to a given image.
The system will be developed using the Python programming language and the
OpenCV library. The system will be tested on a variety of image datasets. The system will
be evaluated based on its ability to detect modified images and similar images.
The results of this project will be a system that can be used to detect modified images and
similar images. The system will be useful for a variety of applications, such as image
forensics analysis, image based attendance.
iv
Table of Contents
DECLARATION.................................................................................................................. i
CERTIFICATION ............................................................................................................... ii
ACKNOWLEDGEMENT ................................................................................................. iii
Abstract .............................................................................................................................. iv
CHAPTER ONE ................................................................................................................. 1
INTRODUCTION .............................................................................................................. 1
PROJECT BACKGROUND .......................................................................................... 1
Why I Thought the Project Was Needed ..................................................................... 1
My Interest in the Project ............................................................................................ 2
Technical or Social Background of the Project ........................................................... 2
PROJECT AIM ............................................................................................................... 2
PROJECT BOUNDARIES ............................................................................................. 2
CHAPTER TWO ................................................................................................................ 4
ANALYSIS AND DESIGN ................................................................................................ 4
PROBLEM STATEMENT.............................................................................................. 4
RESEARCH QUESTIONS ............................................................................................ 4
RESEARCH METHOD.................................................................................................. 5
FUNCTIONAL AND NON - FUNCTIONAL REQUIREMENTS ............................... 5
Functional Requirements ............................................................................................ 5
Non - Functional Requirements .................................................................................. 7
DESIGN OF THE IMAGE MODIFICATION AND IMAGE SIMILARITY
DETECTION APPLICATION........................................................................................ 7
CHAPTER THREE .......................................................................................................... 16
RESULTS AND DISCUSSION........................................................................................ 16
IMPLEMENTATION.................................................................................................... 16
CHAPTER FOUR ............................................................................................................. 20
CONCLUSION ................................................................................................................. 20
FUTURE RESEARCH ................................................................................................. 20
References ......................................................................................................................... 21
APPENDICES .................................................................................................................. 22
v
vi
CHAPTER ONE
INTRODUCTION
The purpose of this image modification and similarity detection application is to detect changes
made to an image. This can be useful in a variety of contexts, ranging from image based attendance
systems, image similarity. The application compares multiple versions of an image to identify any
differences or modifications made to the image. These modifications can include editing or any
other changes made to the image. The detection of these modifications can help to identify
potential fraud or manipulation of the images, or for comparison between images.
PROJECT BACKGROUND
Image modification and image similarity detection are two important tasks in computer vision.
Image modification detection is the task of detecting images or image parts that have been
tampered or manipulated (sometimes also referred to as doctored). This typically encompasses
image splicing, copy-move, or image inpainting.
Image similarity detection A fundamental computer vision task to determine whether a part of an
image has been copied from another image.
These tasks are used in a variety of applications, such as image editing, image search, and image
forensics. Image similarity detection can be used to find similar images, to find duplicate images,
or to identify images that have been tampered with.
I thought this project was needed because there is a growing demand for systems that can detect
modified and similar images. The ability to detect modified images is useful for a variety of
applications, such as image forensics analysis. The ability to detect similar images is useful for a
variety of applications, such as finding similar images, finding duplicate images, and identifying
images that have been tampered with.
1
My Interest in the Project
I am interested in this project because I am passionate about computer vision. I believe that image
modification and image similarity detection are two important tasks in computer vision, and i am
excited to develop a system that can perform these tasks.
The technical background of the project is in image processing and machine learning. Image
processing is the process of extracting information from images, and machine learning is the
process of learning from data. The system will use a combination of image processing techniques
and machine learning algorithms to detect modified images and similar images.
The social background of the project is in the field of computer vision. Computer vision is the field
of computer science that deals with the extraction of information from images and videos.
Computer vision is used in a variety of applications, such as image search, image forensics, and
image editing.
PROJECT AIM
The aim of this project is to develop a system that can detect images that have been modified and
images that are similar. The system will use a combination of image processing techniques and
machine learning algorithms. The system will be able to detect images that have been modified in
different ways such as by adjusting the brightness and contrast and applying filters. The system
will also be able to detect images that are similar to a given image.
PROJECT BOUNDARIES
I was not able to develop a system that was as easy to use as I would have liked. The system was
easy to use for someone who is familiar with programming, but it would be more user-friendly if
it had a graphical user interface. I was also not able to develop a system that was able to detect
modified and similar images in a reasonable amount of time on computers with low processing
power.
2
REPORT STRUCTURE
The rest of the report is given as follows. Chapter 1 talks about the Analysis and Design stage of
the research, how it was carried out, its functional and non-functional dependencies. Chapter 2
Shows code fragments on how key features were implemented and also shows the results obtained
from the implementation. It also talks about what happened and why it happened, possible sources
of errors with the application. Chapter 3 sums up the project and its implications and suggestions
for future research. Chapter 4 includes all the evidence that was cited in the main body of the report
using the citation and referencing style. Chapter 7 shows details for setting up the application.
3
CHAPTER TWO
PROBLEM STATEMENT
The widespread availability of digital image editing tools has made it easy to modify images in a
variety of ways, including adding or removing objects. This has led to an increase in the number
of images that have been manipulated, either intentionally or unintentionally. Image modification
can have negative consequences including:
Manipulated images can be used to spread misinformation, such as creating fake news articles.
Modified images can be used to infringe on copyrights, such as by creating unauthorized copies
of copyrighted works.
Image similarity detection is the task of finding images that are similar to a given image. This can
be useful for a variety of applications such as to find duplicate images and similar images.
RESEARCH QUESTIONS
Before and while carrying out this research, certain questions were raised such as;
1. What are the different types of image modifications that can be detected?
2. What are the different methods that can be used to detect image modifications?
3. What are the factors that affect the accuracy of image modification detection methods?
4. How can image modification detection methods be improved?
5. What are the advantages and disadvantages of the different methods for detecting image
modifications?
6. What are the different metrics that can be used to measure the similarity between images?
7. What are the different methods that can be used to find similar images?
8. What are the advantages and disadvantages of the different methods for finding similar
images?
9. How can image similarity detection be used to find duplicate images?
10. How can image similarity be used to find similar images?
11. How can image modification detection be used to ensure the integrity of evidence?
4
12. How can image modification detection be used to detect fake news and
misinformation?
The paper tries to answer the questions and shed more light on areas for further work and
exploration.
RESEARCH METHOD
A literature review of previous research development in this topic area was conducted.
Image modification detection is the task of detecting images or image parts that have been
tampered or manipulated . There are a number of different methods that can be used to detect
modification. Some of the most common methods include.
Statistical methods: Statistical methods use statistical properties of images to detect changes. For
example, statistical methods can be used to detect changes in the brightness, contrast, or color of
an image.
Feature-based methods: Feature-based methods identify features that are unique to an image and
then compare those features to features of other images. If the features of an image are significantly
different from the features of other images, then the image is likely to have been modified.
Deep learning methods: Deep learning methods use artificial neural networks to detect image
similarity. Deep learning methods can learn to identify patterns in images that are indicative of
similarity.
Image modification detection and image similarity detection are important tools that can be used
for a variety of purposes. The research on these topics is constantly evolving, and new methods
are being developed all the time. As these methods become more accurate and reliable, they will
become increasingly important for a variety of applications.
Functional Requirements
1. The application should be able to detect whether an image has been modified.
5
1. The application can detect whether an image has been modified by comparing the
image to another unmodified image. If the image is different from the unmodified
image, then it has been modified.
2. The application can also detect whether an image has been modified by using a
variety of image processing techniques, such as:
1. Image differencing: This technique compares the pixel values of two
images to identify differences.
2. Feature extraction: This technique extracts features from an image, such
as edges, shapes, and colors. The features can then be used to identify the
image or to compare to another image.
3. Machine learning: This technique can be used to train a model to identify
images that have been modified.
2. The application should be able to identify where the modifications have been made on the
image.
1. The application can identify the specific part of the image where the modifications
have been done by adding the bounding box around the area.
3. The application should be able to calculate the similarity between two images
1. The project can calculate the similarity between two images by comparing the pixel
values of the images. The similarity between two images is a measure of how
similar the images are.
2. The project can also calculate the similarity between two images by using a variety
of image processing techniques, such as:
1. Image differencing: This technique compares the pixel values of two
images to identify differences.
2. Feature extraction: This technique extracts features from an image, such
as edges, shapes, and colors. The features can then be used to identify the
image or to compare it to other images.
3. Machine learning: This technique can be used to train a model to identify
images to identify images that are similar.
6
Non - Functional Requirements
These requirements are seen as attributes to the functional requirements. Functional requirements
are implemented with them in mind and someplace more emphasis on one or more of them than
others.
1. The application should be efficient and should not take too long to detect or calculate image
similarity. This is important because the user should not have to wait a long time for the
application to finish detecting or calculate image similarity.
2. The application should be robust and should be able to handle images of different sizes and
formats. This is important because the user should be able to use the application to detect
or calculate similarity for any image, regardless of its size or format.
3. The application should be accurate and should be able to correctly detect and identify
images that have been modified. This is important because the application will be used to
make important decisions, such as whether to accept an image as evidence or not.
7
be able to compare them. The .shape property returns a tuple of three numbers, representing
the width, height, and number of channels of the image.
4. Printing the shapes of the images: If the images have the same shape, the function prints
the shapes of the images. The shapes are printed as a tuple, with each number separated by
a comma.
5. Printing an error message: If the images do not have the same shape, the function prints
an error message. The error message includes the names of the two images.
8
3. Computing the SSIM: The function uses the stuctural_similarity() function to compute
the SSIM between the two images. The function returns a value between 0 to 100, where
100 indicates that the images are identical.
4. Thresholding and identifying the differences: The function first threshold the difference
image. This converts the image to a binary image where pixels with a value greater than a
certain threshold are white and all other pixels are black. The function then finds the
contours of the white regions in the thresholded image.
5. Drawing rectangle around the differences: The function iterates through the contours
and draws a rectangle around each one. It also writes the number of the different regions to
the image.
6. Saving the images: The function saves the images to disk.
7. Returning the results: The function returns the number of difference regions found, the
image similarity and image difference as percentages, and the images.
9
txt _color tuple The RGB value for the text color.
contour_color1 tuple The RGB value for the first contour color.
contour_color2 tuple The RGB value for the second contour color.
offset int The offset between the text and the rectangle.
score float The structural similarity index between the two images.
10
maskimage str The path to the saved mask image.
Module Description
os.path.split('.') Used to Split the path name into a pair head and tail.
11
2. Creating the figure: The function uses the subplots() function from the matplotlib.pyplot
module to create a figure with two subplots. The subplots() function returns a tuple of two
axes objects, one for each subplot.
3. Displaying the images: The function uses the imshow() function from the
matplotlib.pyplot module to display the images in the subplots. The imshow() function
takes an image array as input and displays it in the specified subplot.
4. Setting the titles: The function uses the set_title() function from the matplotlib.pyplot
module to set the titles of the subplots. The set_title() function takes a string as input and
sets it as the title of the specified subplot.
5. Adding a title to the figure: The function uses the suptitle() function from the
matplotlib.pyplot module to add a title to the figure. The suptitle() function takes a string
as input and sets it as the title of the figure.
6. Tightening the layout of the figure: The function uses the tight_layout() function from
the matplotlib.pyplot module to tighten the layout of the figure. This ensures that all of the
elements of the figure are displayed neatly.
7. Saving the figure to disk: The function uses the savefig() function from the
matplotlib.pyplot module to save the figure to disk. The savefig() function takes a filename
as input and saves the figure to the specified file.
8. Displaying the figure: The function uses the show() function from the matplotlib.pyplot
module to display the figure.
12
f Figure The figure object
Module Description
13
4. Creating the figure: The function uses the figure() function from the matplotlib.pyplot
module to create a figure with four subplots. The figure() function takes a width and height
as input and creates a figure with the specified dimensions.
5. Displaying the images: The function uses the imshow() function from the
matplotlib.pyplot module to display the images in the subplots. The imshow() function
takes an image array as input and displays it in the specified subplot.
6. Setting the titles: The function uses the set_title() function from the matplotlib.pyplot
module to set the titles of the subplots. The set_title() function takes a string as input and
sets it as the title of the specified subplot.
7. Saving the figure to disk: The function uses the savefig() function from the
matplotlib.pyplot module to save the figure to disk. The savefig() function takes a filename
as input and saves the figure to the specified file.
8. Displaying the figure: The function uses the show() function from the matplotlib.pyplot
module to display the figure.
score float The structural similarity index between the two images.
14
columns int The number of columns in the figure.
15
CHAPTER THREE
IMPLEMENTATION
1. check_image function implementation
The function checks if the two image files exist and if they have the same shape
16
Figure 2.2: Implementing side_by_side function
3. Viewing_images function implementation
The function displays the result of the comparison, mask and grayscale of the images on
a screen.
17
18
19
CHAPTER FOUR
CONCLUSION
Image modification detection and image similarity detection are two important tasks in computer
vision. Image modification detection is the task of identifying whether an image has been
modified, while image similarity detection is the task of identifying whether two images are
similar. This report can be used to implement a more efficient process for detection of modified
and similar images.
FUTURE RESEARCH
1. The image modification detection and image similarity detection systems are still under
development, and there is room for improvement. For example, the systems can be made
more accurate and efficient.
2. The systems can be used in a variety of different applications, and there is potential for new
applications to be developed.
3. Future research could focus on improving the accuracy and efficiency of the systems, and
on developing new applications for the systems.
20
References
21
[1]
APPENDICES
PROGRAM SET-UP GUIDE
Prerequisites
If you do not have python installed on your computer, download it here [3],
If you do not have python virtual environment install on you computer, you can use the installation
guide found here [5] , to download
If you do not have pip install on your computer, download it here [3],
Creating a python virtual environment
In your terminal, navigate to the folder on your local storage where you want the project to be
created and run the command “ python3 -m venv ‘virtual environment name’ ”; This command
creates the Python virtual environment.
Activating the virtual environment
In your terminal navigate to the same folder in your local storage where you created the virtual
environment run the command “ source ‘virtual environment name’/bin/activate ”
Downloading Source files
In your terminal navigate to the same folder on your local storage where you created and activated
the virtual environment in your local storage and clone the repository on Github [6] and download
it to your local machine, the link to the repository is found here [6]
Installing dependencies
In your terminal navigate to the location of the project repository in your local
storage and run the command “ pip install -r requirements.txt ”; This command installs all the
projects dependencies.
Running the application
In your terminal navigate to the location of the project repository in your local
storage and run the command “ jupyter notebook ”; This would initialize the jupyter notebook
server on your localhost running on port 8888 or in your browse enter the following URL,
“ HTTP://localhost:8888/notebooks/spot_the_difference.ipynb”
22