File Exchange

image thumbnail

Trainable COSFIRE filters for curvilinear structure delineation in images

version (13 MB) by Nicola Strisciuglio
B-COSFIRE filters detect line at different orientations by combining the responses of DoG filters.


Updated 28 Aug 2017

View Version History

View License

We propose a filter that selectively responds to vessels and that we call B-COSFIRE with B standing for bar which is an abstraction for a vessel. It is based on the existing COSFIRE (Combination Of Shifted Filter Responses) approach.
A B-COSFIRE filter achieves orientation selectivity by computing the weighted geometric mean of the output of a pool of Difference-of-Gaussians filters, whose supports are aligned in a collinear manner. It achieves rotation invariance efficiently by simple shifting operations.
The proposed filter is versatile as its selectivity is determined from any given vessel-like prototype pattern in an automatic configuration process. We configure two B-COSFIRE filters, namely symmetric and asymmetric, that are selective for bars and bar-endings, respectively. We achieve vessel segmentation by summing up the responses of the two rotation-invariant B-COSFIRE filters followed by thresholding.
The B-COSFIRE filters can be used for detection of any elongated patterns in images:
- blood vessels in medical images
- roads and rivers in aerial images
- leaf nerves in natural images
- tiles in mosaics and textured images
The code is continuosly updated in the GitLab repository
If you use this script please cite the following papers:
[1] "George Azzopardi, Nicola Strisciuglio, Mario Vento, Nicolai Petkov, Trainable COSFIRE filters for vessel delineation with application to retinal images, Medical Image Analysis, Available online 3 September 2014, ISSN 1361-8415,"
[2] "N. Strisciuglio, G. Azzopardi, M. Vento, and N. Petkov" - Supervised vessel delineation in retinal fundus images with the automatic selection of B-cosfire filters. Machine Vision and Applications, doi:10.1007/s00138-016-0781-7
V1.4: Added CrackDetectionCluster.m - Experimental code (and data) to replicate results in the CAIP17 paper.
V1.3: Examples added, which are in the paper "N. Strisciuglio, N.Petkov - Delineation of line patterns in images using B-COSFIRE filters, IWOBI 2017". Correction of the approximated computation of the shifting vectors.
V1.2: Visualize B-COSFIRE output response and segmented image when Application() is called without output parameters.
V1.1: Computation of the orientation map added.

Cite As

