Skip to content

TV denoising: fix the step sizes of the CUDA solver (#939) - #978

Merged
AnderBiguri merged 3 commits into
masterfrom
fix/939-tvdenoise
Nov 28, 2026
Merged

AnderBiguri merged 3 commits into
masterfrom
fix/939-tvdenoise

Conversation

@AnderBiguri

@AnderBiguri AnderBiguri commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Fixes #939.

Cause

The CUDA TV denoiser (Common/CUDA/tv_proximal.cu, used by im3ddenoise / im3DDenoise and so by ossart_tv/SART_TV and fista/FISTA) uses the step sizes of Knoll et al., "Fast reduction of undersampling artifacts in radial MR angiography with 3D total variation on graphics hardware", MAGMA 23:103-114 (2010), Eq. (9), which adapts Zhu & Chan's (2008) scheme to 3D:
tau_D = 0.3 + 0.02n, tau_P = (1/tau_D)(1/6 - 5/(15+n)).
The code implements it exactly. But tau_P is negative for n < 15: those primal steps push the image away from the data. The paper ran 200-600 iterations (its Table 2), where this washes out. TIGRE calls the denoiser with 20 (inside ossart_tv/fista) to 50 iterations, and there it is expansive and blows up when applied repeatedly.

Fix

Zhu & Chan's 2D product is 0.5 - 5/(15+n) = 0.5 (1 - 10/(15+n)); Eq. (9) replaces the 0.5 by 1/6 but not the offset. Apply the 3D factor to the whole bracket: tau_P = (1/6)(1 - 10/(15+n)) / tau_D, positive from the first iteration; tau_D unchanged. Two lines in the kernel. Also: Python im3ddenoise divides by max + 2 eps like MATLAB, so a constant image no longer gives NaN.

(The first commit used Zhu & Chan's 2D schedule instead; it is stable but stalls with strong denoising in 3D, so the second commit returns to the paper's 3D values.)

Evidence

On Ander's GPU (master), 128^3 head + noise, 20 denoiser iterations:

lambda non-expansive ratio (must be <= 1) 60 repeated calls
25 2.615 inf
50 1.747 3e17
200 1.173 3e7

and ossart_tv (30 it.) error 6.6e6 / 942 / 1.20 for tvlambda 25 / 50 / 200.

A NumPy copy of the kernel (same update order, boundaries and steps) reproduces those ratios (2.585 / 1.733 / 1.170). With the fixed steps the same copy gives, against an exact ROF solution (Chambolle's projection algorithm, 4000 it.):

  • non-expansive (ratio 0.10 to 0.89), output within the input range, repeated calls shrink instead of growing;
  • relative error 0.18 to 0.32 at 20 iterations, 2e-2 to 0.19 at 50, 5e-4 to 1.3e-2 at 200 (lambda 5 to 200);
  • converges in long runs on noise and step images: about 1e-4 after 2000 iterations for lambda 1 and 1000. Zhu & Chan's 2D schedule stalls at 1e-2 to 2e-2 for lambda 1.
  • at the paper's iteration counts (200) it is as good as or better than Eq. (9) unchanged, so nothing is lost there.

Python/tests/test_tv_denoise_gpu.py (GPU-marked, 32^3, fast) checks non-expansiveness, range and repeated calls; the old code fails all of them in the NumPy copy, the fixed one passes.

Effect on users

Results of TV denoising change (they were wrong). The multi-GPU / split tests compare runs with each other, so they are unaffected. The HIP build (#747) compiles the same file.

GPU check: iterations vs the paper's setting (Ander's GPU)

64^3 noisy phantom, im3ddenoise, relative distance to the converged answer (fixed build, 3000 iterations):

lambda iters master fixed
5 20 10.7 0.23
5 50 0.54 0.16
5 200 2.5e-2 2.1e-2
5 600 1.0e-3 9.4e-4
5 3000 7.2e-6 0
15 20 3.13 0.15
15 50 0.25 6.2e-2
15 200 1.6e-2 1.4e-2
15 600 2.7e-3 2.6e-3
15 3000 6.1e-6 0
50 20 0.96 8.0e-2
50 50 0.14 1.3e-2
50 200 4.2e-4 3.3e-4
50 600 8.7e-6 8.5e-6
50 3000 2.0e-6 0
  • Both builds converge to the same answer (3000 it.: within 1e-5), as the paper says.
  • At the paper's 200-600 iterations master is fine, and the fix is equal or slightly better.
  • At TIGRE's 20-50 iterations master is far off (up to 10x the size of the answer at 20); the fix is 3 to 40 times closer.

GPU check with the fix (Ander's GPU, same test as the table at the top)

  • Non-expansive ratio 0.347 / 0.605 / 0.890 (lambda 25 / 50 / 200), was 2.615 / 1.747 / 1.173.
  • 60 repeated calls: |z| = 269 / 280 / 296 from |x| = 534, was inf / 3e17 / 3e7.
  • ossart_tv (30 it.): error 1.065 / 1.055 / 1.044, below plain ossart (1.263); was 6.6e6 / 942 / 1.20.

🤖 Generated with Claude Code

https://claude.ai/code/session_01L6n1VHnm4txckzfDWNHcDC

AnderBiguri and others added 3 commits November 28, 2026 13:12
tv_proximal.cu used tau1 = (1/6 - 5/(15+k))/(0.3+0.02k), which is
negative for k < 15. Those primal steps moved u away from the data, so
the denoiser was expansive (|D(x)-D(y)| up to 2.6|x-y|) and diverged
when applied repeatedly, as ossart_tv/SART_TV and fista/FISTA do.

Use the Zhu & Chan (2008) schedule, tau2 = 0.2+0.08k,
tau1 = (0.5 - 5/(15+k))/tau2. A NumPy copy of the kernel reproduces the
GPU numbers of the old code; with the new steps it is non-expansive,
stays within the input range, and converges to an exact ROF solution
faster than the alternatives tried.

Python im3ddenoise: divide by max+2eps as MATLAB, so a constant image
no longer gives NaN. GPU test for non-expansiveness, range and
repeated application.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L6n1VHnm4txckzfDWNHcDC
…939)

The original 3D schedule (tau2 = 0.3+0.02k, factor 1/6 instead of
Zhu-Chan's 0.5) was a deliberate 3D adaptation; only the 5/(15+k)
offset had not been scaled with the factor, which made tau1 negative.
Use tau1*tau2 = (1/6)(1 - 10/(15+k)).

Compared with the 2D Zhu-Chan schedule of the previous commit, this
converges where that one stalls with strong denoising (lambda = 1:
1e-4 vs 2e-2 relative error after 2000 iterations), and is equally
non-expansive and bounded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L6n1VHnm4txckzfDWNHcDC
The schedule is exactly Eq. (9) of Knoll et al., MAGMA 23:103-114
(2010); the paper ran 200-600 iterations, where the negative early
primal steps wash out. Comment and changelog only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L6n1VHnm4txckzfDWNHcDC
@AnderBiguri
AnderBiguri marked this pull request as ready for review November 28, 2026 14:11
@AnderBiguri
AnderBiguri merged commit 4f2f4f4 into master Nov 28, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: ossart_tv and fista with TV diverge on a realistic CBCT problem

1 participant