Escolar Documentos
Profissional Documentos
Cultura Documentos
A Project Report
on
DETECTION AND MULTISTAGE CLASSIFICATION OF DIABETIC
RETINOPATHY
Submitted by
Internal Guide
Smt. Deepa Yogish
Assistant Professor, Dept. of CSE
BNMIT, Bengaluru
B. N. M. Institute of Technology
12th Main, 27th Cross, Banashankari II Stage, Bengaluru - 560 070
CERTIFICATE
Certified that the project entitled “Detection and Multistage Classification of Diabetic
Retinopathy” carried out by
Mr. Pradeep G 1BG13CS071
Ms. Sneha M.S 1BG13CS101
are bonafied students of VIII Semester B.E, B.N.M Institute of Technology in partial
fulfillment for the Bachelor of Engineering in COMPUTER SCIENCE AND
ENGINEERING, of the Visvesvaraya Technological University, Belagavi, during the
academic year 2016 - 2017. It is certified that all corrections / suggestions indicated for the
internal assessment have been incorporated in the report. The Project report has been
approved as it satisfies the academic requirements in respect of project work prescribed for
the said degree.
Examiner 1:
Examiner 2:
ACKNOWLEDGEMENT
We consider it a privilege to express through the pages of this report, a few words of
gratitude to all those distinguished personalities who guided and inspired me in the
completion of the project.
We would like to thank Shri. Narayan Rao R Maanay, Secretary, BNMIT, Bengaluru for
providing excellent academic environment in college.
We would like to sincerely thank Prof. T. J. Ramamurthy, Director, BNMIT, Bengaluru for
having extended his support and encouragement during the course of work.
We would like to express my gratitude to Dr. M. S. Suresh, Dean, BNMIT, Bengaluru for
his relentless support, guidance and encouragement.
We would like to thank Dr. Krishnamurthy G.N, Principal, BNMIT, Bengaluru for his
constant encouragement.
We would like to thank Dr. Sahana D.Gowda, Professor and Head of the Department of
Computer Science and Engineering, BNMIT, Bengaluru for her support and encouragement
towards the completion of the project.
We would like to express our gratitude to our, guide Smt. Deepa Yogish, Assistant
Professor, Department of Computer Science and Engineering,BNMIT, Bengaluru who has
given us all the support and guidance in completing the project successfully.
We would like to thank Project coordinator Ms. Patanjali, Assistant Professor, Department
of Computer Science and Engineering, BNMIT, Bengaluru for being the guiding force
towards successful completion of the project.
PRADEEP G
SNEHA M S
i
ABSTRACT
A great challenge in the biomedical engineering is the non-invasive assessment of the
physiological changes occurring inside the human body. Specifically, detecting the abnormalities
in the human eye is extremely difficult due to the various complexities associated with the process.
Retinal images captured by digital cameras can be used to identify the nature of the abnormalities
affecting the human eye. Conventional disease identification techniques from retinal images are
mostly dependent on manual intervention. Human observation is highly prone to error, the success
rate of these techniques is quite low. Diabetic Retinopathy is one such disease of retina which
occurs in people suffering from long standing diabetes. It is a multistage progressing disease
namely NDPR and PDR. Microaneurysms, haemorrhages and exudates are the abnormal features
commonly observed in the retinal image of a person affected by diabetic retinopathy. Image
processing techniques are used to pre-process the fundus image, which is followed by
segmentation of anomalies. Feature extraction is done and the detected features are used to classify
the different stages of diabetic retinopathy. The classification technique used is Random Forest,
and the accuracy obtained is 89.9 %.
ii
CONTENTS
TITLE PAGE NO
ACKNOWLEDGEMENT i
ABSTRACT ii
LIST OF FIGURES v
1. INTRODUCTION 1
1.1 Overview 1
1.2 Motivation 3
1.3 Problem Statement 4
2. LITERATURE SURVEY 5
2.1 Technical Papers 5
3. REQUIREMENT ANALYSIS 10
3.1 Feasibility study 10
3.2 System Requirements 12
3.3 Software Requirements 12
3.4 Hardware Requirements 12
iii
5. IMPLEMENTATION 25
5.1 Algorithms 25
5.1.1 Proposed algorithm 25
5.1.2 Otsu thresholding algorithm 26
5.1.3 Random Forest algorithm 27
5.2 Methods 28
5.2.1 Structuring Element 28
5.2.2 Morphological operations 28
6. TESTING 48
6.1 Introduction 48
6.2 Test cases 50
CONCLUSION 60
BIBLIOGRAPHY
iv
LIST OF FIGURES
v
Figure 5.2b Image after erosion with disk shaped SE 30
vi
Figure 7.6 Final segmented and classified results 58
vii
LIST OF TABLES
viii
CHAPTER 1
INTRODUCTION
1.1 OVERVIEW
Diabetic Retinopathy (DR) is a complication of Diabetes which affects the eye. It
is caused by damage to the blood vessels of the retina – the light-sensitive tissue at the back
of the eye. At first, diabetic retinopathy may cause no symptoms or only mild vision
problems. Eventually, it can cause blindness. It is one of the leading cause of blindness in
the world. Around 80 percent of population having diabetes for more than 10 or more years
has some stage of the disease. Almost two‑third of all Type 2 and almost all Type 1
diabetics are expected to develop DR over a period of time.
a b
Figure 1.1 Vision Affected by Diabetic Retinopathy. a. Normal
Vision b. Vision affected by Diabetic Retinopathy
Figure 1.1 shows the difference between normal vision and diabetic retinopathy affected
vision.
Other complications of PDR include detachment of the retina due to scar tissue
formation. In PDR, new blood vessels grow into the area of the eye that drains fluid from
the eye. This greatly raises the eye pressure, which damages the optic nerve. If left
untreated, PDR can cause severe vision loss and even blindness.
Fundus Image
It is the image of the internal structure of the eye captured using specialized fundus
cameras that consist of an intricate microscope attached to a flashed enabled camera. The
main structures that can be visualized on a fundus image are the central and peripheral
retina, optic disc and macula.
Retinal abnormalities
The common abnormalities found in the human retina are Microaneurysms, Haemorrhages
and Exudates as shown in Figure 1.2.
Blood Vessels
Exudates
Microaneurysm
Microaneurysms
A small swelling that forms on the ends of tiny blood vessels. These small swellings may
break and allow blood to leak into nearby tissue. The earliest visibility of diabetic
retinopathy is the microaneurysms.
Haemorrhages
Retinal hemorrhage is a disorder of the eye in which bleeding occurs into the retina. Retinal
hemorrhages that take place outside of the macula if left undetected for many years, and
may sometimes only be picked up when the eye is examined in detail by ophthalmoscopy
or fundus photography. Some retinal hemorrhages can cause severe impairment of vision.
Exudates
As Diabetic Retinopathy progresses, a fluid rich in protein and cellular elements that oozes
out of blood vessels due to inflammation and is deposited in nearby tissues. Exudates are
manifested as spatially random yellowish or whitish patches of varying sizes, shapes and
locations. These are the visible sign of DR and a major cause of visual loss in Non-
Proliferative forms of DR.
1.2 MOTIVATION
Diabetic Retinopathy has become one of the leading causes of blindness, but it can
be cured if diagnosed at an early stage, this requires regular eye examinations. Currently
the examinations are done by ophthalmologists or optometrists manually. People from low
income backgrounds and rural areas may not be able to afford these regular checkups.
Setting up mass screening centers with automated systems can eliminate unnecessary visits
to the ophthalmologist. This will also eliminate human intervention and thus reduce the
cost.
The automated system will grade the images on the level of severity and refer only
those patients who need medical attention to the Ophthalmologist. This will also relieve
the burden on the doctor who would otherwise have to go through a lot of images which
will come from the mass screening camps.
For a given collection of retinal fundus images (1…N), where N is greater than 100,
the purpose is:
(i) Precise classification of input images into normal, mild, moderate, severe.
(ii) To increase classification accuracy and analyze the efficiency of the proposed work
with the existing algorithms.
LITERATURE SURVEY
Segmentation Method: MAs look like an isolated pattern and are detached from the
vessels. Based on the shape, intensity level and size the features of Microaneurysms can
be extracted. As soon as image is pre-processed, the candidates Microaneurysms are
segmented through isolating them from veins. Blood vessels are huge in subject and are
related section, hence can recognize from MA situated on area. By the experimentation the
threshold value is chosen to remove blood vessels. The threshold value are eliminated if
the object has greater area. For the experimentation, two threshold values are chosen to
cast off noise objects having greater area and scale down than MAs. The consequential
image having objects which have the identical region and some of them are MAs. MAs are
identified from the noises which are in irregular shape. The noise having same area as
Microaneurysms are removed based on the major and minor axis. Based on perimeter and
circularity the Microaneurysms are detected. Based on the resultant image from the
previous segment the canny edge detection is performed. Each perimeter and object area is
manipulated and these outcomes are utilized to form a simple metric representing the
roundness of an entity.
ML Model: SVM training approach is utilized to compare coaching information to
discover a fine viable way to categories the DR images into their respective categories,
natural, slight, moderate and severe. It is robust procedure for the categorization of
information and deterioration. It appears for a hyper plane that may linearly separate
courses of objects. It looks for a hyper plane that can linearly separate classes of items.
This technique is utilized to recognize the different classes. It is used to differentiate the
various categories.
ML Model: Artificial Neural Networks are relatively crude electronic models based on the
neural structure of the brain. ANN is also called perceptron. Single layer perceptrons are
used to classify linear data, by introducing additional hidden layers non-linear data can be
classified. A multilayered perceptron is used with one input layer, one hidden layer and
one output layer is being used. According to the area of DR feature component and with
the help Artificial Neural Network (ANN) by training and defining weights to the previous
layer. Severity of the disease can be classified.
ML Model: The Random Forests algorithm is one of the best among classification
algorithms - able to classify large amounts of data with accuracy. Random Forests are an
ensemble learning method for classification and regression that construct a number of
decision trees at training time and outputting the class that is the mode of the classes output
by individual trees. The basic principle is that a group of “weak learners” can come together
to form a “strong learner”. Random Forests are a wonderful tool for making predictions
considering they do not over-fit because of the law of large numbers. Introducing the right
kind of randomness makes them accurate classifier.
REQUIREMENT ANALYSIS
A feasibility study is carried out to select the best system that meets performance
requirements. The main aim of the feasibility study activity is to determine whether it
would be financially and technically feasible to develop the product. The feasibility study
activity involves the analysis of the problem and collection of all relevant information
relating to the product such as the different data items which would be input to the system,
the processing required to be carried out on these data, the output data required to be
produced by the system as well as various constraints on the behavior of the system. The
key objective of the feasibility study is to weigh up three types of feasibility. They are:
a) Operational Feasibility
b) Technical Feasibility
c) Economic Feasibility
Operational Feasibility:
This is mainly related to human organizational and political aspects. The points to
be considered are:
What new skills will be required? Do the existing staff members have these
skills? If not, can they be trained in due course of time?
What changes will be brought with the system?
The proposed system will provide an automated system for the detection of the
disease.
The technicians will have to learn how to feed the images to the system.
Technical Feasibility:
Technical feasibility analysis makes a comparison between the level of technology
available and that is needed for the development of the project. The level of technology
consists of the factors like software tools, machine environment, and platform developed
and so on. It is also concerned with specifying equipment and software that will
successfully satisfy the user requirement. The technical needs of the system may vary
considerably.
Economic Feasibility:
This is the most important part of the project because the terms and conditions for
implementing the project have to be economically feasible. The risk of finance does not
exist as the existing hardware is sufficient and the software is free of cost. The system is
economically feasible.
Hardware Interface:
Describes the logical and physical characteristics of each interface between the
software product and the hardware components of the system. This may include the
supported device types, the nature of the data and control interactions between the software
and the hardware, communication protocols to be used.
Software Interface:
Describes the connections between this product and other specific software
components (name and version), including databases, operating systems, tools, libraries,
and integrated commercial components. Identify the data items or messages coming into
the system and going out and describe the purpose of each. Describe the services needed
and the nature of communications.
The objective of software project planning is to provide a frame work that enables
the reasonable estimation of resources, cost and schedule.
Software Scope
management and technical levels. The software scope means the actual operation that is
going to be carried out by the software and its plus points and limitations.
Resources
The second task of software planning is the estimation of resources required. Each
resource is specified with the following characteristic. Resource descriptions, details of
availability, when it is required, how long it is required.
Human Resource
Hardware Resource
Software Resource
All the existing systems are concentrating on segmenting the primary anomalies
responsible for initial stage of the disease. Their proposed method is also database
dependent and would work only for that specific database. There is no single approach or
method for segmenting all the anomalies. Building an optimal feature set is needed as this
disease is vision threatening and high benchmarking results need to be achieved. Many
classification techniques are proposed with different and novel approaches of pre-
processing. All these surveyed papers achieve an average of 85% accuracy which still need
to be improved. Researches throughout the world are trying to propose better classification
algorithms by building significant feature set. Limitations of the existing systems are
defects that arise due to DR compliances which cannot be extracted using single method.
Hence there is a need to developed system will overcome and able extract all features using
single platform.
The pre-processing part of both the existing and proposed system remain similar,
the difference comes in the segmentation and feature extraction stages. Existing system
only segmented anomalies like microaneurysms, the problem with this is this anomaly
occurs in the initial stage of the disease. Treatment cannot be given at this stage, hence this
is a major drawback. The proposed system overcomes this by segmenting haemorrhages
along with microaneurysms and also by considering a large feature set which includes the
area and count of the segmented anomalies. The feature set also includes textural features
like energy and correlation, and statistical features like mean and variance. This feature set
is then used to classify the image into the respective severity. Figure 4.1 shows the system
architecture of the proposed system.
Multiple-Anomalies
PRE- FEATURE
PROCESSING EXTRACTION
NORMAL
NPDR 1 CLASSIFICATION
NPDR 2
PDR
Applications of DFD
DFDs are a common way of modeling data flow for software development. For
example, a DFD for a word-processing program might show the way the software
processes the data that the user enters by pressing keys on the keyboard to produce the
letters on the screen.
Significance of DFD
DFDs are popular for software design because the diagram makes the flow of data
easy to understand and analyze. DFDs represent the functions a system performs
hierarchically, starting with the highest-level functions and moving through various layers
or levels of sub-functions. As a modeling technique, DFDs are useful for performing a
structured analysis of software problems, allowing developers to spot and pinpoint issues
in software development.
Every system is developed either to satisfy a need or to overcome the drawbacks of an
existing system.
Level 0
Level 1
1.1 1.2
Pre-Processing Segmentation
Fundus image
1.4 1.3
Grade
(0, 1, 2, 3) Classification Feature Extraction
Each fundus image fed into the system undergoes a series of processes as shown in Figure
4.3, they are:
Pre-processing:
Segmentation:
Segmentation-
• Identifies separate objects within an image Identifies separate objects within an image.
Feature Extraction:
image sizes are large and a reduced feature representation is required to quickly complete
tasks such as image matching, classification and retrieval.
Classification:
Image classification analyzes the numerical properties of various image features and
organizes data into categories. Classification algorithms typically employ two phases of
processing: training and testing. In the initial training phase, characteristic properties of
typical image features are isolated and, based on these, a unique description of each
classification category, i.e. training class, is created. In the subsequent testing phase, these
feature-space partitions are used to classify image features.
Level 1.1
RGB to green
channel
Re-size
Median Filtering
CLAHE
Enhanced Image
Preprocessing stage as shown in Figure 4.4 includes the following sub stages:
The color image is converted to a gray scale image and then the green channel is
extracted from it. Green channel is better than the red or blue channels because the red
channel image is too bright and the blue channel image is too dark. All the anomalies are
visible properly in the green channel image. A comparison of the images of the three
channels is shown in Figure 4.5.
Image resizing:
The green channel image is then resized to 560x720 Standard aspect ratio.
Median filtering:
CLAHE:
Level 1.2
Boundary detection
and removal
Microaneurysm
Haemorrhage
segmentation
Segmentation
Segmented Anomalies
The enhanced image obtained in the previous stage is then segmented. Segmentation
involves the following sub stages:
Mask Generation:
The mask is a binary image with the same resolution as that of fundus image whose
positive pixels correspond to the foreground area. It is important to separate the fundus
from its background so that the further processing is only performed for the fundus and not
interfered by pixels belonging to the background. In a fundus mask, pixels belonging to the
fundus are marked with ones and the background of the fundus with zeros. The fundus can
be easily separated from the background by converting the original fundus image from the
RGB to HSI color system where a separate channel is used to represent the intensity values
of the image. The intensity channel image is threshold by a low threshold value as the
background pixels are typically significantly darker than the fundus pixels. A median filter
is used to remove any noise from the created fundus mask and the edge pixels are removed
by morphological erosion. The final mask obtained is shown in Figure 4.7.
Blood vessel segmentation is a significant step in the red lesion detection. Since the
blood vessels and red lesions namely microaneurysms and haemorrhages are both red in
color the blood vessels need to be extracted out of the fundus image in order to effectively
detect the microaneurysms and haemorrhages. A Contrast limited adaptive histogram
equalization (CLAHE) is performed on the negative of green channel image. Top-hat filter
operation is applied using a flat disc shaped structuring element. Top-hat filtering is the
equivalent of subtracting the result of performing a morphological opening operation on
the input image from the input image itself. Suitable threshold is used to segment out the
blood vessels. This threshold is selected based on the a priori knowledge of the quality of
the image. The resultant image comprises of blood vessels along with haemorrhages,
micro-aneurisms and other stray structures. After removing structures that have area less
than a decided threshold the image containing only blood vessels is obtained.
The boundary of the fundus image gets separated in the process of segmentation
and has to be removed as it causes false detections. By using the generated mask the
boundary is removed.
The microaneurysms and dot haemorrhages are Structures with sharp edges and
circular in shape. Edge detection is done. The detected edges are then filled by applying
morphological closing operation by using a flat disc shaped structuring element. The image
obtained contains microaneurysms and Haemorrhages and blood vessels. Finally the blood
vessels are subtracted from the image to get the red lesions. Microaneurysms and
haemorrhages are further separated from each other depending on the difference in their
sizes. Structures having area smaller than a threshold are classified as candidate
microaneurysms. The candidate microaneurysms contain small fragments of blood vessels
along with microaneurysms. Since these fragments are thin linear structures these are
eliminated by applying a morphological opening operation with a disc shaped structuring
element. Structures bigger than microaneurysms are classified as candidate haemorrhages.
These also contains fragments of blood vessels which are eliminated by applying a
morphological opening operation.
Level 1.3
Once the anomalies are segmented the next stage is feature extraction. The different
features extracted are shown in Figure 4.8. The gray scale image of the input image is used
to extract textural features and statistical features. The textural features are obtained by
Green-Channel
GLCM Textural Features
To illustrate, the Figure 4.9 shows how graycomatrix calculates the first three
values in a GLCM. In the output GLCM, element (1,1) contains the value 1 because there
is only one instance in the input image where two horizontally adjacent pixels have the
values 1 and 1, respectively. glcm (1,2) contains the value 2 because there are two
instances where two horizontally adjacent pixels have the values 1 and 2. Element (1,3) in
the GLCM has the value 0 because there are no instances of two horizontally adjacent
pixels with the values 1 and 3. graycomatrix continues processing the input image,
scanning the image for other pixel pairs (i,j) and recording the sums in the corresponding
elements of the GLCM. The statistical features are calculated by applying the respective
formula. From the segmented anomalies the area and count are also calculated. The textural
features, statistical features and the area and count form the feature set. This is fed to the
classifier in the next stage.
Level 1.4
Depending on the objective and the characteristics of the image data, the classification
classes should be clearly defined.
The most significant features are selected from the huge feature set.
The proposed system uses supervised learning. Supervised learning is the machine learning
task of inferring a function from labeled training data. The training data consist of a set of
training examples. In supervised learning, each example is a pair consisting of an input
object and a desired output value. A supervised learning algorithm analyzes the training
data and produces an inferred function, which can be used for mapping new examples. An
optimal scenario will allow for the algorithm to correctly determine the class labels for
unseen instances.
Various classification techniques will be compared with the training data, so that an
appropriate decision rule is selected for subsequent classification.
Step 5: Classification
Depending up on the decision rule, the images are classified into different classes. These
classes represent the severity level of the disease and are represented by grades 0, 1, 2 and
3, where 0 is normal, 1 is mild, 2 is moderate and 3 is sever.
IMPLEMENTATION
5.1 ALGORITHMS
Step 7: Area and count of these anomalies are extracted as features. Statistical and
GLCM features are also extracted
Step 8: The feature set extracted is then provided to the Random forest classifier
for classification of severity levels.
Otsu thresholding divides image into Foreground and Background Pixels, thus
assigning Pixels nearer to the black level as 0 and white level as 1, converting image to
binary. The thresholding identifies minimum variance between these pixels to aptly
identify them.
Otsu's thresholding method involves iterating through all the possible threshold
values and calculating a measure of spread for the pixel levels each side of the threshold,
i.e. the pixels that either fall in foreground or background. The aim is to find the threshold
value where the sum of foreground and background spreads is at its minimum.
The Random Forests algorithm is one of the best among classification algorithms -
able to classify large amounts of data with accuracy. Random Forests are an ensemble
learning method (also thought of as a form of nearest neighbor predictor) for classification
and regression that construct a number of decision trees at training time and outputting the
class that is the mode of the classes output by individual trees. Random Forests are a
combination of tree predictors where each tree depends on the values of a random vector
sampled independently with the same distribution for all trees in the forest. The basic
principle is that a group of “weak learners” can come together to form a “strong learner”.
Random Forests are a wonderful tool for making predictions considering they do not over
fit because of the law of large numbers. Introducing the right kind of randomness makes
them accurate classifiers and regressors. Single decision trees often have high variance or
high bias. Random Forests attempts to mitigate the problems of high variance and high bias
by averaging to find a natural balance between the two extremes. Considering that Random
Forests have few parameters to tune and can be used simply with default parameter settings,
they are a simple tool to use without having a model or to produce a reasonable model fast
and efficiently.
Random Forests grows many classification trees. Each tree is grown as follows:
Input: Feature set
Output: Grade of severity
Step 1: If the number of cases in the training set is N, sample N cases at random -
but with replacement, from the original data. This sample will be the
training set for growing the tree.
Step 2: If there are M input variables, a number mM is specified such that at each
node, m variables are selected at random out of the M and the best split on
these m is used to split the node. The value of m is held.
Step 4: Each tree is grown to the largest extent possible. There is no pruning.
5.2 METHODS
Dilation and erosion are basic morphological processing operations. They are
defined in terms of more elementary set operations, but are employed as the basic elements
of many algorithms. Both dilation and erosion are produced by the interaction of
structuring element with a set of pixels of interest in the image.
Dilation adds pixels to the boundaries of objects in an image, while erosion removes
pixels on object boundaries. The number of pixels added or removed from the objects in
an image depends on the size and shape of the structuring element used to process the
image. In the morphological dilation and erosion operations, the state of any given pixel in
the output image is determined by applying a rule to the corresponding pixel and its
B.E/Dept. of CSE/ BNMIT Page 28 2016-2017
DETECTION AND MULTISTAGE CLASSIFICATION OF DIABETIC RETINOPATHY
neighbors in the input image. The rule used to process the pixels defines the operation as a
dilation or an erosion. Table 5.1 shows the operations and the rules.
Operation Rule
Dilation The value of the output pixel is the maximum value of all the pixels in
the input pixel's neighborhood. In a binary image, if any of the pixels is
set to the value 1, the output pixel is set to 1.
Erosion The value of the output pixel is the minimum value of all the pixels in
the input pixel's neighborhood. In a binary image, if any of the pixels is
set to 0, the output pixel is set to 0.
DILATION
Figure 5.1a: Original image Figure 5.1b: Image after dilation with
disk shaped SE
EROSION
Figure 5.2a: Original image Figure 5.2b: Image after erosion with
disk shaped SE
Dilation and erosion are often used in combination to implement image processing
operations. Erosion followed by dilation is called an open operation. Opening of an image
smoothes the contour of an object, breaks narrow isthmuses (“bridges”) and eliminates thin
protrusions. Dilation followed by erosion is called a close operation. Closing of an image
smoothes section of contours, fuses narrow breaks and long thin gulfs, eliminates small
holes in contours and fills gaps in contours.
Figure 5.3a: Opening operation with Figure 5.3b: Closing operation with
disk shaped image disk shaped SE image
In an image, an edge is a curve that follows a path of rapid change in image intensity.
Edges are often associated with the boundaries of objects in a scene. Edge detection refers
to the process of identifying and locating sharp discontinuities in an image. It is possible to
use edges to measure the size of objects in an image, isolate particular objects from their
background, and to recognize or classify objects.
The Canny method finds edges by looking for local maxima of the gradient of I. The
gradient is calculated using the derivative of a Gaussian filter. The method uses two
thresholds, to detect strong and weak edges, and includes the weak edges in the output only
if they are connected to strong edges. This method is therefore less likely than the others to
be fooled by noise, and more likely to detect true weak edges. The Canny method performs
better than the others due to the fact that it uses two thresholds to detect strong and weak
edges and for this reason, Canny algorithm is chosen for edge detection.
Figure 5.4a and b show original image and Canny edge detection methods
respectively. It is apparent that by using Canny edge detection method, the weak fine blood
vessels can be detected.
Figure 5.4a: Original image Figure 5.4b: Canny edge detected image
Median filtering is a nonlinear operation often used in image processing to reduce "salt
and pepper" noise. A median filter is more effective than convolution when the goal is to
simultaneously reduce noise and preserve edges. Median of a set is the middle value when
values are sorted. For even number of values, the median is the mean of the middle of two.
Figure 5.5a shows an illustration of a 3 x 3 median filter for a set of sorted values to obtain
the median value.
55 70 57
55 57 62 63 65 66 68 70 260 65
68 260 63
66 65 62
This method of obtaining the median value means that very large or very small values
(noisy values) will be replaced by the value closer to its surroundings. Figure 5.5b shows
the difference before and after applying median filtering. The “salt and pepper” noise in the
original image have been clearly reduced after applying the median filtering.
Figure 5.5b: Original image (left) and image after median filtering (right)
Texture Analysis
Mean, standard deviation, third moment and entropy are statistical type. Mean,
standard deviation and third moment are concern with properties of individual pixels. Mean
N 1 N 1
is defined as: Mean = µ1 = iPi, j and standard deviation is defined as: SD = σ1 =
i 0 j 0
N 1 N 1
Pi, j i
2
1 . Third moment is a measure of the skewness of the histogram and is
i 0 j 0
measures randomness in an image texture. An image that is perfectly flat will have entropy
of zero. Consequently, they can be compressed to a relatively small size. On the other hand,
high entropy images such as an image of heavily cratered areas on the moon have a great
deal of contrast from one pixel to the next and consequently cannot be compressed as much
as low entropy images. Entropy is defined as: − ∑ 𝑃 log 2 𝑃. The texture features used in
this project are mean, standard deviation, third moment and entropy.
The Gray Level Co-occurrence Matrix (GLCM) method is a way of extracting second
order statistical texture features. A GLCM is a matrix where the number of rows and
columns is equal to the number of gray levels, G, in the image. The matrix element P (i, j |
∆x, ∆y) is the relative frequency with which two pixels, separated by a pixel distance (∆x,
∆y), occur within a given neighborhood, one with intensity ‘i’ and the other with intensity
‘j’. The matrix element P (i, j | d, ө) contains the second order statistical probability values
for changes between gray levels ‘i’ and ‘j’ at a particular displacement distance d and at a
particular angle (ө). Using a large number of intensity levels G implies storing a lot of
temporary data, i.e. a G × G matrix for each combination of (∆x, ∆y) or (d, ө). Due to their
large dimensionality, the GLCM’s are very sensitive to the size of the texture samples on
which they are estimated. Thus, the number of gray levels is often reduced. GLCM matrix
formulation can be explained with the example illustrated in Figure 5.6 for four different
gray levels. Here one pixel offset is used (a reference pixel and its immediate neighbor). If
the window is large enough, using a larger offset is possible. The top left cell will be filled
with the number of times the combination 0,0 occurs, i.e. how many time within the image
area a pixel with grey level 0 (neighbor pixel) falls to the right of another pixel with grey
level 0(reference pixel).
Pop up function
describing all the
2 Help.m
steps to use the
software
Main driver
program which
main1(sBmp,h) contains modules
3 of segmentation
and feature
extraction
Segments the
MA_main(x_1) micro-aneurysm
7 and returns the
area and count.
Segments the
binarythining_HA(x_1) haemorrhages
8 and returns the
area and count of
these anomalies.
Applies CLAHE
adapthisteq(MAHA,'Atribute',value,'Atribute',value) and returns the
9 contrast adjusted
image
Returns the
im2bw(med_J,thresholdvalue) binary equivalent
10 of the grayscale
image.
Segments the
CoyeFil(x) vessel structure
11 from the fundus
image.
Subtracts two
imsubtract(JF, J) binary images
15 and returns the
difference image.
Performs otsu
graythresh(Z) algorithm and
16 returns a
threshold value.
Performs the
imcomplement(BW2) compliment of
17 given binary
image
Performs the
wekaClassification(feature_train, class_train, classification of
feature_test, class_test, featName, classifier) the given test data
19
against the
training data.
Loads the
attribute related
20 Loadarrf()
file from system
for classification.
Table 5.2 describes the functions defined in the system. The MATLAB code for some of
the functions are:
CoyeFil(x)
JF = imfilter(J, h);
Z = imsubtract(JF, J);
%% Threshold
level=graythresh(Z);
%% Convert to Binary
BW = im2bw(Z, level);
%% Overlay
BW2 = imcomplement(BW2);
binarythining_HA(x_1)
gray=rgb2gray(x);
%Contrast adjustment
Ie3=adapthisteq(g,'numTiles',[8 8],'nBins',128);
J = imadjust(Ie3,stretchlim(Ie3),[]);
g_fill=imfill(g,'holes');
MAHA=imsubtract(g_fill,g);
med_x=medfilt2(MAHA,[3,3]);
BW=im2bw(med_x,graythresh(med_x));
h_op=imopen(BW,strel('disk',2));
%vessels
vv=~CoyeFil(x);
vessel_d=imdilate(vv,strel('disk',5));
vessel_e=imerode(vessel_d,strel('disk',3));
FF1=imsubtract(h_op,vessel_e);
ff1=im2bw(FF1);
%eliminate fovea
labeledImage = bwlabel(ff1,8);
blobMeasurements = regionprops(labeledImage,ff1, 'all');
allBlobAreas = [blobMeasurements.Area];
not_allowableareas=allBlobAreas>=max(allBlobAreas);
non_keeperIndexes2 = find(not_allowableareas);
non_keeperImage2= ismember(labeledImage, non_keeperIndexes2);
maskedImage = ff1;
maskedImage(non_keeperImage2)=0;
maskedImage=bwareaopen(maskedImage,20);
%overlay
HA=maskedImage;
labeledImage = bwlabel(HA,8);
blobMeasurements = regionprops(labeledImage,HA, 'basic');
numberHA = size(blobMeasurements, 1);
allBlobAreas = [blobMeasurements.Area];
areaHA=sum(allBlobAreas);
end
MA_main(x_1)
%guasian filter
hsize = [3 3];
sigma =2;
h = fspecial('gaussian', hsize, sigma);
ft_g = imfilter(g,h);
g_fill=imfill(ft_g,'holes');
MAHA=imsubtract(g_fill,ft_g);
J=adapthisteq(MAHA,'numTiles',[8 8],'nBins',128);
med_J=medfilt2(J,[3,3]);
MA=im2bw(med_J,graythresh(med_J));
vv=~CoyeFil(x);
%MASK generation
J=adapthisteq(g,'numTiles',[8 8],'nBins',128);
J=adapthisteq(J,'numTiles',[8 8],'nBins',128);
se=strel('disk',15);
eyeMask= im2bw(J,graythresh(g));
eyeMask= imfill(eyeMask,'holes');
eyeMask=bwareaopen(eyeMask,100);
eyemask=imdilate(eyeMask,se);
eyemask=imerode(eyemask,se);
vv(~eyeMask)=0;
vv(~imerode(eyemask,strel('disk',15)))=0;
vvd=imdilate(vv,strel('disk',5));
vve=imerode(vvd,strel('disk',3));
MAF=imsubtract(MA,vve);
MAF=im2bw(MAF);
MAF=imfill(MAF,'holes');
MAF=xor(bwareaopen(MAF,3),bwareaopen(MAF,9));
labeledImage = bwlabel(MAF,8);
blobMeasurements = regionprops(labeledImage,MAF, 'all');
numberMA = size(blobMeasurements, 1);
allBlobAreas = [blobMeasurements.Area];
areaMA=sum(allBlobAreas);
GLCM_Features1(x,0)
format long e
if (pairs == 1)
newn = 1;
for nglcm = 1:2:size(glcmin,3)
glcm(:,:,newn) = glcmin(:,:,nglcm) + glcmin(:,:,nglcm+1);
newn = newn + 1;
end
elseif (pairs == 0)
glcm = glcmin;
end
size_glcm_1 = size(glcm,1);
size_glcm_2 = size(glcm,2);
size_glcm_3 = size(glcm,3);
% checked
out.autoc = zeros(1,size_glcm_3); % Autocorrelation: [2]
out.contr = zeros(1,size_glcm_3); % Contrast: matlab/[1,2]
out.corrm = zeros(1,size_glcm_3); % Correlation: matlab
out.cprom = zeros(1,size_glcm_3); % Cluster Prominence: [2]
out.cshad = zeros(1,size_glcm_3); % Cluster Shade: [2]
out.dissi = zeros(1,size_glcm_3); % Dissimilarity: [2]
out.energ = zeros(1,size_glcm_3); % Energy: matlab / [1,2]
out.entro = zeros(1,size_glcm_3); % Entropy: [2]
out.homom = zeros(1,size_glcm_3); % Homogeneity: matlab
out.maxpr = zeros(1,size_glcm_3); % Maximum probability: [2]
glcm_sum = zeros(size_glcm_3,1);
glcm_mean = zeros(size_glcm_3,1);
glcm_var = zeros(size_glcm_3,1);
u_x = zeros(size_glcm_3,1);
u_y = zeros(size_glcm_3,1);
s_x = zeros(size_glcm_3,1);
s_y = zeros(size_glcm_3,1);
glcm_sum(k) = sum(sum(glcm(:,:,k)));
glcm(:,:,k) = glcm(:,:,k)./glcm_sum(k); % Normalize each glcm
glcm_mean(k) = mean2(glcm(:,:,k)); % compute mean after norm
glcm_var(k) = (std2(glcm(:,:,k)))^2;
for i = 1:size_glcm_1
for j = 1:size_glcm_2
end
out.maxpr(k) = max(max(glcm(:,:,k)));
end
for k = 1:size_glcm_3
for i = 1:size_glcm_1
for j = 1:size_glcm_2
p_x(i,k) = p_x(i,k) + glcm(i,j,k);
p_y(i,k) = p_y(i,k) + glcm(j,i,k); % taking i for j and j for i
if (ismember((i + j),[2:2*size_glcm_1]))
p_xplusy((i+j)-1,k) = p_xplusy((i+j)-1,k) + glcm(i,j,k);
end
if (ismember(abs(i-j),[0:(size_glcm_1-1)]))
p_xminusy((abs(i-j))+1,k) = p_xminusy((abs(i-j))+1,k) +...
glcm(i,j,k);
end
end
end
end
for k = 1:(size_glcm_3)
for i = 1:(2*(size_glcm_1)-1)
out.savgh(k) = out.savgh(k) + (i+1)*p_xplusy(i,k);
out.senth(k) = out.senth(k) - (p_xplusy(i,k)*log(p_xplusy(i,k) + eps));
end
end
% compute sum variance with the help of sum entropy
for k = 1:(size_glcm_3)
for i = 1:(2*(size_glcm_1)-1)
out.svarh(k) = out.svarh(k) + (((i+1) - out.senth(k))^2)*p_xplusy(i,k);
end
end
% compute difference variance, difference entropy,
for k = 1:size_glcm_3
for i = 0:(size_glcm_1-1)
out.denth(k) = out.denth(k) - (p_xminusy(i+1,k)*log(p_xminusy(i+1,k) +
eps));
out.dvarh(k) = out.dvarh(k) + (i^2)*p_xminusy(i+1,k);
end
end
for j = 1:size_glcm_2
hxy1(k) = hxy1(k) - (glcm(i,j,k)*log(p_x(i,k)*p_y(j,k) + eps));
hxy2(k) = hxy2(k) - (p_x(i,k)*p_y(j,k)*log(p_x(i,k)*p_y(j,k) + eps));
end
hx(k) = hx(k) - (p_x(i,k)*log(p_x(i,k) + eps));
hy(k) = hy(k) - (p_y(i,k)*log(p_y(i,k) + eps));
end
out.inf1h(k) = ( hxy(k) - hxy1(k) ) / ( max([hx(k),hy(k)]) );
out.inf2h(k) = ( 1 - exp( -2*( hxy2(k) - hxy(k) ) ) )^0.5;
end
corm = zeros(size_glcm_3,1);
corp = zeros(size_glcm_3,1);
for k = 1:size_glcm_3
for i = 1:size_glcm_1
for j = 1:size_glcm_2
s_x(k) = s_x(k) + (((i) - u_x(k))^2)*glcm(i,j,k);
s_y(k) = s_y(k) + (((j) - u_y(k))^2)*glcm(i,j,k);
corp(k) = corp(k) + ((i)*(j)*glcm(i,j,k));
corm(k) = corm(k) + (((i) - u_x(k))*((j) - u_y(k))*glcm(i,j,k));
out.cprom(k) = out.cprom(k) + (((i + j - u_x(k) - u_y(k))^4)*...
glcm(i,j,k));
out.cshad(k) = out.cshad(k) + (((i + j - u_x(k) - u_y(k))^3)*...
glcm(i,j,k));
end
end
% root is required as done below:
s_x(k) = s_x(k) ^ 0.5;
s_y(k) = s_y(k) ^ 0.5;
out.autoc(k) = corp(k);
out.corrm(k) = corm(k) / (s_x(k)*s_y(k));
end
Feature_Extraction1(I,green_channel)
%calculate mean
mean = 0;
out2.mean = mean2(x);
B.E/Dept. of CSE/ BNMIT Page 44 2016-2017
DETECTION AND MULTISTAGE CLASSIFICATION OF DIABETIC RETINOPATHY
%calculate entropy
GreenC=g;
Green_his_X1 = adapthisteq(GreenC);
Green_his_X2 = adapthisteq(Green_his_X1);
out2.entrop = entropy(Green_his_X2);
end
Performs the classification of the given test data against the training data.
% Then, we forcefully add the classes that is not in the test class
% to the testing data.
tmp_idx = 1;
uTrainClasses = unique(classTrain);
for iclass = 1:length(uTrainClasses)
if (sum(ismember(uTestClasses, uTrainClasses{iclass})) == 0)
featTest = vertcat(featTest, featTest(end,:));
classTest = vertcat(classTest, uTrainClasses{iclass});
tmp_idx = tmp_idx + 1;
end
end
numExtraClass = tmp_idx - 1;
end
import weka.classifiers.functions.supportVector.Puk.*;
%create an java object
trainModel = weka.classifiers.functions.SMO();
%defining parameters
trainModel.setC(1.0);
trainModel.setEpsilon(1.0E-12);
trainModel.setNumFolds(-1);
trainModel.setRandomSeed(1);
trainModel.setToleranceParameter(0.001);
trainKernel = weka.classifiers.functions.supportVector.Puk();
trainKernel.buildKernel(ft_train_weka);
trainModel.setKernel(trainKernel);
%train the classifier
trainModel.buildClassifier(ft_train_weka);
elseif(classifier == 4)
import weka.classifiers.functions.Logistic.*;
%create an java object
trainModel = weka.classifiers.functions.Logistic();
%defining parameters
trainModel.setMaxIts(-1); %Set the value of MaxIts.
trainModel.setRidge(1.0E-8);
%train the classifier
trainModel.buildClassifier(ft_train_weka);
end
%% Making Predictions
actual = cell(ft_test_weka.numInstances()-numExtraClass, 1); %actual labels
predicted = cell(ft_test_weka.numInstances()-numExtraClass, 1); %predicted
labels
probDistr = zeros(ft_test_weka.numInstances()-numExtraClass,
ft_test_weka.numClasses()); %probability distribution of the predictions
for z = 1:ft_test_weka.numInstances()-numExtraClass
actual{z,1} = ft_test_weka.instance(z-
1).classAttribute.value(ft_test_weka.instance(z-1).classValue()).char();%
Modified by GM
predicted{z,1} = ft_test_weka.instance(z-
1).classAttribute.value(trainModel.classifyInstance(ft_test_weka.instance(z-
1))).char();% Modified by GM
probDistr(z,:) = (trainModel.distributionForInstance(ft_test_weka.instance(z-
1)))';
end
display('Classification Completed!');
TESTING
6.1 INTRODUCTION
As the number of possible tests for even simple software components is practically
infinite, all software testing uses some strategy to select tests that are feasible for the
available time and resources. As a result, software testing typically (but not exclusively)
attempts to execute a program or application with the intent of finding software
bugs (errors or other defects). The job of testing is an iterative process as when one bug is
fixed, it can illuminate other, deeper bugs, or can even create new ones.
Software testing can provide objective, independent information about the quality of
software and risk of its failure. Software testing can be conducted as soon as executable
software (even if partially complete) exists. The overall approach to software
development often determines when and how testing is conducted. For example, in a
phased process, most testing occurs after system requirements have been defined and then
implemented in testable programs.
Types of testing:
Black box testing – Internal system design is not considered in this type of testing. Tests
are based on requirements and functionality.
White box testing – This testing is based on knowledge of the internal logic of an
application’s code. Also known as Glass box Testing. Internal software and code working
should be known for this type of testing. Tests are based on coverage of code statements,
branches, paths, conditions.
Grey box testing – Grey-box testing (American spelling: gray-box testing) involves
having knowledge of internal data structures and algorithms for purposes of designing tests,
while executing those tests at the user, or black-box level. The tester is not required to have
full access to the software's source code. Grey-box testing may also include reverse
engineering to determine, for instance, boundary values or error messages.
Incremental integration testing – Bottom up approach for testing i.e. continuous testing
of an application as new functionality is added; Application functionality and modules
should be independent enough to test separately done by programmers or by testers.
Functional testing – This type of testing ignores the internal parts and focus on the output
is as per requirement or not. Black-box type testing geared to functional requirements of
an application.
System testing – Entire system is tested as per the requirements. Black-box type testing
that is based on overall requirements specifications, covers all combined parts of a system.
Case 1
Remarks Pass
Case 2
Remarks Pass
Case 3
Remarks Fail
Compressed images of .jpg format will introduce many compression artifacts to the image.
While the anomalies are being segmented the introduced artifacts will also get segmented
with them, the image will be classified into a wrong grade. Figure 6.3 shows the output of
such a case.
Case 4
Remarks Fail
Case 5
Remarks Pass
7.1 SNAPSHOTS
The Figure 7.1 shows the first screen that appears upon loading the GUI. It has
buttons Help, Load Image, Grade and Reset.
Load image button directs the user to the database of fundus images from where
the user can choose an image to grade.
Grade button grades the choosen image and displays the severity level.
Reset button resets all the fields to their default value.
Help button opens a pop up which has a guide for the user.
It also has a status bar which guides the user to the next step.
The Figure 7.2 shows the screen which appears when the Load image button is
pressed on the main screen of the GUI. The image chosen from this screen will be displayed
on the main screen.
The Figure 7.3 shows the main screen once the fundus image chosen from the
database has been loaded.
The Figure 7.4 shows the error message that appeas if a fundus image is not
choosen.
Figure 7.5 shows the progress bar that appears once the grade button has been
pressed. It shows what features are being segmented.
Figure 7.6 shows the final output of grading. The GUI displays the intensity
adjusted image, segmented blood vessels and the Haemorrhages. It also displays the
Microaneurysm count and area. The severity level is shown along with a suggestion to the
patient.
Figure 7.7 shows the pop up that appears once help button is clicked.
7.2 RESULTS
The fast and efficient early detection of Diabetic Retinopathy is only possible if
there is an effective method for segmenting the diabetic features in the fundus image. The
proposed system presents a fast, effective and robust way of detecting diabetic features in
the fundus images which can be used for classification of the images based on the severity
of the disease. The retinal images are subjected to gray scale conversion, preprocessing and
feature extraction steps. The extracted features are fed to a Random Forest classifier which
will classify the images into different severity levels. Thus this Random forest technique
has given a successful DR screening method which helps to detect the disease in multiple
stages.
[1] Sri, R. Manjula, M. Raghupathy Reddy, and K. M. M. Rao. "Image Processing for
Identifying Different Stages of Diabetic Retinopathy." International Journal on
Recent Trends in Engineering & Technology 11.1 (2014): 83.
[2] Soumya Sree, A.Rafega Beham. “BP and SVM based Diagnosis of Diabetic
Retinopathy”. International Journal of Innovative Research in Computer and
Communication Engineering Vol. 3, Issue 6, June 2015.
[9] Gary G. Yen, and Wen Fung Leong, “A Sorting System for Hierarchical Grading
of Diabetic Fundus Images: A Preliminary Study”, IEEE Transactions on
Information Technology in Biomedicine, Vol. 12, No. 1, pp 118-130, January 200.
[11] Bernhard M. Ege et al. ―Screening for diabetic retinopathy using computer based
image analysis and statistical classification, in Computer Methods and Programs in
Biomedicine,Vol. 62 (2000) ,pp.165–175.
[12] Wong Li Yun, Rajendra Acharya U, Y V. Venkatesh, Caroline Chee, Lim Choo
Min, E.Y.K.Ng. Identification of Different Stages Of Diabetic Retinopathy Using
Retinal Optical Images. Information Sciences Vol. 178, PP 106–121, 2008.