File Exchange

image thumbnail

A Novel Retinal Blood Vessel Segmentation Algorithm for Fundus Images

version (10.6 MB) by Tyler Coye
The algorithm presented here segments retinal blood vessels with a high degree of accuracy.


Updated 15 Mar 2018

View License

This Script is Copyrighted by Tyler L. Coye (2015). Doctoral Candidate in Medicine, Temple University .
This algorithm is the result of many hours of work and problem solving. If you use this algorithm in your work, please copy the following citation:
* * * * *
Coye, Tyler (2015). A Novel Retinal Blood Vessel Segmentation Algorithm for Fundus Images (, MATLAB Central File Exchange.[Month and Day Retrieved], [Year Retrieved].
* * * * *
This Script segments retinal blood vessels in a fundus image, which is a difficult challenge to overcome.
Included in the .zip file are the main file, labeled 'CoyeFilter.m' as well as the overlay algorithm and Isodata algorithm. The 'CoyeFilter.m' utilizes both overlay and isodata methods.
In the .zip is a sample set of fundus images for you to test the Script on.

Instead of using the green channel, as many papers have commonly done in the past, I converted the RGB to Gray using PCA through a process I developed in my algorithm " Hybrid Lesion Detection Algorithm Using Principle Component Analysis."

* * * * * *

My method for segmenting blood vessels in the retina has been cited in the following papers and presentations:

Bandara, A. M. R. R., and P. W. G. R. M. P. B. Giragama. "A retinal image enhancement technique for blood vessel segmentation algorithm." Industrial and Information Systems (ICIIS), 2017 IEEE International Conference on. IEEE, 2017.

Buglione, John. Use of Compton Backscatter X-ray Imaging in Agriculture. ME thesis. University of Pennsylvania, Philadelphia, 2016.

Furtado, Pedro, et al. "Segmentation of Eye Fundus Images by density clustering in diabetic retinopathy." Biomedical & Health Informatics (BHI), 2017 IEEE EMBS International Conference on. IEEE, 2017.

Gu, Lin, et al. "Semi-supervised learning for biomedical image segmentation via forest oriented super pixels (voxels)." International Conference on Medical Image Computing and Computer-Assisted Intervention. Springer, Cham, 2017.

Intaramanee, Tanin, et al. "Optic disc detection via blood vessels origin using Morphological end point." Advanced Informatics: Concepts, Theory And Application (ICAICTA), 2016 International Conference On. IEEE, 2016.

Saponaro, P., et al. "Three-Dimensional Segmentation of Vesicular Networks of Fungal Hyphae in Macroscopic Microscopy Image Stacks." arXiv preprint arXiv:1704.02356 (2017).

Saranya, M., and A. Grace Selvarani. "Fundus Image Screening for Diabetic Retinopathy." Indian Journal of Science and Technology 9.25 (2016).


* * * * * *

The Script for the Segmentation algorithm is below:

%% Computer Assisted Retinal Blood Vessel Segmentation Algorithm
% Developed and Copyrighted by Tyler L. Coye (2015)
% Read Image
I = imread('13_right.jpeg')

% Resize image for easier computation
B = imresize(I, [584 565])

% Read image
im = im2double(B);

% Convert RGB to Gray via PCA
lab = rgb2lab(im);
f = 0;
wlab = reshape(bsxfun(@times,cat(3,1-f,f/2,f/2),lab),[],3);
[C,S] = pca(wlab);
S = reshape(S,size(lab));
S = S(:,:,1);
gray = (S-min(S(:)))./(max(S(:))-min(S(:)));

%% Contrast Enhancment of gray image using CLAHE
J = adapthisteq(gray,'numTiles',[8 8],'nBins',128);

%% Background Exclusion
% Apply Average Filter

h = fspecial('average', [9 9]);
JF = imfilter(J, h);
figure, imshow(JF)

% Take the difference between the gray image and Average Filter
Z = imsubtract(JF, J);
figure, imshow(Z)

%% Threshold using the IsoData Method
level=isodata(Z) % this is our threshold level

%% Convert to Binary
BW = im2bw(Z, level-.008)

%% Remove small pixels
BW2 = bwareaopen(BW, 100)

%% Overlay
BW2 = imcomplement(BW2)
out = imoverlay(B, BW2, [0 0 0])
figure, imshow(out)

Comments and Ratings (41)

Pavel Osipov

it is a really good code.
thank you for your well done.
i wanna know how cam show final result in rgb form??

Avijit Hazra

Hi Tyler, can you run the code in one of my images? I am getting error while running in my data image

Nabin Paudel

Thanks Tyler. So, how do I read the data. The vessel width in micron etc?

clover Zhang

Thanks for your sharing. And I wanna reading some papers about this algorithm. Did you publish it in a journal? May I know the websites?

kewei chen

nicely down, thank you for sharing.

uta Ravi

First of all thank you for providing such wonderful tool for vessel segmentation. Is the proposed algorithm published in a journal?

Sony s

Sony s (view profile)

Thank you very much for helping code

Sony s

Sony s (view profile)

Subscript indices must either be real positive integers or logicals.

Error in isodata (line 49)

Error in CoyeFilter (line 38)
level=isodata(Z); % this is our threshold level
please help to remove this error
Thank u very much for code

Sam Ash

Hi guys!! first of all, thanks a lot Mr. Coye for the elegantly simple and brilliant implementation.
for the people who are getting this error:
Error in isodata (line 69)
level = (Threshold - 1) / (N(end) - 1);
Error in CoyeFilter (line 30)
level=isodata(Z) % this is our threshold level

-make sure that all function files are included.
-try brightening the image ur using (preferably manually in RGB form). images that are too dark wont work because the threshold wont be calculated properly. Just use a brighter image or brighten the one u are already using...when I increased the brightness of the images that were giving me an error it started working.

ranran ma

Ronit Roy

paper publication is a must. We can't use this for research purpose without having a publication.

jayani dhaya

is there any paper publication regarding this work

subbu selvi

Thank u sir.

Ronit Roy

Ronit Roy

This is really nice work. Is there any paper publications where you have purposed about this retinal image segmentation technique?

Anubhav Gupta

Is there any paper or any other data where you have wrote about this type of image segmentation ?


Yes,exactly. It would be awesome,thank you so much!

Tyler Coye

Seda Aktasli are you having this issue on the test images or one of your own private images? This will help me narrow down the problem. If it works on my test images but does not work on your private image, I have a modified code I can email you.


Hi, I am getting an error in:
İt says: Undefined function or variable 'isodata'
How can I fix it, can you help me please, cause I tried to do:"To remedy this issue click the home tab. Press the 'set path' button. Next click 'add folder' and then find where you saved the folder for this filter." as you said but it won't worked.

somayeh gh

Hi Tyler, very good job! Do you have any article to proposed your segmentation algorithm?

Tyler Coye

Xiaohan Zhong: If you like, I can run one of your problem sample images and determine where this error is originating from. Just email it to me and I will take a look.

Xiaohan Zhong

Great work!
I can run your sample successfully,but when I run my own sample,it will show errors like this:

Error in isodata (line 69)
level = (Threshold - 1) / (N(end) - 1);

Error in CoyeFilter (line 30)
level=isodata(Z) % this is our threshold level

I even put my image into your sample file and set the file path again,still cannot solve this problem!

Do you have any article to introduce this code?

Can we use than on OCT angiography?



Wafaa (view profile)

I download the file RGB2Lab and it work but stop on
Error in isodata (line 69)
level = (Threshold - 1) / (N(end) - 1);

Error in CoyeFilter (line 30)
level=isodata(Z) % this is our threshold level
I'm sure all fn on the same folder

thanks a lot.... your algorithm helped me a lot....

Department of

Hi! I am new in matlab. How can i want to develop a matched filter for retinal segmentation using particle swarm optimization. Please, can someone help guide me? Thanks in anticipation.

Tyler Coye

@Allison LoBue. This is a pretty simple fix. Because there are 3 functions being used, if you just click on 1 and run it without including the other 2 in your file path, this filter will not run. To remedy this issue click the home tab. Press the 'set path' button. Next click 'add folder' and then find where you saved the folder for this filter. That should do the trick.

Allison LoBue

I am getting the same error as Nziadam: undefined function or variable 'isodata'. How do I add the isodata function to my file path? What exact steps do I need to do? I'm new to MATLAB and am really struggling with this. Thanks!

Sneha Jain

An error is occurring at line 11
Undefined function 'rgb2lab' for input arguments of type 'double'.
i have matlab R2014a

Tyler Coye

@ Nziadam Nziadam make sure that you add the isodata function to your file path. I believe the error you are getting is a result of not having the function in your search path. This should resolve your problem.

I get error with the isodata.
This is the error i get

Undefined function or variable 'isodata'.

Error in seg (line 35)
level=isodata(Z); % this is our threshold level

your filter is great!Do you have other MATLAB codes like this? I'm studying on blood vessel segementation for my graduate.It will be great if you can provide a little extra help

Tyler Coye

@ Almonsi Ughiovhe. Make sure that you put the image file in your file path. That most likely is the error you are getting.

I keep getting these errors

Error using imread (line 349)
File "13_right.jpeg" does not exist.

Error in Coyefilter (line 6)
I = imread('13_right.jpeg')
How van I fix this?

Tyler Coye

Hi M N, I cannot rectify the code unless I know what type of image you are trying to run the code one. Could you email it to me so that I can check it myself? thanks.


M N (view profile)

Thanks for the code Taylor. But it is giving the below error,

Error using reshape
To RESHAPE the number of elements must not change.

Error in CoyeFilter (line 16)
S = reshape(S,size(lab));

Please rectify. Thank you.

Tyler Coye

Thank you for your comment! I am glad that it was helpful to you. If you need assistance feel free to email me.

Fantastic! really good! I want to write a code like this and your help me! but don't worry I don't want to stole your code. I just get adaptation!!!
Best regard


Updated citations list

added citation

updated citations

updated citations.

citation added

Added citations


Added citation

updated text

text update

Updated the Script for the algorithm to improve segmentation.

Text Changes

Minor description changes

MATLAB Release Compatibility
Created with R2014b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.

Learn About Live Editor