Peering into the Eyes of Health: Detecting Diabetic Retinopathy with MATLAB and Support Vector Machines
Introduction:
Hello fellow tech enthusiasts! Krishanu Dev Sarma here, and today I'm thrilled to share my journey through the intricate realm of healthcare technology. Join me as we unravel the mysteries of Diabetic Retinopathy using the powerful duo of MATLAB and Support Vector Machines (SVM). It's not just code; it's a quest for better health outcomes. So, let's dive in!
The Canvas:
Picture this—a canvas filled with fundus images capturing the essence of our eyes. MATLAB, my palette of choice, holds the promise of turning these images into a diagnostic masterpiece. Why MATLAB? Well, its matrix-based language aligns seamlessly with image processing, making it an artist's dream.
Setting Up the Stage with MATLAB:
Let's kick things off by setting up our workspace. In MATLAB, loading and visualizing images is a breeze.
%Accessing the Diabetic Retinopathy Fundus Image Dataset
imdsT = imageDatastore('G:\images\ddb1_fundusimages','IncludeSubfolders',true,'FileExtensions',[".png"],'LabelSource', 'foldernames')
T = countEachLabel(imdsT);
Preprocessing:
Before unleashing the power of SVM, we need to prepare our data. Image preprocessing is the unsung hero—cleaning, resizing, and enhancing features for a clearer diagnosis.
% Preprocessing the images
for Idx = 1:89
%**********************Preprocessing****************************
%Storing the Image in a variable
im = readimage(imdsT,Idx);
%Green Channel extraction
green = im(:,:,2);
%Applying CLAHE(Contrast Limited Adaptive Histogram)
adhist=adapthisteq(green,'clipLimit',0.02,'Distribution','uniform');
end;
Extracting our Features:
The data to our model cannot be raw, for machine learning models like to play with numbers. So, we have to extract the numbers using various features extraction methods, like Local Binary Patterns(LBP) and Gray Level Co-occurrence Matrix(GLCM).
% Extraction of GLCM features
glcms = graycomatrix(adhist);
R = sum(glcms,'all');
normalized_glcms = glcms./R;
homogeneity = 0;
contrast = 0;
energy = 0; correlation = 0;
mean_glcms = 0;
var_glcms = 0;
for i = 1:8
for j = 1 : 8
homogeneity = homogeneity + (normalized_glcms(i,j)/(1 + (i-j)^2));
contrast = contrast + (normalized_glcms(i,j)*(i-j)^2);
energy = energy + normalized_glcms(i,j)^2;
mean_glcms = mean_glcms + i*normalized_glcms(i,j);
end
end
for i = 1:8
for j = 1:8
var_glcms = var_glcms + (normalized_glcms(i,j)*(i-mean_glcms)^2);
end
end
for i = 1:8
for j = 1:8
correlation = correlation + ((normalized_glcms(i,j)*(i-mean_glcms)*(j - mean_glcms))/var_glcms);
end
end
feature = [homogeneity,correlation,contrast,energy]
% Extraction of LBP features
img=imresize(adhist,[256 256]);
%figure;
%imshow(img)
sum=0;g=0;
for i= 2:255
for j=2:255
sum=0;
if(img(i-1,j-1)<img(i,j))
g=0;
else
g=1;
end;
sum = sum + g*(2^0);
if(img(i-1,j)<img(i,j))
g=0;
else
g=1;
end;
sum = sum + g*(2^1);
if(img(i-1,j+1)<img(i,j))
g=0;
else
g=1;
end;
sum = sum + g*(2^2);
if(img(i,j+1)<img(i,j))
g=0;
else
g=1;
end;
sum = sum + g*(2^3);
if(img(i+1,j+1)<img(i,j))
g=0;
else
g=1;
end;
sum = sum + g*(2^4);
if(img(i+1,j)<img(i,j))
g=0;
else
g=1;
end;
sum = sum + g*(2^5);
if(img(i+1,j-1)<img(i,j))
g=0;
else
g=1;
sum = sum + g*(2^6);
end;
if(img(i,j-1)<img(i,j))
g=0;
else
g=1;
sum = sum + g*(2^7);
end;
img(i,j)=sum;
end;
end;
img(1, :) = []; % Delete rows.
img(255, :) = []; % Delete rows.
img(:, 1) = []; % Delete columns.
img(:, 255) = []; % Delete columns.
h=histeq(img);
h1=imhist(img);
%imshow(img);
%figure;
%plot(h1);
h2=h1'./256;
%Storing the Histograms of the Images in an Array
ArrayOfLBPImages{Idx}= h2;
SVM Unleashed:
Now, let's introduce the star of our show—the Support Vector Machine. In MATLAB, it's like having a reliable companion for classification tasks.
% Splitting the dataset
[train_data, test_data, train_labels, test_labels] = split_data(images, labels);
% Training the SVM
svm_model = fitcsvm(train_data, train_labels, 'KernelFunction', 'linear');
Pros and Cons of using MATLAB for ML:
Pros:
Image Processing Prowess: MATLAB's image processing toolbox is a treasure trove for healthcare applications.
Rich Visualization: Visualizing results is crucial. MATLAB's plotting capabilities provide insights at a glance.
Comprehensive Toolbox: From statistical analysis to deep learning, MATLAB covers a broad spectrum of tools.
Cons:
Cost Factor: MATLAB isn't free, and for some, the licensing cost can be a drawback.
Learning Curve: For those new to the language, MATLAB's syntax might pose a slight learning curve.
Words of Wisdom for Fellow Coders:
Master the Basics: MATLAB's power lies in its matrix operations. A solid understanding of linear algebra pays dividends.
Explore Toolboxes: MATLAB offers specialized toolboxes. Explore them to streamline your workflow.
Code Efficiency: Optimize your code for speed. MATLAB's efficiency shines when code is well-optimized.
Conclusion:
As I stand at the crossroads of healthcare and technology, MATLAB and SVM by my side, I can't help but marvel at the possibilities. Detecting Diabetic Retinopathy isn't just about algorithms; it's about making a positive impact on lives.
So, fellow coders and healthcare enthusiasts, let's continue to harness the power of technology for a healthier tomorrow. MATLAB is not just a tool; it's a partner in our pursuit of a brighter, clearer vision. Happy coding! 🚀💻👁️
Note: This blog provides a high-level overview; specific technical details, code snippets, and results would be integrated into a comprehensive blog post for publication.