Nicola Strisciuglio (2021). Trainable COSFIRE filters for curvilinear structure delineation in images (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (43)

Nicola Strisciuglio

A Python implementation was released few days ago at the repository url:

Murat Cankaya

Thank you very much for this work. I am wondering if there is any Python implementation already. I found an email list* and a bachelor thesis* about the implementation in Python. Did you release it somewhere? Thanks in advance.

Email list:

Nicola Strisciuglio

Edmund, please refer at the example files in the main directory to see how to configure and use the filters: ExampleBloodVesselSegmentation.m, INRIAimages.m, PavementCrackDelineation.m etc.
And to the file BeforeUsing.m to compile the necessary MEX-files.

Edmund Arthur

Dear Dr. Nicola Striscuiglio,

I run the applyCOSFIRE.m script and I get this error:

Not enough input arguments.

Error in applyCOSFIRE (line 20)
tuple = computeTuples(inputImage,operatorlist);

Please help.


Nicola Strisciuglio

The file BCOSFIRE_media15.m already contains an example of use.

Dan Qin

Would please provide the main function as example for implementing the whole package to me? It's difficult to connect the logic for these function

Dear Dr. Nicola Strisciuglio,

Thank you for your clear answer.

Best regards,


Nicola Strisciuglio

Dear Dhimas,
your observations are correct. In our experiments we selected a value of sigma that is a 'good' value for the average size of the vessels in one image. It gives a feeling of the scale at which you are working.

Of course, you can setup different values (i.e. a list of values). This implementation will compute the response of separate COSFIRE filters and the final response as the pixel-wise maximum across scale responses (similarly to the orientation tolerance implementation).


Dear Dr. Nicola Strisciuglio,

Thank you for answering my previous questions.

Now I would like to know why the code uses only one value of sigma for each of symmetric and assymetric filters (i.e. 2.4 and 1.8 for the drive database). I think the image from the database contains vessels with some diameters (2-10 pixels). Is it beneficial to use some sigma values and further combine the responses? A brief explanation on the above matter will be much appreciated.

Best regards,


Noa Shkedi

Dear Dr. Nicola Strisciuglio,

Thanks for the quick answer, I download the last version and still got the same error.
input is not defined in case the inputfilter=DoG:

from 'configureCOSFIRE.m' function -
if strcmp(,'Gabor')
% Get responses of a Bank of Gabor filters
input =

%Suppress the responses that are lower than a given threshold t1 from the maximum response
input(input < params.COSFIRE.t1*max(input(:))) = 0;

again the error is -
>> ExampleBloodVesselSegmentation
Building with 'MinGW64 Compiler (C)'.
MEX completed successfully.
Compiling done.
Enjoy using B-COSFIRE filters!!!
Undefined function or variable 'input'.

Error in configureCOSFIRE (line 23)
input(input < params.COSFIRE.t1*max(input(:))) = 0;

Error in BCOSFIRE_media15 (line 90)
symmfilter{1} = configureCOSFIRE(line1, round([y x]), symm_params);

Error in ExampleBloodVesselSegmentation (line 62)
[output.respimage] = BCOSFIRE_media15(image, symmfilter, asymmfilter, 0.5);

Nicola Strisciuglio

Hi Noa,
for blood vessel segmentation you should use DoG.
I'm not able to reproduce the error. Please refer at the very last version of the code on GitLab and let me know.


Noa Shkedi

Dear Dr. Nicola Strisciuglio,

I am trying to run the blood vessel example and immediantly got errors.
For the blood vessel example, should I change the filter to Gabor (default is DoG)?
If the filter is DoG the error is -

Undefined function or variable 'input'.

Error in configureCOSFIRE (line 23)
input(input < params.COSFIRE.t1*max(input(:))) = 0;

input is not defined if the filter is DoG

Thanks in advanced,

Nicola Strisciuglio

Hello Dhimas,
here the answers:

1. In the parameters of the function blurshift there are shift values for the blurring kernel itself (which we do not use in this implementation, that's why they are set to 0). The shift operation you are referring at is done in computation of the response of the COSFIRE filter in the file applyCOSFIRE.m at the line number 292 (tupleoutput = circshift(tuple.hashtable(hashkey),[round(row),-round(col)]);) using the function circshift.

2. The max operation is done inside blurshift (that calls maxgaussianfilter, which is a gaussian dilation operation (or max-blurring)).


Dear Dr. Nicola Strisciuglio,

Thank you for the submission. The code is very useful.

However, I have some concerns regarding the code as follows:

1. In the paper, you obtained the blurred and shifted DoG filter response using equation (5). If I am not mistaken, you performed blurring and shifting to the DoG filter response using a subcode called 'blurshift' in the 'computeTuples' subcode. As described in the paper, 'blurshift' was used with some sigma values. Also, it was mentioned that several values of u and v were used in the shifting process. Nevertheless, I am curious why 'blurshift' was only used with 'shiftrow' and 'shiftcol' equal to 0.

2. In addition to the point (1), I am not able to find in the 'computeTuples' subcode, a syntax or subcode which maximizes the blurred and shifted DoG filter responses as in equation 5 of the paper. Is the maximization process performed in 'blurshift'?

Thank you very much.

Adrian Kind

lidia Talavera

Excellent work!

remaoun salim

Nicola Strisciuglio

Xingtian dong,
you can find instructions in the README file, where it says that you have to run the script BeforeRunning.m in order to compile a MEX file required by COSFIRE filters.

xingtian dong

I can't run it. It says you haven't define 'dilate'.
blurshift>maxgaussianfilter (line 44)
Z = dilate(dilate(Z1,gauss1D,f1(1)-1,f1(end),f2(1)-1,f2(end)),gauss1D',f1(1)-1,f1(end),f2(1)-1,f2(end));

Nicola Strisciuglio

Dear Haolin,
the problem was that you tried to call Application() without an output parameter.
If you wanted the B-COSFIRE response only, you could call
resp = Application();

If you wanted also the orientation map you could type
[resp, oriensmap] = Application();

Anyway, I corrected this bug and if you download the actual code, MATLAB will visualize the B-COSFIRE response image and the binary vessel map in two different windows when Application() is called without output parameters.


Dear Muhammad, ‘Reference to non-existent field 'respimage'.

Error in Application (line 56)
output.segmented = (output.respimage > 37);’,i don't know what cuase that, please tell me , thank you


Dear Muhammad, ‘Reference to non-existent field 'respimage'.

Error in Application (line 56)
output.segmented = (output.respimage > 37);’,i don't know what cuase that, please tell me , thank you


Thanks for your research, it's extremely promote my work!!!

Pavel Vostatek

lei ru

good jop!

Ciro Mascolo

Nicola Strisciuglio

Dear Muhammad,
L is a parameter whose value has to be chosen by you. It should be the average width (in terms of pixels) of the vessels you want to detect in your images.

Muhammad Usman khan

Hello Nicola,
can you please provide details that how to estimate a reasonable value of sigma. I have funds images having size of 2 MB. I got a lot of noise. I found an equation in section 3.6 to estimate sigma automatically but I don't understand that how to compute the value of "L" in that equation.

ting su


Thanks for the submission, works great!
One comment/tip: the quality of the result improves significantly when applying illumination correction, i.e. subtracting from the grayscale image the median filtered image with large region size (I use 25 pixels).

Nicola Strisciuglio

Dear Michal,
The parameters of the filter, especially the sigma and the rho, are specific for the characteristics of the vessel-like structures that you want to detect. For high-resolution images, I would expect thicker vessels, so I would use lager values for "sigma". It is the same (more or less) if you reduce the resolution of the images: in this case the vessels become thinner and you can use lower values of sigma. By the way, in Section 3.4 of the paper "Trainable COSFIRE filters for vessel delineation with application to retinal images" there is a suggestion about how to estimate a reasonable value of sigma. Hope it was helpful.


quick follow up on my previous comment. high resolution of picture causes the algorithm to break and pick up a lot of noise, upon re sizing <1000px works like charm and is super fast


How should I select the symmfilter and asymmfilter parameters ? when i try to use the same as in demo for my fundus image the segmentation pick up a lot of noise. Or I'm missing some pre-processing step ? Any advice on how to segment this image will be appreciatted.

Thank you

peppeweb dalessio

Very fast algorithm!



Ugo Moschini

Shahab Aslani

Nicola Strisciuglio

Hi zoaia asif, in the zip package you find a README file with the instructions.

zoaia asif

how to run these codes? and which m file to run initially?

Nicola Strisciuglio

We use a vector of the type 0:255 (so 256 values) in Matlab. It indicates the interval for the scaling of the response image and the set of thresholds to use for the evaluation of the algorithm.

Sana Alam

What is the value of span in getStatsData function?

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

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!