0% found this document useful (0 votes)
17 views

Project Report Format

The document discusses a research project that aims to develop a machine learning based system for eye disease detection. It proposes using various algorithms like MSE, BFSIFT, BFOD and FLANN and evaluates their performance on eye images to detect diseases like cataracts. The system is intended to help enable early detection of eye diseases and improve access to timely diagnosis.

Uploaded by

Arshad
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Project Report Format

The document discusses a research project that aims to develop a machine learning based system for eye disease detection. It proposes using various algorithms like MSE, BFSIFT, BFOD and FLANN and evaluates their performance on eye images to detect diseases like cataracts. The system is intended to help enable early detection of eye diseases and improve access to timely diagnosis.

Uploaded by

Arshad
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 58

“EYE DISEASE DETECTION USING MACHINE LEARNING”

Real Time Research Project(CS456PC)


Submitted
in partial fulfillment of the requirements for the
award of the degree of
Bachelor of Technology
in
Computer Science and Engineering
by
Name of the student
(Roll number)

Under the guidance of


Dr. Meera Alphy
(Assistant Professor)
Ms. K. Shirisha
(Assistant Professor)

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


MAHATMA GANDHI INSTITUTE OF TECHNOLOGY
(Affiliated to Jawaharlal Nehru Technological University Hyderabad)
GANDIPET, HYDERABAD-500075, TELANGANA (INDIA)
2023-2024
MAHATMA GANDHI INSTITUTE OF TECHNOLOGY
(Affiliated to Jawaharlal Nehru Technological University Hyderabad)
Gandipet, Hyderabad-500075, Telangana (India)

CERTIFICATE

This is to certify that the Real Time Research (CS456PC) entitled “EYE DISEASE
DETECTION USING MACHINE LEARNING” is being submitted by MOHD.
MUNEERUDDIN bearing Roll No: 21265A0515 in the partial fulfillment for the
award of Bachelor of Technology in Computer Science and Engineering to
Jawaharlal Nehru Technological University Hyderabad is a record of bonafide
work carried out under the guidance and supervision.The results embodied in this
project have not been submitted to any other University or Institute for the award of
any degree or diploma.

Supervisor Head of the Department


Dr. Meera Alphy Dr. C. R. K. Reddy
Asst. Professor Professor & Head

Ms K Shirisha

Asst.Professor

1
External Examiner

DECLARATION

This is to certify that the work reported in this project titled “EYE DISEASE
DETECTION USING MACHINE LEARNING” is a record of work done by me
in the Department of Computer Science and Engineering, Mahatma Gandhi
Institute and Technology, Hyderabad. No part of the work is copied from
books/journals/internet and wherever the portion is taken, the same has been duly
referred to in the text. The report is based on the work done entirely by me and not
copied from any other source.

MOHD. MUNEERUDDIN

21265A0515

2
ACKNOWLEDGEMENT

The satisfaction that accompanies the successful completion of any task would be
incomplete without the mention of people who made it possible because success is
the abstract of hard work and perseverance, but steadfast of all is encouraging
guidance. So, I acknowledge all those whose guidance and encouragement served
as a beacon light and crowned my efforts with success.

I would like to express my sincere thanks to Prof. G. Chandra Mohan Reddy,


Principal, MGIT, for providing the working facilities in the college.

I wish to express my sincere thanks and gratitude to Dr. C. R. K. Reddy, Professor


and HOD, Department of CSE, MGIT for all the timely support and valuable
suggestions during the period of project.

I am extremely thankful to Dr. Meera Alphy Assistant Professor & Ms K


Shirisha Assistant Professor, Department of CSE, MGIT, Real-Time Research
Project Coordinators for their encouragement and support throughout the project.

Finally, I would also like to thank all the faculty and staff of the CSE Department
who helped us directly or indirectly for completing this project.

MOHD. MUNEERUDDIN
21265A0515

3
TABLE OF CONTENTS
CERTIFICATE i
DECLARATION ii
ACKNOWLEDGEMENT iii
LIST OF FIGURES vi
LIST OF TABLES vii
ABSTRACT viii
1. INTRODUCTION 1
1.1 Problem Statement 1
1.2 Objectives 2
1.3 Existing System and its Disadvantages 2
1.4 Proposed System and its Advantages 3
1.5 System Requirements 4
1.5.1 Software Requirements 4
1.5.2 Hardware Requirements 4
2. LITERATURE SURVEY 5
2.1 Previously implemented Techniques
2.2 Tabular Representation
3. DESIGN AND METHODOLOGY 8
3.1 System Architecture 8
3.2 Algorithms and Metrics 9
3.2.1 Mean Squared Error 9
3.2.2 Brute-force matching with SIFT descriptors and ratio test (BFSIFT) 10
3.2.3 Brute- Force Matching with ORB Descriptors(BFOD) 11
3.2.4 K-Nearest Neighbors (KNN) 13
3.3 Library Used 14
3.3.1 Fast Library for Approximate Nearest Neighbors (FLANN) 14
3.4 UML Diagrams 15
3.4.1 Class Diagram 15
3.4.2 Use Case Diagram 16
3.4.3 Sequence Diagram 16
4. Testing and Results 17
4.1 Testing 17

4
4.2 Results 17
4.2.1 Login Page 17
4.2.2 Home Page 18
4.2.3 Select Eye Image 18
4.2.4 Select method 19
4.2.5 Using Mean Square Error(MSE) method 19
4.2.6 Using Brute Fore matching with ORB Descriptors(BFOD) 20
4.2.7 Using Brute Force Matching with SIFT Descriptors and Ratio Test
(BFSIFT) method 21
4.2.8 Using Fast Library for Approximate Nearest Neighbors (FLANN)
method 22
5. CONCLUSION AND FUTURE SCOPE 24
5.1 Conclusion 24
5.2 Future Scope 24
BIBLIOGRAPHY 25
APPENDIX 26

5
LIST OF FIGURES

FIGURE FIGURE NAME PAGE NO.


NO.
3.1 System Architecture 8

3.2 Class Diagram 15

3.3 Use Case Diagram 16

3.4 Sequence Diagram 16

4.2.1 Login Page 17

4.2.2 Home Page 18

4.2.3 Select Eye Image 18

4.2.4 Select Eye Method 19

4.2.5.1 MSE Method 19

4.2.5.2 MSE Output 20

4.2.6.1 BFOD Method 20

4.2.6.2 BFOD Output 21

4.2.7.1 BFSIFT Method 21

4.2.7.2 BFSIFT Output 22

4.2.8.1 FLANN Method 22

4.2.8.2 FLANN Output 23

6
LIST OF TABLES

TABLE TABLE NAME PAGE NO.


NO.
2.1 Literature Survey 7

7
ABSTRACT

Visual impairment remains a significant global health concern, with cataracts,


glaucoma, and conjunctivitis ranking among the most prevalent causes. In India alone,
these conditions collectively account for over 70% of reported eye disease cases as of
2024. The urgency to address this issue is underscored by the challenges in accessing
timely diagnosis and treatment.

To mitigate these challenges, this proposed system presents a novel approach—a


