Repository navigation
TV denoising: fix the step sizes of the CUDA solver (#939) - #978
Merged
Merged
Conversation
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
marked this pull request as ready for review
November 28, 2026 14:11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #939.
Cause
The CUDA TV denoiser (
Common/CUDA/tv_proximal.cu, used byim3ddenoise/im3DDenoiseand so byossart_tv/SART_TVandfista/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_Pis 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 (insideossart_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_Dunchanged. Two lines in the kernel. Also: Pythonim3ddenoisedivides bymax + 2 epslike 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:
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.):
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):GPU check with the fix (Ander's GPU, same test as the table at the top)
ossart_tv(30 it.): error 1.065 / 1.055 / 1.044, below plainossart(1.263); was 6.6e6 / 942 / 1.20.🤖 Generated with Claude Code
https://claude.ai/code/session_01L6n1VHnm4txckzfDWNHcDC