Skip to main content

Ant Colony Optimization (ACO) for Image Analysis

The Image ACO tool uses swarm intelligence to detect linear features and edges in outcrop photographs. It is particularly effective for semi-automatic fracture trace extraction, where conventional edge detectors struggle with noisy, textured rock surfaces.

When to Use ACO

ACO is best suited to photographs where you need to extract:

  • Fracture traces through heterogeneous lithologies where fracture aperture and contrast vary along strike
  • Bedding contacts that are partially obscured by weathering or vegetation
  • Structural lineaments in drone or UAV orthomosaics
  • General edge masks as input to downstream classification or segmentation workflows

For clean, high-contrast edges a simple Sobel or Canny filter is faster. ACO adds value where features are discontinuous, partially hidden, or embedded in texture.

Quick Start

  1. Open a photograph in the Image View
  2. Go to Image View > ACO Settings to configure parameters (see below)
  3. Set Mode to 0 (Edge Detection) or 1 (Fracture Trace)
  4. Run via Image View > ACO
  5. The result appears as a colour-mapped mask overlay on the photograph
  6. Adjust the colour map and filter threshold via the properties panel to isolate features of interest

The debug console will report the output logits range when the run completes. A debug edge-map BMP is also saved alongside the source image.

Modes

Edge Detection (Mode = 0)

General-purpose edge confidence mask. The heuristic measures gradient energy (the dominant eigenvalue of the image structure tensor). Ants are seeded uniformly, explore freely, and every ant deposits pheromone at each step.

Use this mode for:

  • Identifying all edges and boundaries in an image
  • Creating a segmentation mask for downstream ML pipelines
  • Situations where you do not need directional continuity

Fracture Trace (Mode = 1)

Optimised for extracting linear geological features. The heuristic measures structure-tensor coherence (the difference between the two eigenvalues), which responds strongly to locally linear intensity patterns and suppresses isotropic texture and corner features.

Key differences from Edge mode:

BehaviourEdge ModeTrace Mode
HeuristicGradient energyCoherence (linearity)
Ant seedingUniform randomBiased toward high-coherence pixels
Directional biasNoneAnts prefer to continue in their current direction
Pheromone depositionAll antsElitist (best path per iteration gets a bonus deposit)
Tabu memoryShort (8 cells)Long (24 cells), preventing tight loops
Ant respawn rateHigher (0.02)Lower (0.005), allowing longer traces

Use this mode for:

  • Fracture trace mapping on outcrop photos
  • Extracting bedding-parallel features
  • Any setting where you want to emphasise continuous linear structures over general texture

Parameters

Open Image View > ACO Settings to access the property panel. Parameters can be changed between runs without reloading the image.

Core Parameters

PropertyDefaultDescription
Mode00 = Edge Detection, 1 = Fracture Trace. Controls heuristic, seeding, deposition strategy, and continuity bias.
Iterations30Number of outer iterations. More iterations allow better convergence but take longer. 20-50 is a good working range; complex images may benefit from 80-100.
Agents0 (auto)Number of ants in the swarm. 0 auto-scales to the square root of the pixel count (e.g. ~512 for a 512x512 working image). Increase for denser coverage; decrease for speed.
Resampling2Image downsampling factor before processing. 1 = full resolution, 2 = half each dimension (4x fewer pixels), 4 = quarter. Higher values run faster but lose fine detail. Start at 2 and decrease to 1 if small-aperture fractures are missed.

Pheromone Parameters

PropertyDefaultDescription
Pheromone0.10Local pheromone update rate. Controls how strongly each ant visit reinforces the heuristic signal at that cell. Higher values make ants converge faster on strong edges; lower values preserve exploration. Range: 0.01 - 0.5.
Evaporation0.05Global pheromone evaporation rate per iteration. A fraction of all pheromone evaporates after each outer iteration, preventing saturation on early-discovered features and allowing the swarm to adapt. Range: 0.01 - 0.2.

Advanced Parameters

PropertyDefaultDescription
Alpha1.0Pheromone exponent in the transition probability. Higher values make ants follow established pheromone trails more strongly (exploitation).
Beta3.0 (edge) / 2.5 (trace)Heuristic exponent. Higher values make ants prioritise cells with strong edge evidence regardless of existing pheromone (exploration of the image signal).
Exploration0.15Probability that an ant ignores both pheromone and heuristic and moves to a random valid neighbour. Prevents premature convergence. Range: 0.0 - 0.5.
Ant Respawn Rate0.02 (edge) / 0.005 (trace)Per-step probability that an ant is teleported to a new random position. Higher values give broader image coverage; lower values allow individual ants to trace longer features.

Tuning Guide

Noisy images (weathered surfaces, lichen cover)

  • Increase Resampling to 3 or 4 to suppress pixel-scale noise
  • Increase Iterations to 40-60 so pheromone can accumulate above the noise floor
  • Increase Exploration to 0.2-0.3 to prevent ants clustering on noise speckle

Fine fractures in high-resolution photos

  • Set Resampling to 1 (full resolution)
  • Increase Agents to 1000-2000 for sufficient coverage
  • Use Trace mode and keep Ant Respawn Rate low (0.002-0.005) so ants can follow hairline fractures across the full image

Multiple fracture orientations

  • Use Edge mode for an initial pass (no directional bias)
  • Or use Trace mode with higher Exploration (0.25-0.3) so the swarm is not locked into a single dominant set

Fast preview

  • Set Resampling to 4, Iterations to 10, Agents to 200
  • This gives a rough result in seconds for parameter scouting before a full-resolution run

Weak contrast (low-aperture fractures on uniform lithology)

  • Increase Beta to 4.0-5.0 to amplify the heuristic signal
  • Decrease Evaporation to 0.02 so accumulated pheromone persists longer
  • Use Trace mode so the elitist bonus reinforces the best-detected paths

Output

The ACO produces a pheromone confidence map at the original image resolution. Each pixel value represents how strongly the swarm identified that location as part of an edge or fracture.

  • The map is displayed as a colour overlay on the photograph, blended using the current mask opacity setting
  • The logit histogram is shown in the properties panel; drag the filter threshold to isolate high-confidence features
  • A binary edge map (BMP) is saved next to the source image file, thresholded using Otsu's method. The filename includes the mode, iteration count, and pheromone parameters for traceability

Algorithm Overview

The algorithm places a population of artificial ants on a 2D pixel lattice derived from the input photograph. At each step every ant moves to a neighbouring pixel chosen probabilistically, biased by:

  1. Heuristic evidence at the neighbour (structure-tensor gradient energy or coherence, depending on mode)
  2. Accumulated pheromone from prior ant visits
  3. Directional continuity with the ant's previous heading (Trace mode only)

When an ant visits a cell it deposits pheromone proportional to the local heuristic value. After each outer iteration the pheromone map evaporates globally, weakening signals that are not continuously reinforced. Over many iterations, pheromone concentrates on genuinely salient features and fades from noise.

Each ant maintains a short-term memory (tabu list) of recently visited cells, preventing immediate backtracking. In Trace mode this memory is longer (24 cells vs 8), encouraging forward progress along linear structures.

The heuristic is derived from the image structure tensor, a 2x2 matrix of smoothed gradient products at each pixel whose eigenvalues describe local intensity variation. The dominant eigenvalue measures gradient energy (strong at any edge), while the difference between eigenvalues measures coherence (strong only at locally linear features, weak at corners and isotropic texture). This makes the coherence heuristic particularly selective for fracture traces.