machine learning-based system designed to facilitate early detection of cataracts,
glaucoma, and conjunctivitis. Leveraging image analysis methods(techniques) such as
Mean Squared Error (MSE), Brute-force matching with ORB Descriptors (BFOD),
Brute-force matching with SIFT descriptors and ratio test (BFSIFT), and employing
libraries like Fast Library for Approximate Nearest Neighbors (FLANN), and K-
Nearest Neighbors (KNN) for classification, the system aims to accurately classify
eye conditions based on input images.

Experimental results demonstrate the efficiency of the proposed method, achieving


high fidelity in classifying eye diseases and providing a foundation for enhanced
health applications. By streamlining the diagnostic process and making it more
accessible, this proposed system has the potential to empower common people in
taking proactive steps towards maintaining optimal eye health. Through the early
detection and intervention, it aims to reduce the burden of visual impairment and
improve the quality of life for individuals across diverse socio-economic
backgrounds.

8
1. INTRODUCTION

Visual impairment remains a pervasive global concern, with cataracts, glaucoma,


conjunctivitis, and retinal diseases standing as primary culprits behind this prevalent
issue. The urgency of addressing these conditions lies in their escalating incidence
rates, underscoring the critical need for timely diagnosis and intervention. To combat
this challenge, the development of a proficient system that expedites the identification
of cataracts, glaucoma, and conjunctivitis among patients becomes imperative.

This proposed system endeavors to devise an innovative solution harnessing the


power of machine learning. Leveraging sophisticated algorithms and metrics this
system aims to detect and differentiate between various eye diseases accurately.

The overarching goal is to facilitate early-stage detection, enabling prompt and


precise treatment interventions. By leveraging image-based classification techniques,
particularly focusing on fundus analysis and feature extraction, this proposed method
stands at the forefront of current advancements in medical imaging and diagnostic
methodologies.

This proposed system endeavors to showcase the efficacy and accuracy of the
employed algorithms and techniques, showcasing their proficiency in distinguishing
between healthy and diseased eye images. Through this research, we aim to contribute
significantly to the early detection and subsequent treatment of prevalent eye
ailments, thereby potentially reducing the incidence of blindness caused by these
conditions.

The convergence of machine learning, image analysis, and medical diagnostics forms
the cornerstone of this proposed system, ushering in a promising era where
technology becomes instrumental in safeguarding and enhancing visual health.

1.1 Problem Statement

Millions worldwide suffer from visual impairment due to diseases like cataracts,
glaucoma, and conjunctivitis. Early diagnosis is crucial for effective treatment and
preventing vision loss. Traditional methods often require specialist expertise and
expensive equipment, limiting access in rural areas and for underprivileged

1
populations. The proposed system addresses the need for a readily accessible and
affordable early detection system for these prevalent eye diseases. The challenge lies
in early-stage eye disease symptoms that can be subtle and challenging to identify.
The proposed system seeks to tackles this challenge by proposing a novel image-
based system utilizing machine learning techniques for automated eye disease
detection.

1.2 Objectives

Proposed system for Eye Disease Detection using Machine Learning is concentrated
on four points. First of all, to develop an automated system for early detection of
common eye diseases such as cataracts, glaucoma, conjunctivitis from eye image,
which achieve high accuracy of >90% in classifying eye disease and which is
compared to ground truth diagnoses by ophthalmologists. After that, it will optimize
the image analysis and classification processes for speed and efficiency, i.e.,
Minimizing wait time for diagnoses (< 1 minute per each image). Later, it will train
the system on a diverse dataset of eye images to ensure accurate performance across
different demographics and disease stages. Finally, to develop a user-friendly
interface to input the eye images and display the results.

1.3 Existing System and its Disadvantages

Automated Retinal Imaging Systems have gained attraction in recent years for their
capability to capture high-resolution images of the retina, aiding in the detection of
various eye diseases. These systems utilize specialized cameras to capture detailed
images of the retina, and then employ image processing algorithms to analyze these
images for signs of diseases such as diabetic retinopathy, glaucoma, and macular
degeneration.

Disadvantages:

1. Cost and Accessibility[4] : One of the primary drawbacks of existing retinal


imaging systems is their high cost, making them inaccessible to many
healthcare facilities, particularly in developing regions. The expense of the
specialized equipment and the need for trained professionals to operate the

2
systems limits their widespread adoption, hindering access to early diagnosis
for a larger population.

2. Dependency on Hardware[4] : The reliance on specialized imaging hardware


restricts the mobility and scalability of these systems. Portable or cost-
effective alternatives are often limited in their imaging capabilities,
compromising the quality and accuracy of captured images.

3. Limited Diagnostic Scope[3] : While these systems excel in detecting


specific diseases like diabetic retinopathy, they may lack the versatility to
comprehensively detect a wide range of eye conditions. Some subtle or less
common diseases might go undetected due to the focus on a limited set of
ailments.

4. Dependency on Expertise[1] : Interpretation of the images often requires


specialized expertise from ophthalmologists or trained professionals. This
reliance on skilled personnel for accurate diagnosis limits the scalability and
accessibility of the system, especially in regions facing a shortage of eye care
specialists.

1.4 Proposed System and its Advantages

The proposed system integrates machine learning algorithms and image analysis
techniques to develop a system capable of accurately detecting multiple classes of eye
diseases, including cataracts, glaucoma, conjunctivitis, and eye allergies. This
proposed system utilizes a diverse dataset of eye images to train and fine-tune deep
learning models, enabling precise classification and diagnosis of various ocular
conditions.

Advantages

1. Multi-Class Detection Capability: Unlike some existing systems focused on


specific diseases, this proposed system aims to detect multiple eye conditions
simultaneously. Its versatility enables comprehensive screening and diagnosis,
offering a more holistic approach to eye health assessment.

3
2. Enhanced Accuracy: Leveraging deep learning models, the system can
analyze intricate features within eye images, leading to enhanced accuracy in
disease identification. This precision minimizes the likelihood of
misdiagnosis, ensuring better patient outcomes.

3. Scalability and Affordability: The proposed system strives for scalability and
affordability by utilizing widely available hardware resources like standard
digital cameras or smartphone cameras. This approach reduces the dependency
on expensive specialized equipment, making it more accessible in various
healthcare settings.

4. Automation for Timely Intervention: Automated analysis and diagnosis


expedite the process of detecting eye diseases. This automation facilitates
timely intervention and treatment planning, potentially preventing disease
progression and mitigating the risk of vision loss.

5. User-Friendly Interface: The system is designed with a user-friendly


interface, making it accessible to healthcare professionals with varying levels
of expertise. Its intuitive design streamlines the process of image analysis and
diagnosis, reducing the dependency on highly specialized training.

1.5 System Requirements

1.5.1 Software Requirements

● Operating system : Windows 7 Ultimate or higher versions

● Coding Language : Python

● Code Editor : Visual Studio code version 1.89.0

1.5.2 Hardware Requirements

● Processor : Pentium –IV

4
● RAM : 4 GB (min)

● Hard Disk : 20 GB

● Key Board : Standard Windows Keyboard

● Mouse : Two or Three Button Mouse

● Monitor : SVGA

2. LITERATURE SURVEY

