A Practical Implementation of The Box Co PDF
A Practical Implementation of The Box Co PDF
A Practical Implementation of The Box Co PDF
95±100, 1998
# 1998 Elsevier Science Ltd. All rights reserved
Printed in Great Britain
PII: S0098-3004(97)00137-4 0098-3004/98 $19.00 + 0.00
SHORT NOTE
A PRACTICAL IMPLEMENTATION OF THE BOX
COUNTING ALGORITHM
GUIDO GONZATO
Dipartimento di Fisica, Settore di Geo®sica, UniversitaÁ di Bologna, Viale Berti Pichat 8, 40100
Bologna, Italy
(e-mail: guido@ibogfs.df.unibo.it)
INTRODUCTION: FRACTALS AND ALGORITHMS of the object. This step is repeated M times, using
squares of increasingly shorter side. The relation
Fractal geometry and fractal analysis have had a
between Zi and D is
huge impact on geosciences as a whole (see Scholz
and Mandelbrot, 1989; Turcotte, 1992, and refer- log
N
Zi a ÿ D log
Zi :
2
ences therein), though most published works deal
with fractals from a theoretical point of view. One then calculates D by ®tting the regression
Branches of geosciences like geomorphology or ge- line between the independent variable log(Zi) and
ography, which could bene®t from fractal analysis the dependent variable log(N(Zi)), where i = 1, . . . ,
M. D is given by the absolute value of the line
carried out on actual morphologic features, have in
slope.
practice gained less than expected from the fractal
To illustrate practically the use of the method, let
approach.
us imagine one wants to measure the fractal dimen-
This is perhaps a paradox, considering that the
sion of the fault lines distribution in an area: the
®rst instance of fractal analysis dates back to the
®rst step is to draw a tectonic map. The following
works of a geographer, Richardson (1961), in his
algorithm in Table 1 is then applied.
attempts to relate the length of a coastline and the
It must be stressed that in order to obtain reliable
length of the ``ruler'' used to measure it. The
results and a realistic estimate of D, two conditions
method he followed consisted in measuring the
are to be met: (1) a large range of square side
length of the coastline with a map divider, using
lengths must be used and (2) for each step, a large
increasingly shorter steps. Richardson found that
number of boxes must be ``full'' (that is, containing
L
Zi AZi
1ÿD
1 part of the object). Besides, particular care must be
taken with the subsequent regression analysis, see
where L(Zi) is the length of the coastline as a func- Davis (1973), Draper and Smith (1981) and Koch
tion of Zi, Zi is the i-th spread of the map divider, (1987) for examples of application of this technique.
and D is a constant. Mandelbrot (1967) interpreted Manual implementation of the method is tedious
D from a geometrical point of view, noting that and time consuming. As a result, the computer-shy
Equation (1) coincided with the mathematical de®- scholar is bound either to give up or to employ
nition of Hausdor±Besicovich dimension. In this only few square lengths, thus breaking condition 1.
respect, D is a dimension value; Mandelbrot called However, even a PC-class computer can generate Zi,
it ``fractal dimension''. An introduction to fractals N(Zi) and D in a matter of few seconds. The follow-
and the techniques employed for estimating D can ing program has been written with ease of use and
be found in Roach and Fowler (1993). eciency in mind.
The procedure followed by Richardson is known
as the ``divider method'' or ``walker's ruler''
(Mandelbrot, 1982) (see Fig. 1), and in practice it is
THE PROGRAM vsbc
never used because of its main limitation: the object
being measured must be connected. Another algor- vsbc (virtual screen box counting) is a simple
ithm is the box counting (cf. Grassberger, 1993) yet powerful implementation of the classical box-
(see Fig. 2), which has no restrictions on the shape counting algorithm, aimed at fractal analysis of
of the object. To calculate D, one covers the object digitised maps. As its name suggests, it uses a ``vir-
with a grid of squares initially of side Z1, then tual screen'' that is necessary to improve scope and
counts the number N1 of squares that include part performance.
95
96 Short Note
Figure 4. (A) straight line (D = 1). (B) Koch curve (D = 1.2618). (C) Sierpinsky carpet (D=1.5849).
Short Note 99
approach completely and simulate a large screen one changes the directive #define NPIXELS
using conventional memory. 2048 in vscrn.c.
An S*S-pixel wide monochromatic screen can be The critical step in the box counting algorithm is
implemented using an S/8*S array of bytes, where when a box is explored to check whether it contains
each bit acts as a ``virtual pixel'' that is either on or data. In vsbc the search is simple, with the boxes
o (Fig. 3). This implementation is simple, memory systematically searched, pixel by pixel, until either
ecient, and very fast. In fact, accessing the single at least a full pixel is encountered or the last empty
``pixels'' in the virtual screen does not require any pixel is reached. Fast search techniques are beyond
BIOS or graphic library function calls and their in- the scope of this work; see Grassberger (1993) or
herent overhead. Furthermore, the screen resolution Wirth (1976) for further insight.
can be increased at will to increase precision, with vsbc has been compiled and tested using the C
the only limit being available memory. compiler gcc v. 2.7.0 under Linux 1.2.13, as well
Other practical details that can in¯uence the pre- as cc under Digital Unix 4.0, Djgpp v. 2.01 and
cision of the measured D are the scanner resolution, Turbo C++ 3.0 under MS-DOS. The program is
the displacement and the angle of the image on the available by anonymous FTP on ibogeo.df.unibo.it
virtual screen. According to our preliminary tests, (137.204.48.112), in directory /pub/vsbc, or from
the former point does not seem to aect D signi®- FTP.IAMG.ORG.
cantly, whereas the latter is likely to be the main
cause of error, and will be the subject of a sub-
sequent article. RESULTS
Grassberger, P. (1993) On ecient box counting algor- Richardson, L. F. (1961) The problem of contiguity: an
ithms. International Journal of Modern Physics C 4(3), appendix of statistics of deadly quarrels. General
515±523. Systems Yearbook 6, 139±187.
Koch, K. R. (1987) Parameter Estimation and Hypothesis Roach, D. E. and Fowler, A. D. (1993) Dimensionality
Testing in Linear Models. Springer Verlag, Berlin, 378 analysis of patterns: fractal measurements. Computers
pp. & Geosciences 19(6), 849±869.
Scholz, H. and Mandelbrot, B. B. (eds.) (1989) Fractals in
Mandelbrot, B. B. (1967) How long is the coast of Geophysics. BirkhaÈuser Verlag, Basel, 313 pp.
Britain? Statistical self-similarity and fractional dimen- Turcotte, D. L. (1992) Fractals and Chaos in Geology and
sion Science 156, 636±638. Geophysics. Cambridge University Press, Cambridge,
Mandelbrot, B. B. (1982) The Fractal Geometry of Nature. 221 pp.
W. H. Freeman and Co., San Francisco, California, Wirth, N. (1976) Algorithms + Data Structures = Programs.
468 pp. Prentice-Hall, Englewood Clis, New Jersey, 228 pp.