Skip to contents

Calculate fractal dimension using the cube counting method

Usage

fd_cubes(data, lvec = NULL, plot = FALSE, keep_data = FALSE, scale = FALSE)

Arguments

data

An object of class RasterLayer or mesh3d.

lvec

Vector of scales to use for calculation (i.e. cube sizes).

plot

Planar representation of cubes superimposed on 3D mesh or DEM for visualizing lvec. Default = FALSE.

keep_data

Logical. Keep calculation data? Default = TRUE.

scale

Logical. Rescale height values to the extent? Only relevant for RasterLayer objects. (Defaults to FALSE).

Value

A value for fractal dimension, typically between 2 and 3 or a list if keep_data = TRUE.

Details

This function calculates fractal dimension using the cube counting method. If lvec is not specified, a default based on resolution and extent will be used. Based on lvec, cubes of different sizes are defined and the function counts mesh points that fall within each cube. It is recommended to specify the maximum value of lvec so that the largest box encapsulates the entire object. The smallest scale included in lvec should not be smaller than the resolution of your object.

See also

Examples

fd_cubes(mcap, keep_data = TRUE, plot = TRUE)
#> lvec is set to c(0.053, 0.106, 0.212, 0.423).

#> $D
#> [1] 2.315246
#> 
#> $lvec
#> [1] 0.42329634 0.21164817 0.10582408 0.05291204
#> 
#> $data
#>            l   n
#> 1 0.42329634   1
#> 2 0.21164817   8
#> 3 0.10582408  31
#> 4 0.05291204 134
#> 
#> $method
#> [1] "cubes"
#> 
fd_cubes(mcap, lvec = c(0.05, 0.1, 0.25, 0.5), plot = TRUE)

#> [1] 2.200376

dem <- dem_crop(horseshoe, x0 = -469, y0 = 1267, L = 2, plot = TRUE)

fd_cubes(dem, plot = TRUE, keep_data = TRUE)
#> lvec is set to c(0.016, 0.031, 0.063, 0.125, 0.25, 0.5, 1, 2).

#> $D
#> [1] 2.06335
#> 
#> $lvec
#> [1] 2.000000 1.000000 0.500000 0.250000 0.125000 0.062500 0.031250 0.015625
#> 
#> $data
#>          l     n
#> 1 2.000000     1
#> 2 1.000000     7
#> 3 0.500000    33
#> 4 0.250000   157
#> 5 0.125000   626
#> 6 0.062500  2405
#> 7 0.031250  8254
#> 8 0.015625 23742
#> 
#> $method
#> [1] "cubes"
#> 
fd_cubes(dem, plot = TRUE, keep_data = TRUE, scale = TRUE)
#> lvec is set to c(0.016, 0.031, 0.063, 0.126, 0.251, 0.502, 1.005, 2.01).

#> $D
#> [1] 2.099471
#> 
#> $lvec
#> [1] 2.01000000 1.00500000 0.50250000 0.25125000 0.12562500 0.06281250 0.03140625
#> [8] 0.01570312
#> 
#> $data
#>            l     n
#> 1 2.01000000     1
#> 2 1.00500000     8
#> 3 0.50250000    47
#> 4 0.25125000   218
#> 5 0.12562500   940
#> 6 0.06281250  3530
#> 7 0.03140625 11244
#> 8 0.01570312 27610
#> 
#> $method
#> [1] "cubes"
#>