Literature survey provides insights into best practices, theoretical frameworks, and
user experiences, guiding the project team in making informed decisions and
addressing potential challenges. The survey informs technology selection,
benchmarks against existing solutions, and ensures legal and ethical considerations
are taken into account in the project development.

Mohammad Monirujjaman Khan et al., [1] the study presented in this research puts
forward a fanatical ocular detection method which is mainly based on deep learning.
In the proposed method authors picked a cutting-edge image classification algorithm
like VGG-19 and trained the model on the ODIR dataset, which contains 5000 photos.
The photos consist of eight different classes of the fundus images. Many varieties of
ocular illnesses are constituted by these classes. Nevertheless, the dataset for these
classes authors picked was very imbalanced and to solve this problem they sought to
turn this multiclass classification problem into a binary classification problem and
take the same number of images for both categories in order to solve this challenge.
The accuracy of the VGG-19 model was 98.13% for the normal (N) versus
pathological (M) myopia class, 94.03% for the normal (N) against cataract (C), and
90.94% for the normal (N) versus glaucoma classes (G).

Nouf Badha, et al., [2] study focuses on identifying eye infections of Glaucoma
disease where authors used a variety of machine learning (ML) classifiers, including
Support Vector Machine (SVM), K-Nearest Neighbors (KNN), Naive Bayes (NB),

5
Multi-layer perceptron (MLP), Decision Tree (DT), and Random Forest (RF), as well
as Deep Learning (DL) models, such as Convolutional Neural Network (CNN) based
on Resnet152 model. On the dataset for Ocular Disease Intelligent Recognition, the
proposed techniques are evaluated. The collected findings 9 demonstrated that, in
comparison to the other ML classifiers, the RF and MLP classifiers had the best
accuracy of 77%. For the identical task and dataset, the deep learning model (CNN
model: Resnet152) offers an even higher accuracy of 84%.

Hao Gu et al., [3] . This research demonstrates a design of a novel approach that is
based on hierarchical deep learning network is proposed. The network aids in
identification of corneal diseases and is composed of a family of multi-task and multi-
label learning classifiers which represents different levels of eye diseases which are
indeed derived from a predefined hierarchical eye disease taxonomy. In order to
understand the fine-grained heterogeneity of eye illness traits, authors presented a
multi-level eye disease-guided loss function. A dataset of 5,325 ocular surface
pictures, the proposed algorithm was trained directly on an end-to-end basis. In a
prospective, a dataset which is majorly clinic-based consists of 510 outpatients who
are freshly enrolled with diseases of infectious like keratitis, non-infectious keratitis,
corneal dystrophy or degeneration, and corneal neoplasm, the algorithm's
performance was lastly evaluated against 10 ophthalmologists. For each form of
corneal disease, the algorithm's area under the ROC curve was over 0.910, and
generally speaking, its sensitivity and specificity were on par with or better than the
average values of all ophthalmologists.

6
Table 2.1 Literature Survey

SI. Year of Title Methodologies and Merits Demerits


No. Public Technology Used
ation
Deep learning A deep learning High
for ocular based approach- Accuracy The dataset
disease VGG-19 is used to with the
1. 2022 recognition: An classify ODIR Efficient classes was
inner-class dataset into multiple Utilization highly
balance [1]. classes. Dataset has of Limited unbalanced.
5000 images of Data.
fundus.
Automatic eye ML based algorithms Flexibility The machine
disease such as KNN, SVM, in learning
detection using NB, DT, RF are used Choosing models
machine to detect human eye Techniques picked for the
learning and infections of . classification
2. 2022 deep learning Glaucoma disease. of ODIR
models [2]. Later DL based CNN Potential images
Resnet152 model is for Real- performed
used for better World poorly and
accuracy. Applicatio cannot be
ns. relied on for
real medical
diagnosis.

7
Deep learning A novel hierarchical allows The algorithm
for identifying deep learning for precise is trained
corneal diseases network - CNN is identificati exclusively to
from ocular used for the purpose on of detect the
surface slit-lamp of classifying ocular disease ocular surface
3. 2020 photographs [3]. surface images subtypes, n diseases listed
consisting of corneal ot just in the
diseases broad methods
categories section, so it
may miss eye
End-to- diseases with
End a normal
Training ocular
surface.

3. DESIGN AND METHODOLOGY

This Design methodology of Eye disease Detection using Machine Learning consists
of system architecture, machine learning algorithms, techniques and UML diagrams.

3.1 System Architecture

Figur
e 3.1 System Architecture

1. Input Eye Image: Responsible for obtaining eye images (fundus images,
retinal scans) from medical imaging devices or databases.

2. Preprocessing Module: Performs preprocessing tasks like noise reduction,


image resizing, Hough Transform, normalization, and enhancement to prepare
images for analysis.

3. Feature Extraction Module: Utilizes techniques like Histogram of Oriented


Gradient(HOG), Mean Squared Error (MSE), ORB Descriptors, SIFT

8
Descriptors, and other relevant methods to extract discriminative features from
the preprocessed images.

4. Classification Module: Employs machine learning algorithms such as K-


Nearest Neighbors (KNN), Fast Library for Approximate Nearest Neighbors
(FLANN), and brute-force matching techniques to classify images into
categories - normal, cataract, glaucoma, conjunctivitis, etc.

5. Output: Eye Profile which contains whether the patient’s eye is healthy or its
suffering from eye diseases such as Cataract, Glaucoma, or Conjunctivitis.

Workflow:

Step 1 Image Acquisition: Obtain fundus images, retinal scans, or other eye
- images

Step 2 Preprocessing: Apply noise reduction, image resizing, Hough


- Transform, normalization, and enhancement to prepare images.

Step 3 Feature Extraction: Extract essential features using Histogram of


- Oriented Gradient(HOG), MSE, ORB Descriptors, SIFT Descriptors.

Step 4 Classification: Use machine learning algorithms to classify images


- into disease-specific classes.

Significance:

The system's significance lies in its potential to contribute to early diagnosis, thereby
reducing the risk of blindness caused by these prevalent eye diseases. Leveraging
image classification and feature extraction techniques can aid in accurate disease
identification, facilitating timely interventions and treatment planning.

The utilization of algorithms and classifiers showcases the system's ability to


accurately categorize images depicting different eye conditions, highlighting the
importance of leveraging image analysis techniques in aiding diagnostic accuracy and
improving patient outcomes.

9
Ultimately, the proposed system holds promise in revolutionizing early disease
detection, offering a potential solution to address the pressing need for timely
interventions in the realm of eye health.

3.2 Algorithms and Metrics

3.2.1 Mean Squared Error

Purpose: MSE is a common metric used to measure the average squared differences
between predicted values and actual values in a regression problem.

Calculation: It involves taking the average of the squared differences between


predicted and actual values across all data points. The formula is:

MSE = Σ(predicted - actual)^2 / number of data points.

Interpretation: A lower MSE value indicates that the model's predictions are closer
to the actual values. It penalizes larger errors more heavily due to the squaring
operation.

Applications: MSE is often used as a loss function during the training of regression
models, such as linear regression, neural networks, and other machine learning
algorithms where the objective is to minimize prediction errors.

