HaCI Debuts Bio-Inspired Fully Distributed Edge Detection Algorithm
A developer released HaCI (Harmonic Contour Integration), a compact, fully distributed bio-inspired algorithm for RGB edge detection, structured in four stages including pixel-level harmonic contrast, oriented pooling, and seed facilitation/suppression. The open-source work targets computer vision researchers and distributed-systems engineers rather than the LLM/agent space.
Full Report
Contents5 sections
HaCI: Harmonic Contour Integration
A compact, fully distributed algorithm that extracts edges from RGB images through four stages:
-
L0 — pixel harmonic contrast
Each pixel is compared to its eight neighbors in a learned luminance/chroma metric. Each direction's contrast is divided by its own energy plus a learned spatial pool of local contrast (contrast gain control). The result is a per-pixel harmonic field. -
L1 — oriented pooling
L0 harmonics are summed over small, overlapping patches on a sparse cell grid. Each cell gets eight orientation-tuned responses and a dominant orientationθ. -
Seed — facilitation and suppression
Each orientation response passes through Naka–Rushton gain control. Support from neighbouring cells along the contour (an association field with a learned curvature tolerance) scales the response and bridges gaps that have support on both sides. A divisive readout then divides each orientation response by the same orientation's response in the neighbouring cells, so a cell is coded relative to its same-orientation context. Parallel contours on both sides of a cell (flank suppression) divide it further, which damps texture and gratings but leaves a lone edge, or an edge beside a single parallel one, untouched. The result is per-cell contour densityρ. -
Render — ridge back-projection
Cellρis splatted back to full resolution with learned 1D kernels aligned to localθ, producing a soft boundary map. Non-max suppression yields the final edge map.
Paper: HaCI: Harmonic Contour Integration for Edge Detection, DOI 10.5281/zenodo.23403643.
For collaboration contact me on: [email protected]
Examples
Left: input image. Right: HaCI edge map from the bundled pretrained model.
Benchmarks
Scores for pretrained/final.pt on the BRIND test set (200 images; the model was trained on the 300-image BRIND train split). Evaluation uses the Berkeley boundary benchmark: 99 thresholds and maxDist 0.0075 (≈4.3 px on 481×321 images). Predictions are thinned before one-to-one matching; see Test.
| Output | ODS | Precision | Recall | OIS | AP |
|---|---|---|---|---|---|
NMS-thinned map (s_eval) | 0.7179 | 0.6791 | 0.7614 | 0.7402 | 0.7651 |
Raw soft map (c_eval) | 0.7158 | 0.6842 | 0.7505 | 0.7373 | 0.6723 |
Precision and recall are taken at the ODS threshold (0.71 for both maps).
Speed and memory, measured on MPS (Apple M4) with baselines/speed.py.
| Resolution | Time | Host memory | GPU memory |
|---|---|---|---|
| 481×321 | 36 ms | 124 MB | 1.1 GB |
| 1280×720 | 201 ms | 171 MB | 1.1 GB |
| 1920×1080 | 459 ms | 233 MB | 2.2 GB |
Structure
HaCI/
├── pyproject.toml
├── requirements.txt
├── params.py # all hyperparameters
├── train.py # HaCIE2E training
├── test.py # ODS, OIS, AP evaluation
├── infer.py # single-image inference + diagnostics
├── scripts/ # biped.sh, brind.sh, nyud.sh — fetch and lay out datasets
├── haci/
│ ├── L0.py # pixel-level contrast + gain control
│ ├── L1.py # cell-level z₂ moments (E, C, θ)
│ ├── seed.py # η_z NR + association field + same-orientation surround + flank suppression → cell ρ for splat
│ ├── renderer.py # learned ridge projection
│ ├── splat_metal.py # the renderer's splat as Metal kernels, used with --device mps
│ ├── boundary_bench.py # Berkeley boundary benchmark (ODS, OIS, AP)
│ ├── cli.py # `uv run train` / `test` / `infer` entry points
│ └── diagnostics_viz.py # visualisation utilities
├── data/ # BRIND, the default dataset (scripts/brind.sh)
│ ├── train/imgs, train/gt # 300 training pairs
│ └── test/imgs, test/gt # 200 evaluation pairs
├── BIPED/, NYUDv2/ # other datasets, same {train,test}/{imgs,gt} layout (scripts/)
├── pretrained/
│ └── final.pt # bundled weights — infer / test without training
└── output/
├── checkpoints/ # final.pt, intermediate.pt
└── test/{c_eval,s_eval}/ # results.json, eval_bdry*.txt, preds/Install
Python 3.12+.
Install everything from pyproject.toml / requirements.txt (includes CPU torch from PyPI).
uv:
uv syncpip:
pip install -r requirements.txtOptional — GPU Acceleration
Check for a Nvidia GPU
nvidia-smiFor CUDA, note the driver version in the output and pick the matching PyTorch index tag (e.g. CUDA 12.8 → cu128). See pytorch.org/get-started.
- Install non-torch dependencies (or full sync).
- Install CUDA
torchfrom the PyTorch wheel index — use--reinstallso it replaces the CPU build fromuv sync.
uv:
uv sync
uv pip install --reinstall torch --index-url https://download.pytorch.org/whl/cu128pip:
pip install torch --index-url https://download.pytorch.org/whl/cu128
pip install matplotlib>=3.10.8 numpy>=2.0.0 pillow>=12.1.0 pyyaml>=6.0.0 scipy>=1.17.1Replace cu128 with your tag. Do not run pip install -r requirements.txt after the CUDA wheel, as that will pin CPU torch.
Verify:
uv run python -c "import torch; print(torch.__version__, torch.cuda.is_available())"Expect True for the second value on the CUDA path. train, test and infer pick cuda when available, then mps on Apple silicon, then cpu (the choice is printed as device=...); pass --device cpu to force CPU.
On mps, the renderer's splat and its gradient run as Metal kernels (haci/splat_metal.py) and compute the same sums as the CPU path, so results agree up to float rounding.
(注:更多技术实现细节与完整 API 文档请查阅原项目 README)
作者发帖说明(HN):
Hi HN,
I've been working on a bio / visual cortex inspired edge detection algorithm. I released a preliminary version a couple of months ago, and I've been improving it since. Benchmark scores currently sit midway between old-school (Canny, Sobel), and modern deep nets, while having the former's interpretability.
I'm planning to develop this further for downstream use cases, maybe try to improve FPS for video and performance on different hardware.
For anyone interested in a collaboration you can find my email in the Readme. Engineers interested in computer vision frameworks / distributed systems, or anyone in academia following this line of research, feel free to reach out to me.