demosaic: add Menon (2007) DDFAPD and ARI algorithms#20800
demosaic: add Menon (2007) DDFAPD and ARI algorithms#20800dregsist wants to merge 5 commits intodarktable-org:masterfrom
Conversation
|
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. |
164e521 to
83fa112
Compare
Accompanies darktable PR darktable-org#20800 (Menon 2007 + ARI Monno 2015 demosaic). Contents: - BENCHMARK.md / BENCHMARK_JA.md: full writeup, English + Japanese - bench_*.py: reproducible scripts for Kodak-24 (low/mid/high ISO), SIDD medium (iso_clean/iso_noise), chroma zipper, iteration sweep - _paper_ari_ref.py / _paper_ri_ref.py: Python paper-exact references - test_*.c / test_amaze.cc: standalone C test harnesses - viewer_data_paper_vs_simple/: 5 Kodak edge images x 7 methods PNGs - refs/matlab/: authors' original MATLAB code (RI/MLRI/ARI) - dt_tests_dtbuild/mire1_*.jpg: end-to-end darktable integration Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The previous ARI implementation had quality issues (color fringing, maze patterns on mire1) because it cut too many corners in the adaptive selection heuristic. This rewrites ARI to match the Monno 2015 paper line-by-line (structurally equivalent to the authors' MATLAB reference, within ±0.002 dB CPSNR of a Python port). Quality is indeed better:
However, the paper-exact pipeline is slow:
Optimizations applied (all preserve paper-exact output):
Menon (2007) is separately included as a reference implementation. It is fast (~amaze speed), but benchmarking across Kodak-24 + SIDD-medium did not show a clear advantage over amaze — chroma zipper is similar or worse (especially cz_peak), and CPSNR is within 0.1 dB. Both algorithms looked strong on paper; extensive benchmarking showed neither clearly beats the existing methods across the tested conditions. I'll leave the merge decision to maintainers. The benchmark numbers themselves should be useful regardless; full writeup + reproducible scripts + Python reference ported from the original MATLAB are available at: https://github.com/dregsist/darktable-rawforge/tree/demosaic-benchmarks menon.c: keep the unused FIR/k_b locals (they're referenced via OpenMP firstprivate clauses) to fix -Werror=unused-variable with GCC 15. |
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>
- 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>
The previous ARI implementation had quality issues (color fringing, maze patterns on mire1) because it cut too many corners in the adaptive selection heuristic. This rewrites ARI to match the Monno 2015 paper line-by-line (structurally equivalent to the authors' MATLAB reference, within 0.002 dB CPSNR of a Python port). Quality is indeed better: - Kodak low-ISO CPSNR 39.94 dB, +0.8 dB over amaze - Chroma zipper smallest across all tested methods and ISOs - SIDD real raw iso_clean: +0.38 dB over amaze+dual However, the paper-exact pipeline is slow: - 30-80x slower than existing methods - 53s per 15 MP patch at 16 threads (standalone) - 113s through darktable pipeline on mire1.cr2 - Memory-bandwidth bound; OpenCL is unlikely to reach practical speeds Optimizations applied (all preserve paper-exact output): - Rolling sum box filter replacing double integral image - Row-major vertical pass for cache-line reuse on wide images - Paired GF sum sharing (~33 % box-call reduction) - Separable Gaussian 5x5 for criterion smoothing - Separable bicubic 7x7 for R/B residual upsample - Removed redundant refined-estimate recomputation in RI-H - Criterion-side adjacent-loop fusion Menon (2007) is separately included as a reference implementation. It is fast (~amaze speed), but benchmarking across Kodak-24 + SIDD-medium did not show a clear advantage over amaze - chroma zipper is similar or worse (especially cz_peak), and CPSNR is within 0.1 dB. Both algorithms looked strong on paper; extensive benchmarking showed neither clearly beats the existing methods across the tested conditions. I'll leave the merge decision to maintainers. The benchmark numbers themselves should be useful regardless; full writeup + reproducible scripts + Python reference ported from the original MATLAB are available in the sibling darktable-rawforge/demosaic_test/ directory (BENCHMARK.md). menon.c: keep the unused FIR/k_b locals (they're referenced via OpenMP firstprivate clauses) to fix -Werror=unused-variable with GCC 15. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
f937bd7 to
de30883
Compare
|
Thanks for reworking ARI and especially the "benchmarking" :-)
|
|
Thanks for looking at this and for the honest read. Fully agree with your assessment. Both methods I picked from recent papers hoping they'd bring something new, but the benchmarks across Kodak-24, SIDD real raw, and chroma-zipper metrics made it clear:
The existing rcd/amaze/+dual lineup is well-balanced and I don't see a use case these two would unlock in practice. I'll leave the merge/close decision to you — happy either way. The benchmark writeup and reproducible scripts are at dregsist/darktable-rawforge/demosaic_test in case the numbers are useful for future demosaic discussions. |
|
I tried the reference ARI again (on my pretty fast machine) it a) is very slow b) seems to give slightly more details without introducing artefacts compared with rcd or amaze c) it has better "chroma noise resistance". Although when using capture sharpening on rcd the details advantage is not visibly any more to me. I am still working on pixelpipe caching improvements, with current ROI concept ARI is unfortunately not practical. |



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.