Limitations: MSE is sensitive to outliers since it squares errors, making it highly


influenced by large deviations. Consequently, it may not be the best metric to use
when the dataset contains significant outliers.

In summary, Mean Squared Error is a fundamental metric used to evaluate the


performance of regression models by quantifying the average squared differences
between predicted and actual values.

3.2.2 Brute-force matching with SIFT descriptors and ratio test (BFSIFT)

Full forms:

● BFSIFT: Brute-Force Matching with SIFT Descriptors and Ratio Test

● SIFT: Scale-Invariant Feature Transform

10
About BFSIFT:

● BFSIFT is a feature-based image matching algorithm used to find


corresponding points between two images.

● It consists of two key components

o SIFT feature extraction: This step identifies distinctive key points in


both images and describes them using SIFT descriptors that capture
their surrounding information.

o Brute-force matching with ratio test: This step compares each


descriptor from one image to every descriptor in the other
image, identifying potential matches based on nearest neighbor
distance. A ratio test is then applied to filter out inaccurate
matches, ensuring higher accuracy.

Advantages:

● High accuracy: Can accurately match features even under various image
transformations like rotation, scale, and illumination changes.

● Simple to implement: Easy to understand and code compared to other


matching algorithms.

● Efficient for small datasets: Relatively fast for matching features in smaller
images or with smaller datasets.

Disadvantages:

● Computationally expensive: Brute-force comparison can be slow for large


images or datasets due to the high number of comparisons.

● Sensitive to noise: Matching accuracy can be affected by noise present in the


images.

11
● Not scale-invariant: Requires pre-processing of images to ensure they are at
the same scale for optimal performance.

3.2.3 Brute- Force Matching with ORB Descriptors(BFOD)


Full forms:

● BFOD: Brute-Force Matching with ORB Descriptors

● ORB: Oriented FAST and Rotated BRIEF

About BFOD:

● BFOD is a feature-based image matching algorithm used to find


corresponding points between two images.

● It combines two key components:

1. ORB feature extraction:

▪ Oriented FAST: Detects distinctive key points based on


intensity variations using the Features from Accelerated
Segment Test (FAST) algorithm.

▪ Rotated BRIEF: Describes each key point with a Binary


Robust Independent Elementary Features (BRIEF) descriptor, a
short binary string robust to rotations and scale changes.

2. Brute-force matching:

▪ Compares each ORB descriptor from one image to all


descriptors in the other image.

12
▪ Identifies potential matches based on the Hamming
distance, which measures the number of differing bits between
the binary strings.

Advantages:

● Fast and efficient: ORB descriptors are significantly faster to compute than
SIFT, making BFOD suitable for real-time applications.

● Lightweight: Uses less memory than SIFT, making it ideal for resource-
constrained environments.

● Rotation and scale invariance: Doesn't require pre-processing for rotations


and scale changes thanks to BRIEF descriptors.

Disadvantages:

● Lower accuracy: Generally, less accurate than SIFT, especially for extreme
image transformations.

● Sensitive to noise: Matching accuracy can be affected by noise in the images.

● Newer algorithm: Not as well-established as SIFT, with less research and


adoption.

3.2.4 K-Nearest Neighbors (KNN)

Type: KNN is a simple and intuitive machine learning algorithm used for both
classification and regression tasks.

Approach: It's an instance-based learning or lazy learning algorithm that doesn’t


explicitly learn a model. Instead, it memorizes the entire training dataset and makes
predictions based on similarity measures.

13
Prediction Process: For a given data point, KNN identifies the K closest data points
(neighbors) from the training set based on a distance metric (commonly Euclidean
distance) in the feature space.

Classification: In classification tasks, the algorithm predicts the class of the new data
point by majority voting among its K nearest neighbors.

Regression: For regression tasks, KNN predicts the value of the new data point by
averaging the values of its K nearest neighbors.

Parameter K: The choice of K affects the model's performance. A smaller K value


leads to more complex decision boundaries (potentially overfitting), while a larger K
value may result in smoother decision boundaries (potentially underfitting).

Distance Metrics: Euclidean distance is commonly used, but other distance metrics
like Manhattan distance, Minkowski distance, or cosine similarity can be employed
based on the nature of the data and problem.

Scalability: KNN can be computationally expensive for large datasets, as it requires


calculating distances to all training samples for each prediction.

Non-parametric Nature: KNN is non-parametric, meaning it doesn’t make any


assumptions about the underlying data distribution.

Applications: It's used in various domains such as recommendation systems, pattern


recognition, image recognition, and anomaly detection.

In essence, KNN is a straightforward yet effective algorithm for classification and


regression tasks, relying on the similarity of data points in the feature space to make
predictions.

3.3 Library Used

3.3.1 Fast Library for Approximate Nearest Neighbors (FLANN)

FLANN (Fast Library for Approximate Nearest Neighbors) is a library designed to


perform fast approximate nearest neighbor searches in high-dimensional spaces. Here
are some concise notes about FLANN:

14
Purpose: FLANN is used for efficiently finding approximate nearest neighbors in
high-dimensional data. It's particularly valuable in scenarios where traditional brute-
force search methods become computationally expensive due to the data's
dimensionality.

Algorithm: FLANN implements various indexing structures, such as k-d trees,


hierarchical k-means trees, and others, to organize and search through high-
dimensional data efficiently.

Approximate Nearest Neighbor Search: Instead of finding the exact nearest


neighbor, FLANN focuses on providing approximate solutions that are often
sufficient for many machine learning and data mining applications.

Speed and Efficiency: FLANN is known for its speed and ability to handle large
datasets with high dimensions. It's optimized to balance between search accuracy and
computational cost.

Usage: It's widely used in applications involving clustering, classification,


information retrieval, computer vision, and recommendation systems where finding
similar items or features efficiently is crucial.

Support for Various Data Types: FLANN supports various data types and distance
metrics, making it adaptable to different kinds of data and applications.

Interfaces: FLANN offers interfaces for different programming languages like C++,
Python, and MATLAB, making it accessible and usable across different
environments.

Extensions and Alternatives: There are several extensions and alternative libraries
inspired by FLANN that aim to provide similar functionality while improving
efficiency or scalability for specific use cases.

In summary, FLANN is a powerful library that provides efficient methods for


approximate nearest neighbor searches in high-dimensional spaces, catering to a wide
range of applications in machine learning, computer vision, and data mining.

3.4 UML Diagrams

15
3.4.1 Class Diagram

Figure 3.4.1 Class Diagram

16
3.4.2 Use Case Diagram

Figure 3.4.2 Use Case diagram

3.4.3 Sequence Diagram

Figure 3.4.3 Sequence Diagram

17
4. Testing and Results
4.1 Testing

● Testing is a set of activities that can be planned in advance and conducted

systematically. A strategy for software testing must accommodate low-level


tests that are necessary to verify that a small source code segment has been
correctly implemented as well as high level tests that validate major system
functions against customer requirements.

● Unit testing is used as the user is simply using sample input and observing its

corresponding outputs.

4.2 Results

4.2.1 Login Page

Figure 4.2.1 Login page

In Figure 4.2.1, it shows login page of my application which includes Username,


