0% found this document useful (0 votes)
33 views29 pages

Ram

Uploaded by

joycemegvie
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views29 pages

Ram

Uploaded by

joycemegvie
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

UNIVERSITY OF BUEA

Faculty of Science

Department of Computer Science

BACHELOR OF SCIENCE IN COMPUTER SCIENCE

Project Report
IMAGE PROCESSING USING PYTHON TO IDENTIFY OBJECTS IN IMAGES
( IMAGE MODIFICATION DETECTION AND IMAGE SIMILARITY)

RAMSEY IBE BENDE NDIVE


SC20C121

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.

RAMSEY IBE BENDE NDIVE


SC20C121
Department Of Computer Science
Faculty Of Science, University Of Buea

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:

DR. MAGDALIENE NYAMSI May 2023

(supervisor)

Dr. Denis L. Nkweteyim May 2023


Head of Department of Computer Science

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.

Why I Thought the Project Was Needed

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.

Technical or Social Background of the Project

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

ANALYSIS AND DESIGN

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 AND NON - FUNCTIONAL REQUIREMENTS

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.

DESIGN OF THE IMAGE MODIFICATION AND IMAGE SIMILARITY


DETECTION APPLICATION
The design is structured into the design of the python functions used in the application.
check_image function Design:
This function was designed as follows
The function check_image() takes two arguments: image1 and image2. image1 and image2 are the
paths to the two images to be checked. The function has the following operations:
1. Checking if the images exist: The function uses the exists() function from the os.path
module to check if the two images exist. This function returns True if the file exists and
False if it does not.
2. Loading the images: The function uses the cv2.imread() function to load the images into
memory. This function returns an array of pixels representing the image.
3. Checking if the images have the same shape: The function uses the .shape property of
the image arrays to check if they have the same shape. If the images have different
dimensions, then the pixels in each image will not be in the same position, and we will 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.

check_image function schema:

Field Data type Description

image1 str The path to the first image file.

image2 str The path to the second image file.

exists function The exists() function from the os.path module.

img1 ndarray The NumPy array containing the first image.

img2 ndarray The NumPy array containing the second image.

shape tuple The shape of the image.

detect_difference function Design:


This function was designed as follows
The function detect_difference() takes three arguments: image1, image2, and minvalue. image1
and image2 are the two images to be compared, and minvalue is the minimum area of a difference
region to be considered significant. The function has the following operations:
1. Loading the images: The function uses the cv2.imread() function to load the images. The
function returns an array of pixels representing the image.
2. Converting the images to grayscale: The function uses the cv2.cvtColor() function to
convert the images to grayscale. The function returns a new image array with the same
dimensions as the original image, but with only one channel (grayscale).

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.

detect_difference function schema:

Field Data type Description

image1 str The path to the first image.

image2 str The path to the second image file.

The minimum area of a difference to be considered


minvalue int
significant.

green_color tuple The RGB value for the green color.

red_color tuple The RGB value for the red color.

cyan_color tuple The RGB value for the cyan color.

rect_color tuple The RGB value for the rectangle color.

rect_size int The size of the rectangle

9
txt _color tuple The RGB value for the text color.

txt _size int The size of the text.

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.

img1 ndarray The NumPy array containing the first image.

img2 ndarray The NumPy array containing the second image.

img1_gray ndarray The grayscale version of the first image.

img2_gray ndarray The grayscale version of the second image.

score float The structural similarity index between the two images.

diff ndarray The difference between the two images.

diff_boxes ndarray The thresholded difference image.

thresh ndarray The binary image of the thresholded difference image.

contours list The list of contours in the binary image.

nb_differences int The number of differences between the two images

mask ndarray The mask image.

filled_img ndarray The filled image.

basename str The base name of the image file.

image1 str The path to the saved image 1.

image2 str The path to the saved image 2.

10
maskimage str The path to the saved mask image.

filled_image str The path to the saved filled image.

Python modules used in Detect Difference function:

Module Description

