FractalVision Lab · Scientific Documentation

Methodology

How FractalVision Lab measures structural complexity — from raw image to fractal dimension, with full statistical validation.

What is Fractal Dimension?

Classical Euclidean geometry assigns integer dimensions to objects: a line is one-dimensional, a filled square is two-dimensional, a solid cube is three-dimensional. These dimensions describe how a shape scales— double the side length of a square and its area grows by 2² = 4; double a cube's side and its volume grows by 2³ = 8.

Many natural objects — coastlines, leaf venation networks, snowflakes, river tributaries — defy this neat classification. They exhibit self-similarity across scales: a section of a coastline viewed at 1 km resolution looks statistically indistinguishable from the same coastline viewed at 100 m resolution. The geometric complexity is preserved as you zoom in, not smoothed away.

The fractal dimension D is a non-integer exponent that quantifies this scale-invariant complexity. For a two-dimensional binary image, D lies in the range [1, 2]:

Near-linear

D ≈ 1.0–1.2

Smooth curves, simple edges. Barely more complex than a line.

Moderate

D ≈ 1.4–1.6

Complex networks, jagged borders, river systems. Mid-range self-similarity.

Space-filling

D ≈ 1.8–2.0

Dense, highly irregular textures approaching full 2D coverage.

The lower bound D = 1 corresponds to a single continuous curve (a coastline with zero roughness); the upper bound D = 2 would be a completely filled square with no structure. Real biological and geographical patterns cluster between 1.5 and 1.95, reflecting their intermediate complexity. A D value outside [0.5, 2.1] is almost certainly an artefact of preprocessing and is rejected by the analysis pipeline.

The Box-Counting Algorithm

Box-counting (also called the Minkowski–Bouligand dimension estimator) is the most widely used method for computing the fractal dimension of raster images. The algorithm is geometrically intuitive:

  1. 01

    Overlay a grid

    Cover the binary image with a regular grid of square boxes, each of side length ε (epsilon). The grid is aligned to the top-left corner of the image.

  2. 02

    Count occupied boxes

    Count N(ε) — the number of boxes that contain at least one white (foreground) pixel. Empty boxes are discarded.

  3. 03

    Shrink the grid and repeat

    Halve the box size (ε → ε/2) and repeat. FractalVision Lab iterates through powers of 2: ε ∈ {4, 8, 16, 32, 64, 128, …} up to image_size / 4. This gives 6–8 data points per analysis.

  4. 04

    Fit the power law

    As ε → 0, the count N(ε) grows as a power law: N(ε) ~ ε^(−D). Taking logarithms, log N(ε) = −D · log ε + const, so D is the slope of the log-log plot.

D = lim(ε→0) log N(ε) / log(1/ε)

Grid offsets. A known artefact of box-counting is that the result depends slightly on where the grid is anchored relative to the image. To reduce this grid-alignment bias, the algorithm runs box-counting at four grid offsets per box size: 0, 25%, 50%, and 75% of the box size. For each scale, the minimum box count across all offsets is used rather than the average. This implements the tightest box cover — a conservative bound that prevents overcounting caused by favorable grid placement over the fractal pattern.

Log-Log Regression

The relationship N(ε) ~ ε^(−D) is linearised by taking natural logarithms of both sides. Letting x = log(1/ε) and y = log N(ε):

y = D · x + b
where D = fractal dimension (slope), b = intercept (constant)

FractalVision Lab fits this line using scipy.stats.linregress, which applies ordinary least-squares (OLS) regression. The key outputs are:

Slope (D)The estimated fractal dimension. This is the primary scientific output.
R² ScoreCoefficient of determination. Measures how well the data points lie on a straight line in log-log space. R² ≥ 0.99 confirms near-perfect self-similarity across scales. Lower values suggest the pattern is not self-similar over the measured range.
Standard ErrorThe standard error of the slope estimate. Smaller is better. Reported to 4 d.p. in the Reliability Dashboard.
95% Confidence IntervalThe range [D − 1.96·SE, D + 1.96·SE] within which the true fractal dimension lies with 95% probability, under the OLS assumptions. A narrow CI indicates a precise, stable estimate.