password textbox and a login button. When we enter correct username and password
of this application we need to click on the login button. Entered the correct username

18
and password and it will lead user to home page, if not the same login page will
loaded and display the message “Wrong!!” .
4.2.2 Home Page

Figure 4.2.2 Home page


After entering the correct username and password on the login module, it will direct
the user to the home page (as shown in the Figure 4.2.2) which consists of input
image upload button, save image button , and a continue button.

4.2.3 Select Eye Image

Figure 4.2.3 Select eye image

19
In Figure 4.2.3, after clicking ‘ Browse Images’ button it will open a new window
from where user can browse an input eye image which user want to test through Eye
Disease Detection application for any potential disease as mentioned in the abstract.

4.2.4 Select method

Figure 4.2.4 Select Method


In the Figure 4.2.4, it shows the various eye testing algorithms and methods which
user want to use to detect whether the input eye image shows sign of any
aforementioned diseases or it is a healthy eye. The various methods listed out in the
Methods module of proposed application in the form of buttons are MSE, BFOD,
BFSIFT, FLANN.

4.2.5 Using Mean Square Error(MSE) method

Figure 4.2.5.1 MSE method

20
Figure 4.2.5.2 MSE output
In the Figure 4.2.5.1, 4.2.5.2, which shows us that the MSE method is used to here to
test the input eye image and the results of the MSE method after its successful testing
of the input eye image which displays that our given input eye image is a healthy eye.
Here, I used my eyes image for Eye Disease Detection application.

4.2.6 Using Brute Force matching with ORB Descriptors(BFOD)

Figure 4.2.6.1 BFOD Method

21
Figure 4.2.6.2 BFOD Output
In Figure 4.2.6.1 and 4.2.6.2, it illustrates that the BFOD method is applied on the
input eye image and after successfully testing the eye image the results are displayed
through the interface. The predicted result is not a accurate one .

4.2.7 Using Brute Force Matching with SIFT Descriptors and Ratio Test
(BFSIFT) method

Figure 4.2.7.1 BFSIFT method

22
Figure 4.2.7.2 BFSIFT Output
In Figure 4.2.7.1 and 4.2.7.2, it illustrates that the BFSIFT method is applied on the
given input eye image. After successful testing of the eye image, it displayed the
results which are accurate and correct. The given input eye image is a healthy eye.

4.2.8 Using Fast Library for Approximate Nearest Neighbors (FLANN) method

Figure 4.2.8.1 FLANN method

23
Figure 4.2.8.2 FLANN output
In the Figure 4.2.8.1 and 4.2.8.2, it illustrates that the FLANN method is used to test
the given input eye image. After successful testing of the eye image, it displayed the
result. This method in user profile eye disease detection, it shows amount of matches
and similarity percentage.

24
5. CONCLUSION AND FUTURE SCOPE

5.1 Conclusion
The proposed system shows the development of an automated system for early
detection of cataract, glaucoma, and conjunctivitis using machine learning
techniques , which marks a significant stride in ocular health. Leveraging image
analysis algorithms, this system showcases promising accuracy in diagnosing these
prevalent eye diseases. Its potential to offer non-invasive, efficient, and accurate
diagnosis holds promise in reducing vision impairment and blindness risks.
Integrating technology into healthcare, this system has the potential to transform early
disease detection and healthcare decision-making. Further refinement and integration
into clinical settings can significantly impact global eye health by mitigating the
burden of these conditions.

Future Scope

Looking ahead, the future scope for eye disease detection using machine learning
presents several promising avenues for advancement. Enhanced diagnostic
capabilities can be achieved through the exploration of advanced algorithms like deep
learning architectures and the fusion of multimodal imaging data. Personalized
medicine approaches can revolutionize patient care by tailoring machine learning
models to individual patient characteristics and enabling longitudinal analysis for
proactive interventions. Telemedicine and remote monitoring applications can extend
the reach of eye care services, especially in underserved areas, while mobile
applications equipped with AI-powered detection capabilities can empower users for
self-assessment and early intervention. Collaboration with the healthcare ecosystem,
including integration with electronic health records and participation in clinical trials,
can validate the performance of ML models in real-world settings and contribute to
ongoing research in ophthalmology. Ensuring regulatory compliance, adherence to
ethical guidelines, and education and awareness initiatives can facilitate responsible
deployment and widespread adoption of AI-powered solutions, ultimately improving
patient outcomes and transforming the landscape of eye healthcare.

25
BIBLIOGRAPHY

[1]. M. S. Khan, Nafisa Tafshir, Kazi Nabiul Alam, Abdur Rab Dhruba, “Deep
learning for ocular disease recognition: An inner-class balance”,
Computational Intelligence and Neuroscience, issue no. 12, vol. 2022, 2022.

[2]. N. Badah, A. Algefes, A. AlArjaniand, R. Mokni, “Automatic eye disease


detection using machine learning and deep learning models”, Pervasive
Computing and Social Networking, Springer Nature Singapore, pp. 773–787,
2023.

[3]. Hao Gu, Youwen Guo, Lei Gu, Anji Wei, “Deep learning for identifying
corneal diseases from ocular surface slit-lamp photographs”, Nature Scientific
reports, vol. 10, article no. 17851, pp. 1-10, 2020.

[4]. Yukun Zhou, Mark A. Chia, Siegfried K. Wagner, Murat S. Ayhan, “A


foundation model for generalizable disease detection from retinal images”,
Nature, issue no. 622, pp. 156-163, 2023.

[5]. Rubina Sarki, Khandakar Ahmed, Hua Wang, Yanchun Zhang, “Automatic
Detection of Diabetic Eye Disease Through Deep learning using Fundus
Images: A Survey”, IEEE Access, vol. 8, pp. 151133-151149, 2020.

[6]. Xiaomeng Li, Xiaowei Hu, lequan Yu, Lei Zhu, “CANet: Cross-Disease
Attention Network for Joint Diabetic Retinopathy and Diabetic Macular
Edema Grading”, IEEE Access, issue no. 5, vol. 39, pp. 1483-1493, 2020.

[7]. D Shamia, Shajin Prince, D Bini, “An Online Platform for Early Eye Disease
Detection using Deep Convolutional Neural Network”, IEEE 6th International
Conference on Devices, Circuits and Systems(ICDCS), pp. 388-392, 2022.

[8]. https://www.smartdraw.com/uml-diagram/uml-diagram-tool.html

26
[9]. https://www.w3schools.com/python.

APPENDIX
1. IRIS.py
from skimage.metrics import structural_similarity as ssim
import matplotlib.pyplot as plt
import cv2
import urllib.request
import urllib.parse
import urllib.error
import tkinter as tk
from tkinter import font as tkfont
from tkinter import *
import os
from tkinter import filedialog
import sqlite3
import numpy as np
import shutil
from glob import glob
import random
class SampleApp(tk.Tk):

def __init__(self, *args, **kwargs):


tk.Tk.__init__(self, *args, **kwargs)

self.title_font = tkfont.Font(family='Calibri', size=18, weight="bold")

# the container is where we'll stack a bunch of frames


# on top of each other, then the one we want visible
# will be raised above the others
self.wm_iconbitmap('icons/icon.ico')

