Offer SCUNet and NLM alongside the guided denoise

The AI denoise panel now picks between three bases: the existing guided
filter, non-local means and a learned SCUNet model run through
onnxruntime-node on overlapping tiles. The base is part of the render key, so
each model keeps its own cached render and switching back is instant, and jobs
report stage and tile progress instead of a bare spinner.

onnxruntime-node is pinned to 1.23.0, the last release that ships both macOS
architectures, and every Docker and desktop install skips its CUDA download
because only the CPU binaries in the package are used. The SCUNet weights and
ONNX Runtime are added to the third-party notices, the deb copyright file and
the README's denoise, API and redistribution sections.
This commit is contained in:
2026-12-01 04:03:53 +00:00
parent b34d34dacb
commit f7942d0bd0
26 changed files with 945 additions and 161 deletions
+55 -21
View File
@@ -442,7 +442,7 @@ Node server (node:http, port 8787)
raw.mjs LibRaw demosaic, embedded-preview fallback
libraw-*.mjs Node <-> browser shim and decoder worker pool
imaging.mjs sharp encode/resize, dependency-free PNG fallback
denoise.mjs job queue and on-disk render cache
denoise.mjs denoise queue, base selection and render cache
quota.mjs usage accounting, prune plans, warnings, worker
mail.mjs nodemailer transport, admin-editable settings
bridge.mjs dashboard token verification and metadata import
@@ -453,7 +453,7 @@ Data directory
originals/ uploaded files, byte-for-byte, original extension kept
previews/ editable JPEG proxies (raw) and normalised previews
thumbs/ grid thumbnails (server-rendered proofs are 560 px)
denoised/ full-strength denoise renders keyed by pipeline version
denoised/ full-strength denoise renders, one per base model
proofs/ rendered proofs for client galleries
proofThumbs/ thumbnails of those proofs
```
@@ -534,7 +534,7 @@ that predate workspaces are assigned to the oldest account.
| `originals/` | `<photo id>.<original ext>` | Uploaded bytes, untouched; extension preserved |
| `previews/` | `<photo id>.jpg` or `.png` | Editable proxies; PNG when `sharp` is unavailable |
| `thumbs/` | `<photo id>.jpg` | Grid thumbnails; server-rendered proof thumbnails are 560 px |
| `denoised/` | `<photo id>.<key>.jpg` | Key encodes the pipeline version; old keys are pruned |
| `denoised/` | `<photo id>.<key>.jpg` | Key encodes the pipeline version and the base model; one render is kept per model |
| `proofs/` | `<photo id>.jpg` | Rendered client-gallery proofs |
| `proofThumbs/` | `<photo id>.jpg` | Thumbnails of those proofs |
@@ -596,8 +596,8 @@ routes are public and are gated only by the share token.
| GET | `/api/photos/:id/preview` | owner | Stream the editable proxy |
| GET | `/api/photos/:id/thumb` | owner | Stream the thumbnail (proof thumbnail first, if present) |
| POST | `/api/photos/:id/proof` | owner | Store a rendered JPEG proof and its thumbnail from base64 |
| POST | `/api/photos/:id/denoise` | owner | Queue a full-strength denoise render; returns a job id |
| GET | `/api/denoise/jobs/:id` | session | Job state: running/done/error, timing, stats, cache hit |
| POST | `/api/photos/:id/denoise` | owner | Queue a full-strength render; body `{"base": "guided" \| "scunet" \| "nlm"}`, default `guided`; returns a job id |
| GET | `/api/denoise/jobs/:id` | session | Job state: running/done/error, `progress` (`stage`, `done`, `total` tiles), `ms`, `bytes`, `stats` and `cached` for a cache hit |
| GET | `/api/photos/:id/denoised?v=<key>` | owner | Stream the cached denoise render |
| DELETE | `/api/photos/:id/denoised` | owner | Drop all denoise renders for the photo |
| GET | `/api/quota` | session | The caller's quota state |
@@ -922,26 +922,52 @@ busy count.
## Detail-preserving denoise
`server/denoise/` is a dependency-free pipeline (planes, noise estimation, colour,
detail, RGB reconstruction) adapted from the `raw-noise` project. It reconstructs each
pixel as a crossfade between the source and a denoised base, so the result is bounded by
the original pixels and cannot ring or overshoot: flat noise is replaced, structure is
handed back verbatim.
`server/denoise/` is Luminary's denoise pipeline: planes, noise estimation, colour,
detail and RGB reconstruction, adapted from the `raw-noise` project, driving one of three
base denoisers. The result is a per-pixel crossfade between the source and the denoised
base, so it is bounded by the original pixels and cannot ring or overshoot: flat noise is
replaced, structure is handed back verbatim.
**Provenance.** `raw-noise` is not published on npm, and no copyright or licence notice
for it is included in this repository. Before redistributing Luminary, add the origin's
notice and terms to `server/denoise/`, or replace that folder with an independently
licensed implementation.
The **AI denoise** panel offers the three bases in this order:
| Base | Implementation | One 256 × 256 test frame |
| --- | --- | --- |
| **Guided** (default) | Guided filter in the copied pipeline; fastest, keeps the most fine texture | 0.06 s |
| **SCUNet** | Learned colour denoiser `server/denoise/scunet_color_25.onnx`, run through `onnxruntime-node` on 256 px tiles with a 32 px overlap | 12.1 s (4 tiles) |
| **NLM** | Non-local means in the copied pipeline; slower than Guided, smooths less than SCUNet | 0.43 s |
Timings are what the three bases measured here on a 256² noisy frame; a full frame costs
more in proportion to its area (and SCUNet to its tile count). The base is stored per
photo in `aiDenoise.model` and is part of the render key, so switching models does not
invalidate another model's render. SCUNet is the only path that needs
`onnxruntime-node`; it is imported lazily, so Guided and NLM keep working when the native
binding cannot load. The package is pinned to `1.23.0`, the last release that ships both
macOS architectures, and its install step is skipped in the Dockerfile and the desktop
builds (`ONNXRUNTIME_NODE_INSTALL=skip`) because only the CPU binaries in the package are
used.
**Provenance and licences.** `raw-noise` is not published on npm, and no copyright or
licence notice for it is included in this repository. Before redistributing Luminary, add
the origin's notice and terms to `server/denoise/`, or replace that folder with an
independently licensed implementation. The SCUNet weights are Apache-2.0 (upstream
`cszn/SCUNet`, ONNX export by `Heliosoph/scunet-onnx`) and ONNX Runtime is MIT; both are
listed in [`THIRD_PARTY_NOTICES.md`](THIRD_PARTY_NOTICES.md).
- The server always renders the full-strength denoise and the GPU blends it, so the
Amount slider is instant, one file serves every amount, and the amount cannot be
applied twice.
- Renders are cached in `denoised/` under a key that includes `PIPELINE_VERSION`. Bump
that constant whenever the copied pipeline changes output, or stale renders will be
served as current.
- Renders are cached in `denoised/` as `<photo id>.<key>.jpg`, where the key is the first
12 hex characters of `sha1(photoId|PIPELINE_VERSION|base)`. One render is kept per
model, so switching back to a model is instant; a finished run prunes only keys from an
older pipeline version. Bump `PIPELINE_VERSION` in `server/denoise.mjs` whenever the
copied pipeline or the SCUNet tiling changes output, or stale renders will be served as
current.
- Each run is seconds of CPU, so jobs go through a capped queue
(`LUMINARY_DENOISE_WORKERS`, default `min(4, cores−1)`). A second request for the same
photo joins the run already in progress instead of starting an identical one.
photo and base joins the run already in progress instead of starting an identical one,
and a request whose render already exists returns at once with `cached: true`.
- While a job runs it reports `progress` (`stage` and, for SCUNet, the tile count), which
the panel turns into a real status line instead of a spinner.
- The job table keeps the newest 40 entries and never drops a queued or running job.
---
@@ -997,6 +1023,11 @@ positions. Camera-lens defaults require both a normalised camera and lens name t
| `npm run predeploy` | Typecheck, unit suite, render check, then build — run this before pushing a deploy; the build is skipped when only test files changed since the last build |
| `npm run deploy` | Predeploy gate, then rsync, remote build, restart and bundle-hash check (see [Production deployment](#production-deployment)) |
`npm install` also installs `onnxruntime-node` for the SCUNet denoise base. Its install
step downloads the CUDA build (~350 MB) unless `ONNXRUNTIME_NODE_INSTALL=skip` is set
before the install; the Dockerfile and the desktop builds set it, because only the CPU
binaries that ship inside the package are used.
### Continuous integration
`.gitea/workflows/ci.yml` runs on every push and pull request: `npm ci`,
@@ -1007,8 +1038,9 @@ built and attached by hand; the workflow is what keeps `main` buildable.
Conventions worth knowing before changing code:
- The server is plain ESM (`.mjs`) with no build step. Keep it framework-free and avoid
native modules; `node:sqlite` is deliberate, and `sharp` must stay optional.
- The server is plain ESM (`.mjs`) with no build step. Keep it framework-free; native
modules stay optional — `node:sqlite` is deliberate, `sharp` must stay optional, and
`onnxruntime-node` is loaded lazily and only for SCUNet.
- The client is strict TypeScript with `noEmit`; Vite builds only `src/` and `public/`.
- Edits are data, not pixels: adding a control means extending `src/types.ts`, the
renderer uniforms/shaders, `normalizeEdits()` defaults, the export path and the panel
@@ -1213,7 +1245,9 @@ full CC BY-SA 3.0 text. Before distributing Luminary or its container image:
(OFL-1.1) and DejaVu Sans Mono (Bitstream Vera licence) — with any redistributed
copy.
7. Record the terms of the `server/denoise/` pipeline's `raw-noise` origin; it is not
published on npm and its licence is currently undocumented here.
published on npm and its licence is currently undocumented here. The SCUNet weights
and ONNX Runtime are already catalogued in `THIRD_PARTY_NOTICES.md`; ship that file
and the model's `.onnx.data` shard with the app.
### No endorsement