A physics-grounded, zero-allocation computational Image Signal Processor (ISP) and digital night vision engine engineered in Rust and C99/C++17, spanning high-throughput desktop multi-core processors and resource-constrained microcontrollers (#![no_std]).
NightVision is architected around two synchronized backends sharing deterministic noise physics and bidirectional tone models:
-
nightvision-core(Desktop & Edge SoC Engine):- Multi-threaded planar
$Y, C_b, C_r$ zero-allocation ISP processor (PlanarIspProcessor). - Physics-gated
$3\times3$ guided filter ($r=1$ ) and continuous$1.25\times$ pre-tone detail injection. - Sustains 360.5 to 438.7 FPS (
$2.28\text{ ms}$ to$2.77\text{ ms}$ ) on 600Γ400 low-light frames.
- Multi-threaded planar
-
nightvision-mcu(Embedded Fixed-Point Streaming Engine):- Zero-allocation 3-line circular sliding buffer (
LineBuffer3), consuming 1.8 KB to 2.3 KB SRAM across typical sensor resolutions. -
#![no_std]streaming pipeline utilizing single-cycle bit-shifted arithmetic (>> 2,>> 3) and precomputed 8-bit Flash tables. - Sustains 166.0 to 232.9 FPS (
$4.29\text{ ms}$ to$6.02\text{ ms}$ ) on 600Γ400 low-light frames with zero runtime heap allocations.
- Zero-allocation 3-line circular sliding buffer (
-
C99/C++17 Firmware API & Tables (
include/nightvision.h,include/nightvision_tables.h):- Zero-SRAM Flash lookup tables (3.50 KB Flash /
.rodata, 0 bytes SRAM) for STM32H7, ESP32-S3, RP2040, and RISC-V targets. - Single-cycle unsharp mask macro:
#define NIGHTVISION_UNSHARP_MASK_1_25X(orig, blur)with safe intermediate integer casting and saturation clamping.
- Zero-SRAM Flash lookup tables (3.50 KB Flash /
For complete mathematical derivations, memory footprint calculations, and empirical benchmark matrices across extreme low light and photodiode saturation, see the technical whitepaper: π docs/ARCHITECTURE_AND_BENCHMARKS.md
NightVision/
βββ Cargo.toml # Cargo workspace configuration
βββ CMakeLists.txt # C/C++ interface & CMake export
βββ include/ # C/C++ embedded public headers
β βββ nightvision.h # C-API engine definitions & line processors
β βββ nightvision_tables.h # Static .rodata Flash lookup tables (3.50 KB)
βββ docs/
β βββ ARCHITECTURE_AND_BENCHMARKS.md # Unified technical whitepaper & benchmark suite
βββ assets/
β βββ benchmarks/ # 5-panel panoramic comparison strips
βββ crates/
β βββ nightvision-core/ # Zero-allocation planar ISP and physics engine
β βββ nightvision-mcu/ # #![no_std] fixed-point 3-line streaming engine
β βββ nightvision-cli/ # CLI batch processor, benchmark harness, and header exporter
β βββ nightvision-gui/ # Real-time native desktop viewer (egui / eframe)
Models physical photon starvation across natural lighting environments:
-
Overcast Night (
$0.0001,\text{lux}$ ): Extreme photon starvation ($< 0.1,e^-/\text{pixel}$ ). -
Clear Starlight (
$0.001,\text{lux}$ ): Heavy Poisson shot noise + Gaussian read noise. -
Quarter Moon (
$0.01,\text{lux}$ ): Deep shadow noise regime. -
Twilight (
$1.0,\text{lux}$ ): Low-light transition.
Photon flux is accumulated across consecutive frames to boost Signal-to-Noise Ratio:
Implements an
-
Multi-Scale Retinex with Color Restoration (MSRCR) decomposes illuminance and reflectance across Gaussian scales (
$\sigma \in {15, 80, 200}$ ). - CLAHE partitions luminance into contextual tiles, clipping histograms at strict thresholds to prevent noise explosion in pitch-black tiles, with bilinear interpolation eliminating tile seams.
- Digital Auto-Gating: Detects high-luminance flares and applies instant local tone compression ($I / (1 + 0.4I)$) protecting the observer's night-adapted eyes.
- Full-Color DNV: Full natural RGB color with white balance color constancy.
- Tactical White Phosphor (P45): Cool silver-white phosphor preferred by modern special operations for maximum visual acuity.
-
Tactical Green Phosphor (P43): Classic military Gen 3 green peak (
$545,\text{nm}$ ) with phosphor persistence. - High-Contrast Recon: Edge-boosted amber phosphor for reading text and identifying targets.
- Thermal Fusion: Ironbow pseudo-thermal colormap fused with optical outlines.
- Rust:
1.80+(cargoandrustc) - uv: Modern fast Python package manager
Simulates raw CMOS capture in starlight and quarter-moon, runs temporal accumulation, renders all tactical modes, and generates side-by-side comparison images:
cargo run --release --example demo -- --resolution 640x480 --frames 12The output images will be stored in output/demo/:
00_reference_ground_truth.png01_starlight_raw_cmos_single.png(raw CMOS static noise)02_starlight_enhanced_full_color.png(enhanced full-color night vision)03_starlight_white_phosphor.png(tactical P45 white phosphor)03_starlight_green_phosphor.png(tactical P43 green phosphor)04_starlight_side_by_side_comparison.png(multi-view composite)
Measures processing latency and sustained frame rates across VGA, HD 720p, and Full HD 1080p:
cargo run --release -p nightvision-cli -- benchmark --iterations 20Launches the native desktop dashboard with real-time sliders for Lux, Exposure, Temporal depth, Denoise radius, and live mode switching:
cargo run --release -p nightvision-guiCalculate quantitative PSNR and SSIM between ground truth and enhanced frames:
cd python
uv run scripts/evaluate.py ../output/demo/00_reference_ground_truth.png ../output/demo/02_quarter_moon_enhanced_full_color.pngGenerate the publication-ready SNR vs. Lux enhancement curve:
uv run scripts/benchmark_curves.pyEvaluated across real-world photon-starved captures (600x400 native resolution) comparing the multi-threaded Desktop FPU engine (nightvision-core) against the embedded fixed-point streaming engine (nightvision-mcu):
| Scene ID | Raw Luma (Mean) | Raw Range | Desktop FPU (FPS / ms) | MCU Stream (FPS / ms) | Desktop Lap. Var | MCU Lap. Var | PSNR (dB) | SSIM | AEC Regime |
|---|---|---|---|---|---|---|---|---|---|
10.png |
14.1 | 0..36 | 375.1 FPS (2.67 ms) | 226.2 FPS (4.42 ms) | 1765.7 | 1817.7 | 33.21 dB | 0.9894 | LowLight (+2.8 EV) |
100.png |
9.1 | 0..60 | 438.7 FPS (2.28 ms) | 218.0 FPS (4.59 ms) | 2672.5 | 2505.7 | 31.42 dB | 0.9878 | LowLight (+3.5 EV) |
114.png |
5.3 | 0..65 | 360.5 FPS (2.77 ms) | 224.8 FPS (4.45 ms) | 4180.1 | 5352.7 | 30.33 dB | 0.9672 | UltraDark (+4.3 EV) |
115.png |
10.2 | 0..227 | 412.3 FPS (2.43 ms) | 232.9 FPS (4.29 ms) | 2352.3 | 2403.2 | 31.83 dB | 0.9907 | LowLight (+3.3 EV) |
117.png |
6.0 | 0..53 | 362.0 FPS (2.76 ms) | 166.0 FPS (6.02 ms) | 3783.9 | 4554.1 | 31.74 dB | 0.9725 | UltraDark (+4.1 EV) |
121.png |
5.0 | 0..92 | 369.3 FPS (2.71 ms) | 221.3 FPS (4.52 ms) | 4492.4 | 5348.6 | 30.55 dB | 0.9711 | UltraDark (+4.3 EV) |
Each panorama displays 5 synchronized panels from left to right:
[1. Raw Low-Light Input | 2. Desktop Color | 3. MCU Color | 4. Desktop White Phosphor | 5. MCU White Phosphor]
Evaluated across extreme photodiode well saturation (
| Image File | Optical Regime | Native Resolution | Raw Luma [Range] | Desktop FPU (FPS / ms) | MCU Stream (FPS / ms) | Desk / MCU Lap. Var | PSNR / SSIM | AEC Regime & Rec. EV |
|---|---|---|---|---|---|---|---|---|
High10.jpeg |
100% Saturation Ceiling | 960Γ1280 | 255.0 [255..255] | 41.5 FPS (24.1 ms) | 34.1 FPS (29.3 ms) | 0.0 / 0.0 | 100.0 dB / 1.0000 | FullSaturation (-7.0 EV) |
Room_Window_Overexposed.jpg |
Severe Window Flare & Washout | 768Γ1024 | 251.2 [181..255] | 65.0 FPS (15.4 ms) | 49.2 FPS (20.3 ms) | 987.6 / 1008.7 | 33.53 dB / 0.9959 | FullSaturation (-6.7 EV) |
High_Glare_Bloom.png |
Diffuse Outdoor Glare | 640Γ480 | 214.4 [65..255] | 97.5 FPS (10.3 ms) | 118.2 FPS (8.5 ms) | 4444.6 / 4444.6 | 16.94 dB / 0.9918 | HighExposure (-1.0 EV) |
High_Overexposed_Toys.png |
Direct Spotlight Wash | 600Γ400 | 224.8 [80..255] | 169.3 FPS (5.9 ms) | 144.6 FPS (6.9 ms) | 36671.4 / 36671.4 | 17.76 dB / 0.9855 | FullSaturation (-5.7 EV) |
VivoBook_Screen.jpg |
Mixed Screen & Dark Keyboard | 768Γ1024 | 64.8 [0..254] | 63.2 FPS (15.8 ms) | 54.2 FPS (18.5 ms) | 2504.4 / 1819.7 | 28.39 dB / 0.9931 | NormalDaylight (+0.7 EV) |
Recovers washed-out foreground from 91.6% saturation using min-RGB dark channel guidance and full-range dehaze ($\gamma=3.2$), expanding dynamic range by 3.2x (floor dropped 181 β 18 ADU) and boosting edge acuity by 56x (Laplacian Var 17.7 β 1008.7) with authentic pastel highlight roll-off in P43 Green Phosphor.

Lifts dark keyboard shadows while preserving bright text on the emissive screen (+88.5% edge definition).

Concave power shoulder ($x_{\text{knee}} = 140\text{ ADU}, \gamma = 2.2$) recovers plush embroidery (+305% Desktop Lap. Var).

Following empirical benchmarking across physical, spatial, and generative highlight synthesis pipelines on extreme overexposure (
| Approach Tested | Visual Outcome on Blown Portrait & Window | Real-Time / Production Fit | Verdict |
|---|---|---|---|
Stage 1 Physical ISP (isp.rs + mcu_pipeline.rs: glare floor inversion + 55/45 power LUT) |
Deep crisp blacks, intact vibrant cyan doorframe ( |
|
SHIP (Primary Production Engine) |
Hardware AEC Telemetry (fast_aec_probe + AecSensorCommand) |
Prevents highlights from hitting |
|
SHIP (Live Real-Time Streams) |
| Spatial Chroma Heuristics (1-Jet, PatchMatch, Push-Pull Chroma, Scanline EMA) | Metallic craters, grey bleached moats, cyan doorframe wiped to concrete grey ( |
Inconsistent across diverse scenes, breaks generality | DROPPED |
| SD 1.5 + LCM-LoRA Inpainting (OpenVINO Iris Xe GPU) | Recovered facial structure in tight crops, but full-frame latent downsampling ( |
|
DROPPED |
ONNX Face Restorers (GFPGAN v1.4, CodeFormer w=0.5 / 0.8) |
Bit-exact outside face ( |
|
DROPPED |
When a photodiode is triple-clipped at



