SPB Git

Repository Public License

computational-photography.md 6.1 KB 88 lines markdown

1<!--2ORIX Camera3File: docs/architecture/computational-photography.md4Author: Simon-Pierre Boucher5Contact: contact@spboucher.ai6-->78# Computational Photography910Four pipelines, all in `Packages/ORIXCameraKit/Sources/ORIXImaging/Computational/`, all operating on gamma-encoded values in 32-bit float. They are ORIX Camera's own; none uses or imitates Apple's private processing.1112Shared type: `FloatImage`, three planar float arrays (R, G, B, 0…1), with conversions from BGRA buffers and CGImages and to 8-bit buffers and **16-bit** CGImages.1314## 1. FrameAccumulator: long exposure and light trails1516| Mode | Per frame | Result |17|---|---|---|18| `mean` | `sum += frame` (vDSP_vadd) | `sum / (255 · N)` |19| `lighten` | `sum = max(sum, frame)` (vDSP_vmax) | `sum / 255` |2021Frames are converted row by row from 8-bit to float into a small scratch buffer, so the working memory is three float planes: 12 bytes per pixel (25 MB at 1080p, 100 MB at 4K). Frames of another size or format are rejected.2223In the app: the shutter starts the accumulation with a frame limit of `seconds × frame rate`; the monitor shows `result()` converted to 8 bits about every 450 ms; reaching the limit, or pressing the shutter again, finishes it. Fewer than two frames is reported as a failure.2425**Honest naming.** Averaging N short exposures approximates one exposure N times longer for motion and noise; it does not gather more light per frame and it cannot recover highlights a single frame clipped. The tool's description says "A computed long exposure, not a long shutter."2627**Resolution.** Output is at the live stream's resolution.2829Tests: mean of constants; maximum of constants; rejected sizes; a moving light draws a ring under `lighten` while never darkening any pixel; `mean` blurs the moving light and leaves a static patch unchanged; the 16-bit output keeps sub-code-value precision (100.5/255 survives).3031## 2. StackDenoiser: night stack3233The first frame is the reference. Each later frame s is merged per pixel and per channel:3435```36d  = s − r                          r = reference37w  = τ² / (τ² + d²)                 τ = 0.06 by default38num += w · s        den += w        (both start at r and 1)39result = num / den40```4142Where the scene is static, d is only noise, w ≈ 1, and the result approaches a plain average: noise standard deviation falls roughly with √N. Where something moved, d is large, w → 0, and the reference pixel survives: no ghost.4344Frames can be shifted by whole pixels before merging; rows and columns that fall outside are left out of the sums.4546Tests: eight noisy copies of a static image gain more than 6.5 dB PSNR (ideal averaging gives 9 dB); a square moving across five frames leaves no ghost where a plain mean would; a shifted frame merges in place.4748## 3. ImageAligner: registration4950`VNTranslationalImageRegistrationRequest` gives the translation that maps a frame onto the reference; the app rounds it to whole pixels.5152**Plausibility guard.** A shift larger than 8 % of the frame side is rejected (`maxShiftFraction`). During development, a periodic test texture made Vision return a 131-pixel shift for a 4-pixel displacement: registration can lock onto the wrong structure. A rejected frame is **skipped and counted**, never merged at a wrong offset. If fewer than two frames remain, the capture fails with "The frames could not be aligned. Hold the camera steady or use a tripod."5354Only translation is corrected. Rotation and parallax are not: these modes are for a tripod or steady hands.5556## 4. ExposureFusion: bracket fusion5758Mertens, Kautz and Van Reeth (2007). For each exposure k a weight map:5960```61W_k = C_k^wc · S_k^ws · E_k^we + 10⁻⁶62C = |Laplacian of luma|                       contrast63S = standard deviation of R, G, B             saturation64E = Π_c exp(−(c − 0.5)² / (2σ²)),  σ = 0.2    well-exposedness65```6667Weights are normalised across exposures. Each weight map becomes a Gaussian pyramid; each channel of each exposure becomes a Laplacian pyramid; the fused pyramid is the weighted sum level by level; collapsing it gives the result, clipped to 0…1. Blending per frequency band is what prevents seams and halos where the weights change.6869Pyramid operators: 5 × 5 binomial blur and resampling with vImage. The Laplacian level is defined as `G_l − up(G_{l+1})` with the same `up` used when collapsing, so reconstruction is exact for any resampling filter; a test confirms it to 10⁻⁴.7071**Memory.** Sources are held as 8-bit RGBA and float planes are produced one at a time. Measured peak for three exposures (`orix-bench fusion`, `/usr/bin/time -l`): 542 MB at 6 MP, 720 MB at 8 MP, 929 MB at 12 MP. `CameraModel.fusionPixelBudget` therefore limits the working size by physical memory: 4 MP under 5 GB, 6 MP under 7 GB, 8 MP under 11 GB, 12.5 MP above. Brackets are decoded at reduced size when they exceed the budget.7273In the app: `captureBracket` requests −N, 0, +N EV (or −N, +N if only two frames are allowed) at 12 MP or less; frames are aligned to the middle exposure; unalignable frames are dropped; at least two must remain. The work runs in a detached task.7475Tests: identical inputs return the input (PSNR above 50 dB); a scene with a dark half and a bright half, shot under and over, shows texture in both halves after fusion and in only one half of each source; size mismatches and empty input throw.7677## Saving multi-frame results7879`saveComputed` turns the float result into a 16-bit image, rotates it upright (the capture angle, baked into pixels), and encodes HEIC at quality 0.95, or 16-bit TIFF when "16-bit TIFF for computational captures" is on. The capture summary (frame count, duration, bracket, frames skipped) is stored in the EXIF user comment and in the library index.8081## Evaluated, not shipped8283| Technique | Why not in 1.0 |84|---|---|85| Focus stacking | needs per-frame focus bracketing on a device, sharpness maps and alignment under focus breathing; cannot be validated without hardware |86| Panorama | needs feature matching, homography estimation, seam finding and exposure matching; a fabricated or fragile result would be worse than none |87| Full-resolution long exposure | would require bursts of full-size stills; left for after device measurements |88
Files main
Menu

Theme