Files
luminary/server/denoise/baseDenoiser.ts
T
bhursey f7942d0bd0 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.
2026-12-01 04:03:53 +00:00

39 lines
1.4 KiB
TypeScript

/**
* Resolve a base denoiser by name -- the slot the pipeline calls as `runBase`.
*
* Three choices, all occupying the same interface from `standin.ts`:
*
* - `guided` (default): the classical guided filter. Fast, edge-preserving,
* the current shipping path.
* - `nlm`: non-local means. Slower, the quality reference the model must beat.
* - `scunet`: the learned SCUNet model, run tiled with overlap-add.
*
* Constructing is free: the ONNX session is created lazily on first use, so the
* model selector can show all three even before a run ever picks SCUNet. A
* missing model surfaces as a clear error at run time, not at import time.
*/
import { fileURLToPath } from 'node:url';
import { guidedDenoiser, nlmDenoiser, type BaseDenoiser } from './standin.ts';
import { createOnnxBaseDenoiser, type TileProgress } from './onnx.ts';
export type BaseDenoiserName = 'guided' | 'nlm' | 'scunet';
/** The SCUNet weights shipped with the server, next to this file. */
const SCUNET_MODEL = fileURLToPath(new URL('./scunet_color_25.onnx', import.meta.url));
export function createBaseDenoiser(
base: BaseDenoiserName,
onProgress?: (progress: TileProgress) => void,
): BaseDenoiser {
switch (base) {
case 'nlm':
return nlmDenoiser();
case 'scunet':
return createOnnxBaseDenoiser({ modelPath: SCUNET_MODEL, tile: 256, overlap: 32, onProgress });
case 'guided':
default:
return guidedDenoiser();
}
}