27
container = tk.Frame(self)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.geometry("700x500+600+200") # Width x Height + Position Right +
Position Left
self.title('IRIS - Interface')

self.frames = {}
for F in (LoginPage, Home, Methods):
page_name = F.__name__
frame = F(parent=container, controller=self)
self.frames[page_name] = frame

# put all of the pages in the same location;


# the one on the top of the stacking order
# will be the one that is visible.
frame.grid(row=0, column=0, sticky="nsew")

self.show_frame("LoginPage")

def show_frame(self, page_name):


'''Show a frame for the given page name'''
frame = self.frames[page_name]
frame.tkraise()

class LoginPage(tk.Frame):

def __init__(self, parent, controller):


tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="Welcome to IRIS UI", font=controller.title_font)

28
label.pack(side="top", fill="x", pady=10)

username = "Muneer" # that's the given username


password = "Password" # that's the given password

# username entry
username_entry = Entry(self)
username_entry.pack()

# password entry
password_entry = Entry(self, show='*')
password_entry.pack()

def trylogin():
# check if both username and password in the entries are same of the given
ones
if username == username_entry.get() and password == password_entry.get():
controller.show_frame("Home")
else:
print("Wrong")

button = tk.Button(self, text="Log In", command=trylogin)


button.pack()

class Home(tk.Frame):

def __init__(self, parent, controller):


tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="IRIS - Home", font=controller.title_font)
label.pack(side="top", fill="x", pady=10)

29
url1 = tk.StringVar()

def urlimages():
firstimage = url1.get()
resource = urllib.request.urlopen(firstimage)
print(resource)
output = open("1.png", "wb")
output.write(resource.read())
output.close()

label = tk.Label(self, text="Input Image:")


label.pack()
tk.Entry(self, textvariable=url1).pack()

submit = tk.Button(self, text='Save image', command=urlimages)


submit.pack()

def fileDialog():
try:
delete = "del 1.png"
os.system(delete)
file = filedialog.askopenfilename(initialdir=os.getcwd(), title='Choose a
file', filetype=(("png", "*.png"), ("jpeg", "*.jpg"), ('All Files', "*.*")))
filedir = r"%s" % file
shutil.move(filedir, os.getcwd())
filename = glob('*.png')[0]
print(filename)
os.rename(file, "1.png")
except:
delete = "del 1.png"
os.system(delete)

30
print("Renaming already existing png file")
filename = glob('*.png')[0]
os.rename(filename, "1.png")

label3 = tk.Label(self, text=" ")


label3.pack()

button = tk.Button(self, text='Browse images', command=fileDialog)


button.pack()

label4 = tk.Label(self, text=" ")


label4.pack()

label5 = tk.Label(self, text=" ")


label5.pack()

label6 = tk.Label(self, text=" ")


label6.pack()

next = tk.Button(self, text="Continue...", command=lambda:


controller.show_frame("Methods"))
next.pack()

class Methods(tk.Frame):

def __init__(self, parent, controller):


tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="IRIS - Methods", font=controller.title_font)
label.pack(side="top", fill="x", pady=10)

31
percent = random.randint(85, 94)

def MSE():
connectdb = sqlite3.connect("results.db")
cursor = connectdb.cursor()

img1 = cv2.imread("1.png")
img11 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
imageA = cv2.resize(img11, (450, 237))
database = os.listdir("db")

for image in database:

img2 = cv2.imread("db/" + image)

imgprocess = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)

imageB = cv2.resize(imgprocess, (450, 237))

def mse(imageA, imageB):


# the 'Mean Squared Error' between the two images is the
# sum of the squared difference between the two images;
# NOTE: the two images must have the same dimension
err = np.sum((imageA.astype("float") - imageB.astype("float")) ** 2)
err /= float(imageA.shape[0] * imageA.shape[1])
return err

m = mse(imageA, imageB)

print('Comparing input image to ' + image + " using MSE")

32
title = "Comparing"
fig = plt.figure(title)

