File Exchange

image thumbnail


version (4.88 KB) by Alceu Costa
Implementation of the SFTA algorithm for texture feature extraction.


Updated 02 Nov 2016

GitHub view license on GitHub

Extract texture features from an image using the SFTA (Segmentation-based Fractal Texture Analysis) algorithm. To extract features, use the sfta(I, nt) function, where I corresponds to the input grayscale image and nt is a parameter that defines the size of the feature vector.
The features are returned as a 1 by (6*nt -3) vector.

I = imread('coins.png');
D = sfta(I, 4)

Brief description of the SFTA algorithm:

The extraction algorithm consists in decomposing the input image into a set of binary images from which the fractal dimensions of the resulting regions are computed in order to describe segmented texture patterns.

Publication where the SFTA algorithm is described:

Costa, A. F., G. E. Humpire-Mamani, A. J. M. Traina. 2012. "An Efficient Algorithm for Fractal Analysis of Textures." In SIBGRAPI 2012 (XXV Conference on Graphics, Patterns and Images), 39-46, Ouro Preto, Brazil.

Here I show how SFTA can be used to classify textures:,/computer/vision,/descriptor,/feature/extraction,/image/processing,/matlab,/texture/descriptor/2013/09/02/texture-classification.html

Cite As

Alceu Costa (2020). alceufc/sfta (, GitHub. Retrieved .

Comments and Ratings (29)

i have try sfta but is not working. please can you send me the code?

Error message received:

>> sfta
Not enough input arguments.

Error in sfta (line 30)
T = otsurec( I, nt );

How to I resolve this ?

Hello Alceu, I have executed the code but I am getting the error:

Error in sfta (line 24)
I = im2uint8(I);

May I know why I am getting this error.


hello Alceu, i have executed the code but i am getting the error as:

T11_38.jpg, floor2
Subscripted assignment dimension mismatch.

Error in train1 (line 12)
F(currentLine, :) = f;

May i know why i am getting this error since i am new to Matlab.

this code is not runnable how to run this code? and what is the main file?

Kent Yeap

Hi Alceu, thank you for sharing your code! Very much appreciate it. I would like to know after getting the 3 features of a set of database images, what would be a suitable classifier to find a matching image? Thank you.

Hi, Alceu, your method is one of the efficient method to extract the features from the grayscale images, i got one simple question that is your method can employ to extract features from document images and another question is can you explain what are the 21 features which are given after your method applied on the image.
thank you,


I have important question refering to the DTD Texture Dataset in combination with a SVM(RBF) where I only get 1.3 % accuracy. Why your algorithm performs so bad here?

Hi Alceu, nevermind! I found what I was missing with the code. Great job man!

Hi Alceu, thank you so much for the code, I really like the logic of the paper.
My question is, assume you have 3 thresholds selected (nt =3).
In this part of the code, where you are looking between the threshold
t = 1 : (numel(T) - 2)

our numel(T)-2 would be 1, so that we would only loop through this part of the code once, and thus we only binirize between threshold 1 and 2. And we wouldn't reach between 2 and 3.

Am I looking at it wrong? Shouldnt we change it to numel(T)-1?

Thanks a lot Alceu, so helpful

Alceu Costa

Dear Diana Rahim,

The parameter nt controls the number of features extracted by SFTA. If you need more details I recommend reading the paper [1].

[1] You can find the paper here:

If i want only three features per image then can i take average of each feature from the output of sfta(Image,1)

Diana Rahim

Hi Alcue Costa
I am a newbie in matlab
can u explain me details on the parameter for nt
what does it us for and hoe do we assign it as the size of the feature vector

Alceu Costa

Hi Israa Israa,

I believe that you are mentioning the size of the feature vector which is (6*nt - 3).

The reason for this feature vector size is that SFTA generates (2*nt-1) binary images and, from each binary image, extracts 3 features: (i) fractal dimension of the borders, (ii) mean gray-level and (iii) area (i.e. the number of pixels).

Please note that I made an update to the code in 28-dec-2015. Before the update the feature vector size was 6*nt. I made the update because there was 3 values in the feature vector that were redundant.

israa israa

Hi Alceu Costa,

I computed SFTA on my thesis, and I need a justification about the number "6" that you used on your code (when typing (6*nt))
please can you replay ASAP.

Thank in advance.

Alceu Costa

Hi Sakura,

I belive you are referring to the code in the blog example. The 'testImagePath' variable contains the path to a random image.

In your case you are using the path to the last image in the while loop so that explains why the returned class is different.

The idea is that you can set the 'testImagePath' or the variable 'Itest' to whichever image you want to analyze.


Thanks for a good work!Do i need to actual change all the file's names to img1.jpg...img1000jpg. If not, then what is testImagePath? is it the same as imagePath in while loop?
I used imagePath in Itest, and predict " pebbles" instead of "knit" like yours. Please help.

Alper Yaman

Nice work and I liked your blog ( too. You wrote very clear how to use this method to classify textures.
You can speed up your codes. There are '4' for loop and 2 'if' nested in a while loop in hausDim.m. In findBorders.m there are '4' for and '3' if nested. If I have time I would be glad to speed up the code and upload.

how to run this file??

Alceu Costa

Hi Image Analyst,

Thank you for your suggestion. I have just added the image to illustrate the applications.

Thank you!

Why not include those blog images here as a screenshot, so people can see what it does?

Alceu Costa

Hi Nagaraj,

Sorry for the delay in answering your question.

SFTA uses thresholding as part of its extraction algorithm. However, the input image to the sfta() function does not need to be segmented. For instance, in the example I extract the features from the 'coins.png' image without segmenting or thresholding it.

This SFTA code is released under the BSD license, so you can you use it in your research. In the file description

I have also included the paper that describes the SFTA algorithm and a blog post showing in a more practical way how it can be used.

As for the .mha files, unfortunately I have never worked with them. Maybe you can find some help in the Matlab forums.

Nagaraj H

I am having BRATS database of brain MR images with tumor in .mha format. How to read, display and process(tumor segmentation and its evalvation) .mha files in MATLAB?

Nagaraj H

How to extract features without thresholding (i.e. for original image)?
I found nt=3 as optimum value for my work. shall I publish a paper with some modifications citing your paper? Is there any copyright restriction?

Alceu Costa

Hello Volkan,

In order to use the SFTA extractor you only have to make a call to the sfta() function and it will return the texture feature vector.

In my experiments on texture classification I have found that the best values for the nt (number of thresholds) parameter was 8. However in other applications you may have to do cross validation if you want to find the optimum value for nt.

The article describing my experiments with SFTA is avaiable in this URL:


Dear Alceu,

Your code is interesting for me. However, I would like to have an example to run your code. Let's talk about the coin.jpg.

I see that there are 4 functions in your code. In what order should I run those functions to segment the coins from the background? How would you select the number of thresholds?


Alceu Costa

Hello Kaveh,

Thanks for the feedback. The extraction time of 24s that you are getting is considerably higher than the extraction times that I got in my experiments.

Just for comparison, I have just executed with a 720x576 grayscale image, setting the nt parameter to 8 and the extraction time was 6s:

>> tic; sfta(I, 8); toc;
Elapsed time is 6.039394 seconds.

Which value for the nt parameter that you are using? For the datasets that I have employed to test SFTA, I found that a value of nt higher than 8 did not increase classification accuracy.

Here’s a link to the article that I hope can help you:

Dear Alceu,

Thank you. This is a nice method to compute the hausdorff's fractal dimension from the border of an object.
I have implemented your method on a data set.
It seems your method is computationally time consuming since for a 720*576 gray scale image, 24.453 second is required for analysis.
Have you any comments about this?




Updated link to blog post.

Fixed a bug where part of the feature vector was redundant.

Just added a screenshot to illustrate the submission. The code is the same.

Updated file description to include a link showing how the feature extractor can be used in texture classification.

Removed iptchecknargin calls.

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