cv2.cvtColor Used to convert an image from one color space to another

cv2.threshold() Used to apply the thresholding.

cv2.findContours() Used to extract contours from the image.

cv2.rectangle() Used to draw a rectangle on the images.

cv2.putText() Used to draw a text string on the images.

cv2.drawContours() Used to draw the contours on the images.

cv2.imwrite() Used to save the images.

os.path.basename() used to get the base name in specified path

os.path.split('.') Used to Split the path name into a pair head and tail.

Side_by_side_images function Design:


This function was designed as follows
The function side_by_side_images() takes three arguments: image1, image2, and w and h. image1
and image2 are the paths to the two images to be displayed, and w and h are the width and height
of the figure. The function has the following operations:
1. Loading the images: The function uses the imread() function from the matplotlib.pyplot
module to load the images into memory. This function returns an array of pixels
representing the image.

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.

Side_by_side_images function schema:

Field Data types Description

image1 str The path to the first image file.

image2 str The path to the second image file.

w int The width of the figure.

h int The height of the figure.

12
f Figure The figure object

ax Axes The axes object

title str The title of the figure.

fontsize int The font size of the title.

Python modules used in Side_by_side_images function:

Module Description

plt.imshow() Used to display data as an image

plt.subplots() Used to Create a figure and a set of subplots

plt.tight_layout() Used to adjust the padding between and around subplots.

plt.savefig() Used to save the figure created after plotting data.

plt.show() provides a unified interface for creating different types of plots.

Viewing_images function Design:


This function was designed as follows
The function viewing_images() takes two arguments: w and h. w and h are the width and height
of the figure. The function has the following operations:
1. Printing the names of the two images: The function prints the names of the two images
that were compared to the console.
2. Printing the current date and time: The function uses the datetime.now() function to get
the current date and time. It then prints the date and time to the console.
3. Printing the number of differences found and the similarity index: The function prints
the number of differences found and the similarity index to the console.

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.

Viewing_images function schema:

Field Data type Description

w int The width of the figure.

h int The height of the figure.

image1 str The path to the first image file.

image2 str The path to the second image file.

nb_differences int The number of differences between the two images.

score float The structural similarity index between the two images.

fig Figure The figure object.

rows int The number of rows in the figure.

14
columns int The number of columns in the figure.

15
CHAPTER THREE

RESULTS AND DISCUSSION


This section contains code fragments containing key logic on how the project was implemented
and the results from implementing the application. Results would be shown in the form of
screenshots followed by brief descriptions, see the appendix section below on how to run the
application.

IMPLEMENTATION
1. check_image function implementation
The function checks if the two image files exist and if they have the same shape

Figure 2.1: Implementing check_image function


2. Side_by_side_images function implementation
The function displays the two images that are being compared side by side.

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.

Figure 2.3: Implementing viewing_images function


4. detect_difference function implementation

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

[1] "image-similarity-detection," [Online]. Available: https://paperswithcode.com/task/image-


manipulation-detection.
[2] "Image-manippulation-detection," [Online]. Available:
https://paperswithcode.com/task/image-manipulation-detection.
[3] "BeginnersGuide," [Online]. Available: wiki.python.org/moin/BeginnersGuide/Download.
[4] "Installation - pip documentation," [Online]. Available: pip.pypa.io/en/stable/installation/.
[5] "installing using pip and virtual environments," [Online]. Available:
packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments.
[6] "image modification and modification similarity detection with python," [Online]. Available:
github.com/ramseyibe/image-modification-and-modification-similarity-detection-with-
python.
[7] Y. J. Liu Z, "Deep learnig for image forensics: A survey," vol. 34, no.
10.1109/MSP.2017.2675733, March 2017.
[8] H. Farid, "Image Forgery Detection," vol. 26, no. ma, pp. 97-109, March 2009.
[9] Z. Y. Xin ji, "STATISTICAL MEHTODS FOR IMAGE CHANGE DETECTION WITH
UNCERTAINTY".

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

You might also like