Commit f937bd7
demosaic: rewrite ARI to paper-exact, optimize; honest about outcome
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>1 parent 83fa112 commit f937bd7
3 files changed
Lines changed: 2087 additions & 616 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
| 50 | + | |
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| |||
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
| 171 | + | |
171 | 172 | | |
172 | 173 | | |
173 | 174 | | |
| |||
182 | 183 | | |
183 | 184 | | |
184 | 185 | | |
| 186 | + | |
185 | 187 | | |
186 | 188 | | |
187 | 189 | | |
| |||
274 | 276 | | |
275 | 277 | | |
276 | 278 | | |
| 279 | + | |
277 | 280 | | |
278 | 281 | | |
279 | 282 | | |
| |||
481 | 484 | | |
482 | 485 | | |
483 | 486 | | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
484 | 504 | | |
485 | 505 | | |
486 | 506 | | |
487 | | - | |
| 507 | + | |
488 | 508 | | |
489 | 509 | | |
490 | 510 | | |
491 | 511 | | |
492 | | - | |
| 512 | + | |
493 | 513 | | |
494 | 514 | | |
495 | 515 | | |
496 | 516 | | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
497 | 530 | | |
498 | 531 | | |
499 | 532 | | |
| |||
906 | 939 | | |
907 | 940 | | |
908 | 941 | | |
909 | | - | |
| 942 | + | |
910 | 943 | | |
911 | 944 | | |
912 | 945 | | |
| |||
1420 | 1453 | | |
1421 | 1454 | | |
1422 | 1455 | | |
| 1456 | + | |
1423 | 1457 | | |
1424 | 1458 | | |
1425 | 1459 | | |
| |||
1634 | 1668 | | |
1635 | 1669 | | |
1636 | 1670 | | |
| 1671 | + | |
1637 | 1672 | | |
1638 | 1673 | | |
1639 | 1674 | | |
| |||
1830 | 1865 | | |
1831 | 1866 | | |
1832 | 1867 | | |
| 1868 | + | |
| 1869 | + | |
| 1870 | + | |
| 1871 | + | |
| 1872 | + | |
1833 | 1873 | | |
1834 | 1874 | | |
1835 | 1875 | | |
| |||
0 commit comments