version 1.0.0.0 (1.6 MB) by
Frederic Moisy

Fractal dimension using the 'box-counting' method for 1D, 2D and 3D sets

BOXCOUNT Box-Counting of a D-dimensional array (with D=1,2,3).

The Box-counting method is useful to determine fractal properties of a

1D segment, a 2D image or a 3D array. If C is a fractal set, with fractal dimension DF < D, then the number N of boxes of size R needed to cover the set scales as R^(-DF). DF is known as the Minkowski-Bouligand dimension, or Kolmogorov capacity, or Kolmogorov dimension, or simply box-counting dimension.

[N, R] = BOXCOUNT(C), where C is a D-dimensional array (with D=1,2,3), counts the number N of D-dimensional boxes of size R needed to cover the nonzero elements of C. The box sizes are powers of two, i.e., R = 1, 2, 4 ... 2^P, where P is the smallest integer such that MAX(SIZE(C)) <= 2^P. If the sizes of C over each dimension are smaller than 2^P, C is padded with zeros to size 2^P over each dimension (e.g., a 320-by-200 image is padded to 512-by-512). The output vectors N and R are of size P+1. For a RGB color image (m-by-n-by-3 array), a summation over the 3 RGB planes is done first.

BOXCOUNT(C,'plot') also shows the log-log plot of N as a function of R

(if no output argument, this option is selected by default).

BOXCOUNT(C,'slope') also shows the semi-log plot of the local slope DF = - dlnN/dlnR as a function of R. If DF is contant in a certain range of R, then DF is the fractal dimension of the set C.

The execution time depends on the sizes of C. It is fastest for powers

of two over each dimension.

Examples:

c = (rand(1,2048)<0.2);

boxcount(c);

c = randcantor(0.8, 512, 2);

boxcount(c);

figure, boxcount(c, 'slope');

Frederic Moisy (2021). boxcount (https://www.mathworks.com/matlabcentral/fileexchange/13063-boxcount), MATLAB Central File Exchange. Retrieved .

Created with
R2006a

Compatible with any release

- Mathematics > Fractals >

**Inspired:**
Audio Watermarking by selvakarna, LEFA (Lineament Extraction Fracture Analysis), DEM to volumetiric, Dicom Operator - EsmeProcess

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

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

john steve vanegas canchonbuenas tardes me presenta este error

Error using boxcount (line 51)

Not enough input arguments.

error(nargchk(1,2,nargin));

max segalithanks for this..... how can I extract the slope of the curve? the scales are logaritmic so the basic fitting does not help. cheers

Ahmet TunaHan Weikavya negihow do I download it?

Pablo Perezwhich 3d image format is entered?

Shuqi WangFrederick WhiteHi,

I am trying to use this method currently but with many different images the boxcount plot always seems to be exactly the same.

How can you get the programme to return D value?

Thanks,

Best

Fred.

Athos GarciaThanks, great work on the demo!

eslam aliError using boxcount

Too many output arguments.

how can solve that

cobrathanks of sharing this

seyed hosein alhoseinyhello thank you from your good code-I need codes about fractal simulations in Geology and mineral exploration Issues such as estimation and simulation for Thickness of Orebodies using fractal algorithms.thank you

10BPhumzile MabuzaHi, can I please ask how to get the boxcount or randcantor function, I am using 2014a student version and cannot find the functions. Where can Ii download from

please help!

orlando chancayHi

I am Working with this method

I need to calculate the fractal dimension of lesions in the Brain but this are very smalls, size of lesions is( 7x5x8 ) , and the result of FD in this lesions is around 1.4 to 2,2, and do not understand why this result, would know that should is 2-3.

kinorHi Frederic,

thanks for your submission, works really nicely.

to get if faster for 2D i propose instead of the inner loops:

c = c(1:2:end,1:2:end)|c(2:2:end,1:2:end)|c(1:2:end,2:2:end)|c(2:2:end,2:2:end);

n(g+1) = sum(c(:));

cheers

kinor

Nathan OrloffI think the for loops in the function could be replaced with arrayfun to make the execution a little faster. And the output should be reshaped to be able to be used with cellfun. Other than that it is 1) correct and 2) awesome. I think that is the best you can hope for.

xiang fionaLucaWhat if one channel of an RGB image has some blocks equal to 0 ?

I modified your code:

[n,r] = boxcount(bcont);

if n==0,

DF(i,j,d) = 0;

else

df=-diff(log(n))./diff(log(r));

DF(i,j,d) = mean(df);

end;

LucaIs it possible that your nice algorithm (i love it) is too much slow..?

Jeff TuhtanThanks for the submission, it worked just fine analyzing the fractal dimension of river cross sections.

Marian Axentemoisy.nospam@fast.u-psud.fr bounces me every time...

Frederic MoisyDear Marian

Please use my email address for questions or discussions about this submission. Algorithms to compute a fractal dimension (box-counting or other methods) are all approximations, which converge towards the "true" topological dimension in the limit of large scale separation. I hope this helps. - F.

Marian AxenteSorry...you are right. One more question in light of my fractal inexperience: why is the algorithm not give a full topological dimension whenever we put a square or a cube as input? Rather it gives 1.96 or 2.9. I thought that for smooth manifolds, the fractal dimension is equal to the topological dimension. Is there an approximation somewhere, or how could I modify your code to get a full 3 for a cube input?

Frederic MoisyDear Marian,

What does it mean "the program crashes"? Please provide an example. If I make the simplefollowing test to compute the "fractal" dimension of a square,

a=zeros(4096,4096);

a(600:800, 1200:1400)=1;

boxcount(a,'slope')

it works properly (dimension close to 2 for small r, and close to 0 for large r, as expected)

F.

Marian AxenteHi Frederic

Could you point me in the right direction about your boxcounting algorithm? If I put a cube as input the program crashes; I thought that it was an easy way to check for consistency of the results.

Ashwin SundarFrederic MoisyDear Owen Horsfield,

This is not really a bug: boxcount does not give the *minimum* number of boxes needed to cover the set, but only the number of boxes starting from the 1st element. However, it is true that starting the box covering with the 1st element is arbitrary, and other choice may lead to slightly different results.

Owen HorsfieldConsider:

[n,r]=boxcount([0 1 1 0])

I can put a single 1x2 box around the nonzero elements. So output should be:

n=[2 1 1]

r=[1 2 4]

However boxcount returns:

n=[2 2 1]

r=[1 2 4]

Algorithm problem? or am i missing something?

Carissa PanThanks for sharing

Carissa PanThanks for sharing.

ton malakaFabien MONTELclair et efficace ! merci pour le programme, il m'a fait gagné du temps

Guna SekaranVery good tool. It works. Thanks to Author. May be more docs will help for better understanding.

Martin LopezThe program works.

It would be very useful more documentation.

SIMONA SSSSSEMBRA UN PROGRAMMA CHE FUNZIONI!