demosaic: add Menon (2007) DDFAPD and ARI algorithms#20800
demosaic: add Menon (2007) DDFAPD and ARI algorithms#20800dregsist wants to merge 4 commits intodarktable-org:masterfrom
Conversation
Add two new Bayer demosaicing methods: - Menon (2007) DDFAPD: directional filtering with a posteriori decision - ARI: adaptive residual interpolation with quality levels (fast/balanced/quality) Both are CPU-only, OpenMP parallelized. Introspection v6->v7 migration added. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
rawprepare can produce negative pixel values; clamp to zero at the start of Menon processing, consistent with how RCD handles this case. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
rawprepare can produce negative pixel values. Create a clamped copy of the input at the entry of ari_demosaic so that all gradient and residual computations (which depend on consistent non-negative data) see a uniform view of the CFA. Mirrors the approach used in RCD. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
| @@ -0,0 +1,551 @@ | |||
| /* | |||
| This file is part of darktable, | |||
| Copyright (C) 2024-2025 darktable developers. | |||
There was a problem hiding this comment.
only 2026 obviously. And the same header must be added into ari.c.
| /* Helper: mirror-boundary 1D horizontal convolution with a 3-tap kernel. | ||
| kernel[] is indexed [-1..+1] stored as kernel[0..2]. */ | ||
| static inline float _menon_cnv_h3(const float *const restrict buf, | ||
| const int row, const int col, |
There was a problem hiding this comment.
style: one parameter per line (there is quite some instances of this).
- Update copyright year to 2026 in menon.c - Replace custom header in ari.c with standard darktable GPL header - Split multi-parameter function signatures to one parameter per line in both ari.c and menon.c (style requirement) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Thank you for the review!
|
|
Would you be able to hint at raw images plus the region to inspect where you think there is an improvement over current demosaicers? Menon is ~half performance of rcd here, can you confirm? Btw there definitely is room for perf gains by internal tiling. |
|
Can we use the integration test repo images to have a quantitative comparison between demosaicers? |
nope. |
|
Thank you @jenshannoschwalm for running the comparison — I'll investigate first — likely a bug in the R/B interpolation After that, planning to:
@da-phil yes, will include results against the integration test images as well. |



Summary
darktable's demosaicing lineup covers the speed-vs-quality axis well at
the extremes (VNG/PPG for speed, AMaZE for quality), but the mid-range
lacks per-pixel adaptive selection. This PR adds two algorithms that
fill that gap:
Menon (2007) — Directional De-mosaicing for Frequency-Adaptive
Pattern (DDFAPD): a two-pass algorithm that separates horizontal and
vertical interpolation and merges them via local gradient energy
weighting. Produces sharp edges with reduced zipper artifacts at a
cost comparable to RCD.
ARI — Adaptive Resolution Interpolation (Monno et al. 2017):
generates multiple green-channel candidates (MLRI via Laplacian
energy direction, and HA via Hamilton-Adams), then selects per-pixel
using noise-adaptive criteria. Three quality levels: Fast (MLRI only),
Balanced (2 candidates), Quality (3 candidates with guided-filter
smoothing on color differences). ARI's per-pixel candidate selection
also addresses the same high-ISO use case as the existing
AMaZE+bilinear blend, without requiring manual threshold tuning.
Implementation notes
existing RCD and LMMSE modules.
at algorithm entry, consistent with RCD's
_safe_in()approach.qualityparameter (1–3) in the UI; stored in theparams struct, version bumped 6→7 with legacy_params migration.
procmaxscaler used by RCD/LMMSE.References
Filtering and a posteriori Decision," IEEE Trans. Image Process.,
vol. 16, no. 1, pp. 132–141, Jan. 2007.
Interpolation for Color and Multispectral Image Demosaicking,"
Sensors, vol. 17, no. 12, 2807, 2017.
Testing
test targets.
bilinear and VNG on high-ISO crops.
AMaZE) confirmed.