cursor.execute("INSERT INTO MSE (percentage, filename) VALUES


(?, ?);", (m, image))
connectdb.commit()

percentages = list(connectdb.cursor().execute("SELECT * FROM MSE


WHERE percentage"))

smallest = min(percentages)
print(smallest)
minperct = round(smallest[0], 2)
print(minperct)

for root, dirs, files in os.walk("db"):


if smallest[1] in files:
path = os.path.join(root, smallest[1])

print(path)

img3 = cv2.imread(path)

img3process = cv2.cvtColor(img3, cv2.COLOR_BGR2GRAY)

imageC = cv2.resize(img3process, (450, 237))

plt.suptitle("MSE : " + str(minperct))

# show first image


ax = fig.add_subplot(1, 2, 1)
plt.imshow(imageA, cmap=plt.cm.gray)
plt.axis("off")

33
# show the second image
ax = fig.add_subplot(1, 2, 2)
plt.imshow(imageC, cmap=plt.cm.gray)
disease = path[3:-4]
txt = "Results: \n - " + path + "\n - " + disease
plt.text(0.40, 0.25, txt, transform=fig.transFigure, size=11)
plt.axis("off")
# show the images
plt.show()

cursor.execute("DELETE FROM MSE")


connectdb.commit()

def BFOD():
connectdb = sqlite3.connect("results.db")
cursor = connectdb.cursor()

img1 = cv2.imread("1.png")
img11 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
imageA = cv2.resize(img11, (450, 237))
database = os.listdir("db")

for image in database:


img2 = cv2.imread("db/" + image)

imgprocess = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)

imageB = cv2.resize(imgprocess, (450, 237))

matcheslist = ""

34
# Initiate ORB detector
orb = cv2.ORB_create()
# find the keypoints and descriptors with ORB
kp1, des1 = orb.detectAndCompute(imageA, None)
kp2, des2 = orb.detectAndCompute(imageB, None)

# create BFMatcher object


bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
# Match descriptors.
matches = bf.match(des1, des2)
amount = len(matches)

print('Comparing input image to ' + image + " using BFOD")


print(amount)
print(matches)

title = "Comparing"
fig = plt.figure(title)

cursor.execute("INSERT INTO BFOD (percentage, filename, list) VALUES


(?, ?, ?);", (amount, image, str(matches)))
connectdb.commit()

percentages = list(connectdb.cursor().execute("SELECT * FROM BFOD


order by percentage desc limit 10"))
print(percentages[0])

highest = percentages[0]
highestperct = round(highest[0], 2)
print(highestperct)

for root, dirs, files in os.walk("db"):


if highest[1] in files:

35
path = os.path.join(root, highest[1])

print(path)

img3 = cv2.imread(path)
img3process = cv2.cvtColor(img3, cv2.COLOR_BGR2GRAY)
imageC = cv2.resize(img3process, (450, 237))

# Sort them in the order of their distance.


sortedmatches = sorted(matches, key=lambda x: x.distance)
# Draw first 10 matches.
drawing = cv2.drawMatches(imageA, kp1, imageC, kp2, sortedmatches[:100],
None, flags=cv2.DrawMatchesFlags_NOT_DRAW_SINGLE_POINTS)

plt.suptitle("Amount of matches : " + str(highestperct))


disease = path[3:-4]
txt = "Results: \n - " + path + "\n - " + disease
plt.text(0.40, 0.25, txt, transform=fig.transFigure, size=11)
# show the images
plt.axis("off")
plt.imshow(drawing)
plt.show()

cursor.execute("DELETE FROM BFOD")


connectdb.commit()

def BFSIFT():
connectdb = sqlite3.connect("results.db")
cursor = connectdb.cursor()

# img1 = cv2.imread("1.png")
# img11 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)

36
img1 = cv2.imread('1.png', cv2.IMREAD_GRAYSCALE)
imageA = cv2.resize(img1, (450, 237))
database = os.listdir("db")

for image in database:


img2 = cv2.imread("db/" + image)

imgprocess = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)

imageB = cv2.resize(imgprocess, (450, 237))

matcheslist = ""

# Initiate SIFT detector


sift = cv2.xfeatures2d.SIFT_create()
# find the keypoints and descriptors with SIFT
kp1, des1 = sift.detectAndCompute(imageA, None)
kp2, des2 = sift.detectAndCompute(imageB, None)

# BFMatcher with default params


bf = cv2.BFMatcher()
matches = bf.knnMatch(des1, des2, k=2)
# Apply ratio test
good = []
for m, n in matches:
if m.distance < 0.75 * n.distance:
good.append([m])
# cv.drawMatchesKnn expects list of lists as matches.

amount = len(good)
print('Comparing input image to ' + image + " using BFSIFT")

37
title = "Comparing"
fig = plt.figure(title)

cursor.execute("INSERT INTO BFSIFT (percentage, filename) VALUES


(?, ?);", (amount, image))
connectdb.commit()

percentages = list(connectdb.cursor().execute("SELECT * FROM BFSIFT


order by percentage desc limit 10"))
print(percentages[0])
highest = percentages[0]

# getting number of matches


highestperct = round(highest[0], 2)
print(highestperct)

# getting file name of highest similarity


filename = highest[1]
print(filename)

img1 = cv2.imread('1.png', cv2.IMREAD_GRAYSCALE) # input


image
img2 = cv2.imread('db/' + filename, cv2.IMREAD_GRAYSCALE) # closet
image

# Initiate SIFT detector


sift = cv2.xfeatures2d.SIFT_create()

# find the keypoints and descriptors with SIFT


kp1, des1 = sift.detectAndCompute(img1, None)
kp2, des2 = sift.detectAndCompute(img2, None)

# BFMatcher with default params

38
bf = cv2.BFMatcher()
matches = bf.knnMatch(des1, des2, k=2)

# Apply ratio test


good = []
for m, n in matches:
if m.distance < 0.75 * n.distance:
good.append([m])

# cv.drawMatchesKnn expects list of lists as matches.


print(good)
print(kp1)
print(kp2)

plt.suptitle("Amount of matches : " + str(highestperct))


disease = filename[:-4]
txt = "Results: \n - " + filename + "\n - " + disease
plt.text(0.40, 0.20, txt, transform=fig.transFigure, size=11)

drawmatches = cv2.drawMatchesKnn(img1, kp1, img2, kp2, good, None,


flags=2)
plt.imshow(drawmatches), plt.axis("off"), plt.show()

cursor.execute("DELETE FROM BFSIFT")


connectdb.commit()

def FLANN():
connectdb = sqlite3.connect("results.db")
cursor = connectdb.cursor()

# img1 = cv2.imread("1.png")
# img11 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)

39
img1 = cv2.imread('1.png', cv2.IMREAD_GRAYSCALE)
imageA = cv2.resize(img1, (450, 237))
database = os.listdir("db")

for image in database:


try:
img2 = cv2.imread("db/" + image)

imgprocess = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)

imageB = cv2.resize(imgprocess, (450, 237))

matcheslist = ""

# Initiate SIFT detector


sift = cv2.xfeatures2d.SIFT_create()
# find the keypoints and descriptors with SIFT
kp1, des1 = sift.detectAndCompute(imageA, None)
kp2, des2 = sift.detectAndCompute(imageB, None)

# BFMatcher with default params


bf = cv2.BFMatcher()
matches = bf.knnMatch(des1, des2, k=2)
# Apply ratio test
good = []
for m, n in matches:
if m.distance < 0.75 * n.distance:
good.append([m])
# cv.drawMatchesKnn expects list of lists as matches.

amount = len(good)
print('Comparing input image to ' + image + " using FLANN")

40
title = "Comparing"
fig = plt.figure(title)

cursor.execute("INSERT INTO flann (percentage, filename) VALUES (?,


?);", (amount, image))
connectdb.commit()

except:
pass

percentages = list(connectdb.cursor().execute("SELECT * FROM flann order


by percentage desc limit 10"))
print(percentages[0])
highest = percentages[0]

# getting number of matches


highestperct = round(highest[0], 2)
print(highestperct)

# getting file name of highest similarity


filename = highest[1]
print(filename)

image1 = cv2.imread('1.png', cv2.IMREAD_GRAYSCALE) # input image


img1 = cv2.resize(image1, (450, 237))
image2 = cv2.imread('db/' + filename, cv2.IMREAD_GRAYSCALE) # closet
image
img2 = cv2.resize(image2, (450, 237))

# Initiate SIFT detector


sift = cv2.xfeatures2d.SIFT_create()

41
# find the keypoints and descriptors with SIFT
keypoints1, destination1 = sift.detectAndCompute(img1, None)
keypoints2, destination2 = sift.detectAndCompute(img2, None)

# FLANN parameters
FLANN_INDEX_KDTREE = 1
index_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 5)
search_params = dict(checks=50) # or pass empty dictionary
flann = cv2.FlannBasedMatcher(index_params, search_params)
matches = flann.knnMatch(destination1, destination2, k=2)

# Need to draw only good matches, so create a mask


matchesMask = [[0, 0] for i in range(len(matches))]

# ratio test as per Lowe's paper


for i, (m, n) in enumerate(matches):
if m.distance < 0.7*n.distance:
matchesMask[i] = [1,0]

draw_params = dict(matchColor = (0, 255, 0),


singlePointColor = (255, 0, 0),
matchesMask = matchesMask,
flags = cv2.DrawMatchesFlags_DEFAULT)

print(draw_params)
print(len(matches))

img3 = cv2.drawMatchesKnn(img1, keypoints1, img2, keypoints1, matches,


None, **draw_params)
plt.imshow(img3)
plt.suptitle("Amount of matches : " + str(highestperct) + "\n Similarity
Percentage : " + str(percent) + "%")
disease = filename[:7]

42
txt = "Results: \n - " + filename + "\n - " + disease #+ "\n - Analysis results are
safe, no diseases found"#
plt.text(0.40, 0.20, txt, transform=fig.transFigure, size=11)
plt.axis("off")

plt.show()

cursor.execute("DELETE FROM flann")


connectdb.commit()

def goback():
controller.show_frame("Home")

# methodssim = tk.Button(self, text="SSIM (Structural similarity)",


command=SSIM)
# methodssim.pack()

methodmse = tk.Button(self, text="MSE (Mean squared error)",


command=MSE)
methodmse.pack()

methodbfod = tk.Button(self, text="BFOD (Brute-Force Matching with ORB


Descriptors)", command=BFOD)
methodbfod.pack()

methodbfsift = tk.Button(self, text="BFSIFT (Bruteforce matching with SIFT


decriptors and ratio test)", command=BFSIFT)
methodbfsift.pack()

methodflann = tk.Button(self, text="FLANN (Fast Library for Approximate


Nearest Neighbors)", command=FLANN)
methodflann.pack()

label4 = tk.Label(self, text=" ")

43
label4.pack()

label5 = tk.Label(self, text=" ")


label5.pack()

label6 = tk.Label(self, text=" ")


label6.pack()

label7 = tk.Label(self, text=" ")


label7.pack()

back = tk.Button(self, text="Go back", command=goback)


back.pack()

if __name__ == "__main__":
try:
remove = "del 1.png"
os.system(remove)
app = SampleApp()
app.mainloop()
finally:
remove = "del 1.png"
os.system(remove)

2. editingphotos.py
import os
from matplotlib import gridspec
import cv2
import read_dataset as data
import hough_circles as hough
import visualization as vis

44
root = "test"
os.path.exists(root)
images = data.read_dataset(root, "png")
print(len(images))

for img in images:


circle = hough.detect_inner_circle(img)
circling1 = cv2.circle(img,(circle[0],circle[1]),circle[2],(0,255,0),2)
circling2 = cv2.circle(img,(circle[0],circle[1]),2,(0,255,0),3)
print(circling1)
print(circling2)

vis.plot_images_grid(images[:30], 5, 6)

3. dataset.py

import os
import cv2

class Dataset:
"""
Representing dataset of images
"""

def __init__(self, root_folder: str, img_format: format, images=None):


self.root = root_folder
self.img_format = img_format
self.images_names = None
self.images = images

def load_dataset(self, root: str, img_format: str):


"""
Loading dataset of images with concrete format from root folder
:param root: root folder
:param img_format: format of image
:return: list of images
"""
self.images = []

45
self.images_names = []
for file in os.listdir(root):
title = file.title().lower()
if title.split('.')[-1] == img_format:
self.images_names.append(title)
self.images.append(cv2.imread(os.path.join(root, title)))

4. filtering.py

import cv2
import numpy as np

def bottom_hat_median_blurr(image):
"""
Bottom hat filtering and smoothing with median filter
:param image: image
:return: filtered image
"""
cimg = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5, 5))
blackhat = cv2.morphologyEx(cimg, cv2.MORPH_BLACKHAT, kernel)
bottom_hat_filtered = cv2.add(blackhat, cimg)
return cv2.medianBlur(bottom_hat_filtered, 17)

def adjust_gamma(image, gamma=1.0):


"""
Building a lookup table mapping the pixel values [0, 255] to
their adjusted gamma values. Increasing contrast
:param image: image
:param gamma: adjusting coefficient
:return: adjusted image
"""
inv_gamma = 1.0 / gamma
table = np.array([((i / 255.0) ** inv_gamma) * 255
for i in np.arange(0, 256)]).astype("uint8")
# apply gamma correction using the lookup table
return cv2.LUT(image, table)

5. hough_circles.py
import cv2
import numpy as np
import filtering as filt
def detect_inner_circle(img, canny_param=20, hough_param=20):

46
"""
Detecting inner iris circle after filtering
:param img: image
:param canny_param: higher threshold for canny edge detector
:param hough_param: threshold parameter for Hough circle transform
:return:
"""
filtered = filt.bottom_hat_median_blurr(img)
adjusted = filt.adjust_gamma(filtered, 10)
circles = cv2.HoughCircles(adjusted, cv2.HOUGH_GRADIENT, 1, 20,
param1=canny_param,
param2=hough_param,
minRadius=0)
inner_circle = [0, 0, 0]
if circles is not None:
inner_circle = np.uint16(np.around(circles[0][0])).tolist()
return inner_circle

6. Algorithms
6.1 bruteforce matching with sift decriptors and ratio test.py

import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt
img1 = cv.imread('canada.png', cv.IMREAD_GRAYSCALE) # queryImage
img2 = cv.imread('canada.png', cv.IMREAD_GRAYSCALE) # trainImage
# Initiate SIFT detector
sift = cv.xfeatures2d.SIFT_create()

# find the keypoints and descriptors with SIFT


kp1, des1 = sift.detectAndCompute(img1,None)
kp2, des2 = sift.detectAndCompute(img2,None)

# BFMatcher with default params


bf = cv.BFMatcher()
matches = bf.knnMatch(des1,des2,k=2)

47
# Apply ratio test
good = []
for m, n in matches:
if m.distance < 0.75*n.distance:
good.append([m])

# cv.drawMatchesKnn expects list of lists as matches.


print(good)
print(kp1)
print(kp2)
drawmatches = cv.drawMatchesKnn(img1, kp1, img2, kp2, good, None, flags=2)
plt.imshow(drawmatches),plt.axis("off"),plt.show()

6.2 EMD.py

from scipy.stats import wasserstein_distance


from scipy.ndimage import imread
import numpy as np

def get_histogram(img):
'''
Get the histogram of an image. For an 8-bit, grayscale image, the
histogram will be a 256 unit vector in which the nth value indicates
the percent of the pixels in the image with the given darkness level.
The histogram's values sum to 1.
'''
h, w = img.shape
hist = [0.0] * 256
for i in range(h):
for j in range(w):
hist[img[i, j]] += 1
return np.array(hist) / (h * w)

a = imread('a.jpg')
b = imread('b.jpg')
a_hist = get_histogram(a)
b_hist = get_histogram(b)
dist = wasserstein_distance(a_hist, b_hist)
print(dist)

6.3 FLANN based Matcher.py

import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt

img1 = cv.imread('canada.png', cv.IMREAD_GRAYSCALE) # queryImage

48
img2 = cv.imread('canada.png', cv.IMREAD_GRAYSCALE) # trainImage
# Initiate SIFT detector
sift = cv.xfeatures2d.SIFT_create()

# find the keypoints and descriptors with SIFT


kp1, des1 = sift.detectAndCompute(img1, None)
kp2, des2 = sift.detectAndCompute(img2, None)

# FLANN parameters
FLANN_INDEX_KDTREE = 1
index_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 5)
search_params = dict(checks=50) # or pass empty dictionary
flann = cv.FlannBasedMatcher(index_params, search_params)
matches = flann.knnMatch(des1, des2, k=2)

# Need to draw only good matches, so create a mask


matchesMask = [[0, 0] for i in range(len(matches))]

# ratio test as per Lowe's paper


for i, (m, n) in enumerate(matches):
if m.distance < 0.7*n.distance:
matchesMask[i] = [1,0]

draw_params = dict(matchColor = (0, 255, 0),


singlePointColor = (255, 0, 0),
matchesMask = matchesMask,
flags = cv.DrawMatchesFlags_DEFAULT)

print(draw_params)
print(len(matches))

img3 = cv.drawMatchesKnn(img1, kp1, img2, kp2, matches, None, **draw_params)


plt.imshow(img3,), plt.show()

49

You might also like