4.125

4.1 | 9 ratings Rate this file 212 downloads (last 30 days) File Size: 1.6 MB File ID: #13063

boxcount

by Frederic Moisy

 

21 Nov 2006 (Updated 10 Jul 2008)

Code covered by BSD License  

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

Download Now | Watch this File

File Information
Description

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');

MATLAB release MATLAB 7.2 (R2006a)
Zip File Content  
Published M Files Computing a fractal dimension with Matlab: 1D, 2D and 3D Box-counting
Other Files
boxcount/Apollonian_gasket.gif,
boxcount/boxcount.m,
boxcount/Contents.m,
boxcount/demo.m,
boxcount/dla.gif,
boxcount/fractal_tree.jpg,
boxcount/Thumbs.db,
boxcount/html/demo.png,
boxcount/html/demo_01.png,
boxcount/html/demo_02.png,
boxcount/html/demo_03.png,
boxcount/html/demo_04.png,
boxcount/html/demo_05.png,
boxcount/randcantor.m,
boxcount/html/demo_07.png,
boxcount/html/demo_08.png,
boxcount/html/demo_09.png,
boxcount/html/demo_10.png,
boxcount/html/demo_11.png,
boxcount/html/demo_12.png,
boxcount/html/demo_13.png,
boxcount/html/demo_14.png,
boxcount/html/demo_15.png,
boxcount/html/demo_16.png,
boxcount/html/Thumbs.db,
boxcount/html/demo_06.png
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (15)
05 Feb 2007 SIMONA SSSS

SEMBRA UN PROGRAMMA CHE FUNZIONI!

23 Nov 2007 Martin Lopez

The program works.
It would be very useful more documentation.

28 Dec 2007 Guna Sekaran

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

19 Feb 2008 Fabien MONTEL

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

07 May 2008 ton malaka  
07 May 2008 Carissa Pan

Thanks for sharing.

07 May 2008 Carissa Pan

Thanks for sharing

09 May 2008 Owen Horsfield

Consider:
[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?

15 May 2008 Frederic Moisy

Dear 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.

02 Oct 2008 Ashwin Sundar  
26 Oct 2009 Marian Axente

Hi 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.

29 Oct 2009 Frederic Moisy

Dear 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.

30 Oct 2009 Marian Axente

Sorry...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?

30 Oct 2009 Frederic Moisy

Dear 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.

02 Nov 2009 Marian Axente

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

Please login to add a comment or rating.
Updates
10 Jul 2008

help text improved

Tag Activity for this File
Tag Applied By Date/Time
fractals Frederic Moisy 22 Oct 2008 08:49:43
fractal Frederic Moisy 22 Oct 2008 08:49:43
dimension Frederic Moisy 22 Oct 2008 08:49:43
boxcounting Frederic Moisy 22 Oct 2008 08:49:43
mathematics Frederic Moisy 22 Oct 2008 08:49:43
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com