File Exchange

image thumbnail

Hausdorff (Box-Counting) Fractal Dimension

version (1.82 KB) by Alceu Costa
Returns the Haussdorf fractal dimension of an object represented by a binary image.


Updated 18 Dec 2013

View License

Returns the Haussdorf fractal dimension D of an object represented by the binary image I. Nonzero pixels belong to an object and 0 pixels constitute the background.


1 - Pad the image with background pixels so that its dimensions are a power of 2.
2 - Set the box size 'e' to the size of the image.
3 - Compute N(e), which corresponds to the number of boxes of size 'e' which contains at least one object pixel.
4 - If e > 1 then e = e / 2 and repeat step 3.
5 - Compute the points log(N(e)) x log(1/e) and use the least squares method to fit a line to the points.
6 - The returned Haussdorf fractal dimension D is the slope of the line.

In this blog post I show how this code can be used to compute the fractal dimension:

Cite As

Alceu Costa (2019). Hausdorff (Box-Counting) Fractal Dimension (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (12)

How to apply this algorithm on cropped image (i.e i have 1024x1024, i will divide in 10 blocks) , after that i need to create a Matrix to store BCI. Thanks in advance.


How do I cite this ?

Does this program work on Newton Fractals?

Tan Nguyen

Great work! I wrote another implementation of the algorithm at In test cases, it is about a little bit more than 2x faster. You guys are welcomed to try and let me know your idea.


very helpful for my research work.Thanks a lot!


ya i got it ...!

Alceu Costa


Just repeat the same procedure for each set of boundary point returned by bwboundaries.

If you have the original black and white image from which you extracted the boundary points, then you probably can use the bwperim function instead of bwboundaries.


hi ,
if i have number of objects then how do i convert all those objects boundary.. in a single image.

Alceu Costa


All you have to do is to convert the boundary points to a black and white image, where the non zero pixels are the boundary and the zero pixels are background.

First, get the linear indices of the boundary pixels:

>> B = bwboundaries(I);
>> BP = B{1}
>> L = sub2ind(size(Ib), BP(:,1), BP(:,2)) % Get the linear indices of the boundary pixels.

Then use the linear indices to generate the binary image Ib:

>> Ib = zeros(size(I))
>> Ib(L) = 1;

And then use Ib to compute the fractal dimension:

>> hausDim(Ib)


hi ,
i have a problem . i have boundary points which i got from bwboundaries function. i need to use box counting to this boundary points or boundary. how could i use ur method..?can u help me in this regard..?


Updated the description to include a link to a blog post explaining how the code can be used.

Corrected a typo in the file title .

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