A high R² value is the strongest single indicator of a well-behaved fractal structure. It confirms that the power-law relationship holds across all measured scales, not just locally — a requirement for meaningful fractal dimension estimation. Dissertation specimens in FractalVision Lab's gallery achieve R² ≥ 0.9953.

Image Preprocessing Pipeline

Box-counting requires a binary image — every pixel is either foreground (white, 255) or background (black, 0). The preprocessing pipeline transforms a colour photograph into this binary mask in three stages:

Stage 1 — Grayscale Conversion

The colour image (BGR format from OpenCV) is converted to an 8-bit grayscale image using cv2.cvtColor(image, cv2.COLOR_BGR2GRAY). Luminance weights (0.114 B + 0.587 G + 0.299 R) are applied, preserving perceptual intensity. The image is also resized to a maximum dimension of 1 024 px if larger, preserving aspect ratio.

Stage 2 — Thresholding Method

Otsu (automatic)

Otsu's method finds the global threshold that minimises intra-class variance between the foreground and background pixel intensity distributions. It is fully automatic and works well when the image has a clear bimodal histogram (e.g. a dark leaf on a bright background).

Adaptive (local)

For images with uneven illumination (shadows, vignetting), adaptive thresholding computes a per-pixel threshold from the weighted average of a 11×11 neighbourhood (Gaussian weights, C = 2). This suppresses lighting gradients that would confuse a global threshold.

Manual (user-set)

The user provides an explicit threshold value (0–255). Pixels darker than the threshold become foreground. Useful for fine-tuning or reproducing a specific preprocessing condition.

Stage 3 — Analysis Mode

Full Mask

The entire thresholded binary mask is counted. D measures the total spatial complexity of the foreground structure — appropriate for solid or filled patterns.

Boundary (Canny edge)

After Otsu thresholding, Canny edge detection (thresholds 50/150) extracts just the boundary pixels. D measures the complexity of the outline rather than the filled region. Particularly meaningful for smooth-edged biological specimens.

Texture (morphological gradient)

A morphological gradient (dilation − erosion, 3×3 kernel) highlights local texture transitions. This mode captures internal surface complexity and is appropriate for porous or textured materials.

Quality and Reliability Metrics

Because fractal dimension estimates can be sensitive to preprocessing choices and image quality, FractalVision Lab accompanies every result with a multi-layer reliability assessment.

Quality Score (0–100)

A composite integer score that begins with the regression fit quality and applies stepwise penalties for conditions that undermine measurement reliability.

Base Score

base = R² × 100
if R² ≥ 0.999: base += 5 (bonus for near-perfect fit)
if R² < 0.95: base -= 20 (poor linearity)
if R² < 0.90: base -= 20 (cumulative — very poor linearity)
if scales < 5: base -= 10 (too few data points)

Penalty Adjustments

Foreground ratio < 5%−15Mask too sparse — box counts dominated by noise
Foreground ratio < 10%−5Somewhat sparse
Foreground ratio > 95%−15Near-saturated — most boxes trivially occupied
Foreground ratio > 85%−5Somewhat dense
Threshold sensitivity σ > 0.10−20Very unstable across threshold variation
Threshold sensitivity σ > 0.05−10Unstable across threshold variation
Rotation sensitivity σ > 0.10−15Highly orientation-dependent
Rotation sensitivity σ > 0.05−8Moderately orientation-dependent

Foreground ratio penalties are mutually exclusive (only the first matching condition applies). Sensitivity penalties are applied only when the corresponding test was run. The final score is clamped:

score = max(0, min(penalised_base, 100))

Reliability Bands

≥ 85

High reliability

70–84

Medium reliability

< 70

Low reliability

Threshold Sensitivity Test

The sensitivity test re-runs the full analysis at three threshold values: the computed threshold, threshold − 15, and threshold + 15. The standard deviation σ of the three resulting D values is computed. If σ < 0.05, the result is marked Stable; otherwise it is marked Unstable. A stable result means the fractal dimension is a robust property of the structure, not an artefact of the exact threshold chosen. The test is only available for Full Mask mode with Otsu or Manual threshold.