Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Common/CUDA/tv_proximal.cu
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,14 @@ void cpy_from_host(float* device_array,float* host_array,
// Inter interations.
for(unsigned int ib=0; (ib<(buffer_length)) && ((i+ib)<maxIter); ib++){

// Step sizes of Knoll et al., MAGMA 23:103-114 (2010), Eq. (9): Zhu & Chan's (2008)
// scheme adapted to 3D, tau1 = (1/tau2)*(1/6 - 5/(15+k)). That tau1 is negative for
// k < 15, which pushes u away from the data. The paper ran 200-600 iterations, where this
// washes out; TIGRE calls the denoiser with 20-50, and there it was expansive and
// diverged when repeated (#939). Zhu & Chan's 2D product is 0.5*(1 - 10/(15+k)); here
// the 3D factor 1/6 multiplies the whole bracket, which keeps tau1 > 0.
tau2 = 0.3f + 0.02f * (i+ib);
tau1 = (1.f/tau2) * ((1.f/6.f) - (5.f/(15.f+(i+ib))));
tau1 = (1.f/tau2) * ((1.f/6.f) * (1.f - 10.f/(15.f+(i+ib))));
// bdim and gdim

// Only the piece and its halo_lo/halo_hi halo slices (see above).
Expand Down
47 changes: 47 additions & 0 deletions Python/tests/test_tv_denoise_gpu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""im3ddenoise (CUDA tv_proximal) behaves like a TV proximal step (#939).

Its step sizes made the primal step negative for the first 15 iterations, so
the denoiser amplified differences (|D(x)-D(y)| up to 2.6 |x-y|) and blew up
when called repeatedly, as ossart_tv and fista do. A TV proximal step is
non-expansive and keeps the result within the range of its input.
"""
import numpy as np
import pytest

import tigre # noqa: F401 (first: on Windows it puts CUDA's DLLs on the search path)

pytestmark = pytest.mark.gpu

try:
from tigre.utilities.im_3d_denoise import im3ddenoise
except ImportError:
pytest.skip("TIGRE's CUDA extensions are not built", allow_module_level=True)


def _images():
rng = np.random.default_rng(0)
n = 32
z, y, x = np.mgrid[:n, :n, :n]
img = ((z - 16) ** 2 / 150 + (y - 16) ** 2 / 120 + (x - 16) ** 2 / 100 < 1).astype(np.float32)
x0 = (img + 0.3 * rng.standard_normal(img.shape) - 0.2).astype(np.float32)
x1 = (x0 + 0.01 * rng.standard_normal(x0.shape)).astype(np.float32)
return x0, x1


@pytest.mark.parametrize("lmbda", [5, 25, 200])
def test_denoise_is_nonexpansive_and_bounded(lmbda):
x0, x1 = _images()
d0 = im3ddenoise(x0, 20, lmbda)
d1 = im3ddenoise(x1, 20, lmbda)
assert np.linalg.norm(d0 - d1) <= 1.001 * np.linalg.norm(x0 - x1)
tol = 1e-3 * (x0.max() - x0.min())
assert d0.min() >= x0.min() - tol and d0.max() <= x0.max() + tol


def test_repeated_denoise_does_not_grow():
x0, _ = _images()
z = x0.copy()
for _ in range(30):
z = im3ddenoise(z, 20, 25)
assert np.isfinite(z).all()
assert np.linalg.norm(z) <= np.linalg.norm(x0)
3 changes: 2 additions & 1 deletion Python/tigre/utilities/im_3d_denoise.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def im3ddenoise(img, iter=50, lmbda=15.0, gpuids=None):
imgmin = np.amin(img.ravel())
img = img - imgmin
imgmax = np.amax(img.ravel())
img = img / imgmax
# As MATLAB's im3DDenoise: a constant image gives 0/0 otherwise
img = img / (imgmax + 2 * np.finfo(np.float64).eps)

if gpuids is None:
gpuids = GpuIds()
Expand Down
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ thank you.
(off by default, as in MATLAB) (#201).

### Fixed
- TV denoising (`im3ddenoise` / `im3DDenoise`, and through it `ossart_tv`/`SART_TV` and `fista`/`FISTA`): the CUDA
solver's step sizes made the primal step negative for the first 15 iterations, so the denoiser amplified
differences and diverged when called repeatedly, as those algorithms do. The step sizes (Knoll et al. 2010, Zhu &
Chan's scheme for 3D) were designed for hundreds of iterations, not the 20-50 TIGRE uses; with the 3D factor
applied to the whole term they stay positive, and the denoiser is now a proper
TV proximal step: non-expansive and within the range of its input. Results of TV denoising change. Python's
`im3ddenoise` no longer gives NaN for a constant image, as MATLAB (#939).
- `IRN_TV_CGLS` (MATLAB and Python): the loss-of-orthogonality check watched ||Ax-b||, which may rise legitimately
when the regularisation is strong, so it fired falsely and cut the iterations short. It now watches the residual of
the whole regularised system, which CGLS never lets grow, with a tolerance for single-precision rounding. In
Expand Down
Loading