/** * 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(); } }