Vibe-Coding a Hologram Generator
If you've ever fiddled with inline holography, you know the “twin image” is the little horror movie that always plays during reconstruction. You try to pull a clean object out of an interference pattern and—boom—an unwanted mirror-ghost shows up, smearing things and ruining your metrics. What if we could train a neural network to hush that ghost? Better yet: what if we could churn out thousands of realistic synthetic holograms without living in the lab for six months?
Meet `HoloGen` — a Python toolkit I built by vibe-coding with an AI pair-programmer. It generates synthetic hologram datasets so you can train ML models to suppress twin images, test reconstruction methods, or just amuse yourself with simulated speckle patterns. And yes, it’s open source.
The Twin Image Problem (aka Why Holography Has a Stalker)
Quick primer: inline holography records interference between light scattered by an object and the unscattered reference beam. One-shot, simple optics—very elegant. The catch: when you numerically reconstruct, you get two overlapping images: the real object and its conjugate twin. They overlap, blur, and make accurate analysis annoyingly difficult.
Classical fixes: iterative phase retrieval, off-axis setups (more hardware), or clever filtering. These work, but they’re either slow, hardware-heavy, or finicky. What if a physics-aware neural network could learn to remove the conjugate while leaving the true image intact?
Physics-Aware SWIN Transformers to the Rescue
The plan: train Shifted Window (SWIN) transformers that don’t just learn pixel mappings but actually respect wave physics. These models need to learn Fresnel propagation, how twin images form, and how to suppress the conjugate while preserving phase and amplitude information.
Big problem: they need a ton of paired data — object ↔ hologram — with varied noise, aberrations, distances, etc. Collecting that in the real world is slow and expensive.
Vibe-Coding the Dataset Generator
from hologen import (
HologramConfig,
InlineHolography,
CircleGenerator,
SensorNoiseModel,
generate_hologram
)
# Generate a hologram with realistic sensor noise
config = HologramConfig(
image_size=512,
pixel_size=3.45e-6, # microns
wavelength=532e-9, # green laser
propagation_distance=0.01 # 1 cm
)
obj_field = CircleGenerator(radius=50).generate(config)
hologram = generate_hologram(obj_field, config, InlineHolography())
# Add sensor noise (shot noise, read noise, quantization)
noise_model = SensorNoiseModel(
read_noise_std=5.0,
dark_current_rate=0.1,
quantum_efficiency=0.8
)
noisy_hologram = noise_model.apply(hologram, config)Public dataset — intensity-only inline holograms (100k pairs, ≈157 GB)
Good news: you don’t have to start from scratch. There’s already a large, published dataset of intensity-only inline holograms — about 100,000 paired examples (roughly 157 GB) — hosted on Hugging Face. Think of it as a 157 GB buffet of holographic snacks: perfect as a training baseline or to augment HoloGen’s synthetic data. Note that this dataset provides intensity-only pairs (no complex phase ground truth), so if your SWIN model expects complex-field targets you’ll either need to reconstruct phase from the intensities or pair these real examples with HoloGen’s phase-aware simulations for a hybrid training strategy.

Coming Soon
Next step: train SWIN transformers on HoloGen datasets. Input: noisy inline holograms. Output: clean reconstructions with the twin suppressed. Key idea: make the network physics-aware — include the propagation operator in the loss so the model learns to respect the wave equation.
Vibe-Coding: the Future of Research Software?
Building HoloGen via AI-assisted vibe-coding was illuminating. The usual cycle — prototype, curse, rewrite, repeat — compresses into faster, iterative loops. I focused on physics and architecture; the AI helped with boilerplate, patterns, and catching dumb bugs.
Is it perfect? No. Is it usable, tested, and extensible? Absolutely. More importantly: it exists and works — unlike many research prototypes that die in notebooks.
The twin image has haunted holography since Gabor’s day (1948). Maybe neural nets can finally tell it to take a hike. And maybe vibe-coding is the shortcut that gets us there sooner — with fewer late-night lab runs and more coffee-fueled model training.