From a01029ed50d67407ec7c23f18678ae76139bc9e3 Mon Sep 17 00:00:00 2001 From: mrava87 Date: Thu, 8 Oct 2026 09:48:12 +0100 Subject: [PATCH 1/3] Add PnP and RED solvers to the image deblurring benchmark Co-Authored-By: Claude Opus 5.5 --- benchmarks/image_deblurring/README.md | 2 + .../image_deblurring/solvers/pnp_admm_bm3d.py | 54 ++++++++++++++ .../image_deblurring/solvers/red_bm3d.py | 70 +++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 benchmarks/image_deblurring/solvers/pnp_admm_bm3d.py create mode 100644 benchmarks/image_deblurring/solvers/red_bm3d.py diff --git a/benchmarks/image_deblurring/README.md b/benchmarks/image_deblurring/README.md index abb8820..a5424f6 100644 --- a/benchmarks/image_deblurring/README.md +++ b/benchmarks/image_deblurring/README.md @@ -20,5 +20,7 @@ Solvers compared: | `PrimalDual-TV` | Isotropic total variation regularization, with or without bound constraints on the pixel values, solved with the primal-dual algorithm (PyProximal) | | `PrimalDual-DWT2D` | L1 sparsity of the image in one or more wavelet domains (analysis form, e.g. Haar, db4 or both stacked), solved with the primal-dual algorithm (PyProximal) | | `LinearizedADMM-rMS` | Relaxed Mumford-Shah (truncated quadratic) penalty on the image gradient, nonconvex, solved with the linearized ADMM (PyProximal) | +| `PnP-ADMM-BM3D` | Plug-and-Play prior with the BM3D denoiser in place of the proximal operator of the regularizer, solved with ADMM (PyProximal) | +| `RED-BM3D` | Regularization by Denoising with the BM3D denoiser, solved with fixed-point iterations (PyProximal) | All wavelet transforms are `pylops.signalprocessing.DWT2D` with 3 levels. diff --git a/benchmarks/image_deblurring/solvers/pnp_admm_bm3d.py b/benchmarks/image_deblurring/solvers/pnp_admm_bm3d.py new file mode 100644 index 0000000..7703217 --- /dev/null +++ b/benchmarks/image_deblurring/solvers/pnp_admm_bm3d.py @@ -0,0 +1,54 @@ +import numpy as np +from benchopt import BaseSolver +from pyproximal import L2 +from pyproximal.optimization.pnp import PlugAndPlay +from pyproximal.optimization.primal import ADMM + +from pylops_bench.denoisers import bm3d_denoise + + +class Solver(BaseSolver): + r"""Plug-and-Play prior with the BM3D denoiser, solved with ADMM. + + The proximal operator of the regularizer in + :func:`pyproximal.optimization.primal.ADMM` is replaced by the BM3D + denoiser (:func:`pylops_bench.denoisers.bm3d_denoise`), with noise + standard deviation :math:`\sigma \tau` relative to the 0-255 range of the + image (:func:`pyproximal.optimization.pnp.PlugAndPlay`). The proximal + operator of the data term :math:`\frac{1}{2} \|y - Op x\|_2^2` is + evaluated with a few warm-started inner iterations. + """ + + name = "PnP-ADMM-BM3D" + + requirements = ["pip::pylops", "pip::pyproximal", "pip::bm3d"] + sampling_strategy = "run_once" + + parameters = { + "sigma": [0.004], + "tau": [15.0], + "niter": [60], + } + + def set_objective(self, Op, y, meta): + self.dims = meta["dims"] + self.Op = Op + self.y = y + self.x0 = np.zeros(Op.shape[1], dtype=Op.dtype) + + def run(self, _): + # warm-started proximal operators keep state between calls: build + # them at every run so that repeated runs give the same result + proxf = L2(Op=self.Op, b=self.y, niter=20, warm=True) + self.x = PlugAndPlay( + proxf, + lambda x, tau: bm3d_denoise(x, self.sigma * tau, scale=255.0), + self.dims, + x0=self.x0, + solver=ADMM, + tau=self.tau, + niter=self.niter, + )[0] + + def get_result(self): + return dict(x=self.x.reshape(self.dims)) diff --git a/benchmarks/image_deblurring/solvers/red_bm3d.py b/benchmarks/image_deblurring/solvers/red_bm3d.py new file mode 100644 index 0000000..0f2e80a --- /dev/null +++ b/benchmarks/image_deblurring/solvers/red_bm3d.py @@ -0,0 +1,70 @@ +from functools import partial + +import numpy as np +from benchopt import BaseSolver +from pyproximal import L2 +from pyproximal import RED as REDTerm +from pyproximal.optimization.red import RED + +from pylops_bench.denoisers import bm3d_denoise + + +class Solver(BaseSolver): + r"""Regularization by Denoising (RED) with the BM3D denoiser, solved + with fixed-point iterations. + + .. math:: + \min_x \frac{1}{2} \|y - Op x\|_2^2 + + \sigma x^T (x - f_{\sigma_d}(x)) + + where :math:`f_{\sigma_d}` is the BM3D denoiser + (:func:`pylops_bench.denoisers.bm3d_denoise`) with noise standard + deviation :math:`\sigma_d` relative to the 0-255 range of the image. + Solved with :func:`pyproximal.optimization.red.RED` and + ``solver="fixedpoint"``: each iteration denoises the current estimate and + solves the normal equations + :math:`(Op^H Op + \sigma I) x = Op^H y + \sigma f_{\sigma_d}(x)` with + ``niter_inner`` LSQR iterations started from the current estimate. + """ + + name = "RED-BM3D" + + requirements = ["pip::pylops", "pip::pyproximal", "pip::bm3d"] + sampling_strategy = "run_once" + + parameters = { + "sigma": [0.02], + "sigmad": [0.08], + "niter": [60], + "niter_inner": [50], + } + + def set_objective(self, Op, y, meta): + self.dims = meta["dims"] + self.Op = Op + self.y = y + self.x0 = np.zeros(Op.shape[1], dtype=Op.dtype) + + def run(self, _): + # the RED term keeps state between calls: build it at every run so + # that repeated runs give the same result (the fixed-point solver + # only uses the operator and data of the L2 term) + proxf = L2(Op=self.Op, b=self.y) + red = REDTerm( + partial(bm3d_denoise, scale=255.0), + self.dims, + sigma=self.sigma, + sigmad=self.sigmad, + call=False, + ) + self.x = RED( + proxf, + red, + x0=self.x0, + solver="fixedpoint", + niter=self.niter, + niter_inner=self.niter_inner, + ) + + def get_result(self): + return dict(x=self.x.reshape(self.dims)) From 25176b5f0424eb961291eb155b4912e21a7b89c3 Mon Sep 17 00:00:00 2001 From: mrava87 Date: Thu, 8 Oct 2026 09:48:12 +0100 Subject: [PATCH 2/3] Add PnP and RED solvers to the image denoising benchmark Co-Authored-By: Claude Opus 5.5 --- benchmarks/image_denoising/README.md | 14 ++++ .../image_denoising/solvers/pnp_admm_bm3d.py | 49 ++++++++++++++ .../image_denoising/solvers/red_bm3d.py | 66 +++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 benchmarks/image_denoising/solvers/pnp_admm_bm3d.py create mode 100644 benchmarks/image_denoising/solvers/red_bm3d.py diff --git a/benchmarks/image_denoising/README.md b/benchmarks/image_denoising/README.md index cefd2e3..7f1248c 100644 --- a/benchmarks/image_denoising/README.md +++ b/benchmarks/image_denoising/README.md @@ -23,9 +23,23 @@ Solvers compared: | `PrimalDual-DWT2D` | L1 sparsity of the image in one or more wavelet domains (analysis, e.g. Haar, db4 or both stacked), solved with the primal-dual algorithm (PyProximal) | | `PrimalDual-TV-DWT2D` | Isotropic total variation plus L1 sparsity in the wavelet domain, solved with the primal-dual algorithm (PyProximal) | | `FISTA-Patch2D` | L1 sparsity in overlapping local 2D DCT or FFT windows (`pylops.signalprocessing.Patch2D`), solved with FISTA | +| `PnP-ADMM-BM3D` | Plug-and-Play prior with the BM3D denoiser in place of the proximal operator of the regularizer, solved with ADMM (PyProximal) | +| `RED-BM3D` | Regularization by Denoising with the BM3D denoiser, solved with fixed-point iterations (PyProximal) | All gradients are first-order forward differences and all wavelet transforms are `pylops.signalprocessing.DWT2D`. Solvers that share a formulation solve the same problem, so they converge to the same image: their weights are tuned so that this image has the highest PSNR, and their iterations so that they have converged. + +`PnP-ADMM-BM3D` and `RED-BM3D` use the BM3D denoiser (hard-thresholding +stage, `pylops_bench.denoisers.bm3d_denoise`). Since the operator is the +identity, a single call of BM3D with the noise standard deviation of the data +(about 0.115) is already a strong baseline (29.6 dB). `PnP-ADMM-BM3D` +reaches the same PSNR: its best denoiser strength is close to the noise +level, and the iterations do not improve on a single call. `RED-BM3D` behaves +differently: its fixed point balances the data with a weak denoiser applied +repeatedly, and it is best with a large RED weight and a denoiser strength +well below the noise level (`sigma=5`, `sigmad=0.03`), reaching about 0.5 dB +less than a single BM3D call. Both solvers outperform the total variation +and wavelet solvers. diff --git a/benchmarks/image_denoising/solvers/pnp_admm_bm3d.py b/benchmarks/image_denoising/solvers/pnp_admm_bm3d.py new file mode 100644 index 0000000..0d5babe --- /dev/null +++ b/benchmarks/image_denoising/solvers/pnp_admm_bm3d.py @@ -0,0 +1,49 @@ +import numpy as np +from benchopt import BaseSolver +from pyproximal import L2 +from pyproximal.optimization.pnp import PlugAndPlay +from pyproximal.optimization.primal import ADMM + +from pylops_bench.denoisers import bm3d_denoise + + +class Solver(BaseSolver): + r"""Plug-and-Play prior with the BM3D denoiser, solved with ADMM. + + The proximal operator of the regularizer in + :func:`pyproximal.optimization.primal.ADMM` is replaced by the BM3D + denoiser (:func:`pylops_bench.denoisers.bm3d_denoise`), with noise + standard deviation :math:`\sigma \tau` + (:func:`pyproximal.optimization.pnp.PlugAndPlay`). The proximal operator + of the data term :math:`\frac{1}{2} \|y - x\|_2^2` is in closed form. + """ + + name = "PnP-ADMM-BM3D" + + requirements = ["pip::pylops", "pip::pyproximal", "pip::bm3d"] + sampling_strategy = "run_once" + + parameters = { + "sigma": [0.11], + "tau": [1.0], + "niter": [10], + } + + def set_objective(self, Op, y, meta): + self.dims = meta["dims"] + self.proxf = L2(b=y) + self.x0 = np.zeros(Op.shape[1], dtype=Op.dtype) + + def run(self, _): + self.x = PlugAndPlay( + self.proxf, + lambda x, tau: bm3d_denoise(x, self.sigma * tau), + self.dims, + x0=self.x0, + solver=ADMM, + tau=self.tau, + niter=self.niter, + )[0] + + def get_result(self): + return dict(x=self.x.reshape(self.dims)) diff --git a/benchmarks/image_denoising/solvers/red_bm3d.py b/benchmarks/image_denoising/solvers/red_bm3d.py new file mode 100644 index 0000000..a09ad46 --- /dev/null +++ b/benchmarks/image_denoising/solvers/red_bm3d.py @@ -0,0 +1,66 @@ +from benchopt import BaseSolver +from pyproximal import L2 +from pyproximal import RED as REDTerm +from pyproximal.optimization.red import RED + +from pylops_bench.denoisers import bm3d_denoise + + +class Solver(BaseSolver): + r"""Regularization by Denoising (RED) with the BM3D denoiser, solved + with fixed-point iterations. + + .. math:: + \min_x \frac{1}{2} \|y - x\|_2^2 + + \sigma x^T (x - f_{\sigma_d}(x)) + + where :math:`f_{\sigma_d}` is the BM3D denoiser + (:func:`pylops_bench.denoisers.bm3d_denoise`) with noise standard + deviation :math:`\sigma_d`. + Solved with :func:`pyproximal.optimization.red.RED` and + ``solver="fixedpoint"``: each iteration denoises the current estimate and + solves :math:`(1 + \sigma) x = y + \sigma f_{\sigma_d}(x)` (one LSQR + iteration, exact for the identity operator), starting from the noisy + image. + """ + + name = "RED-BM3D" + + requirements = ["pip::pylops", "pip::pyproximal", "pip::bm3d"] + sampling_strategy = "run_once" + + parameters = { + "sigma": [5.0], + "sigmad": [0.03], + "niter": [30], + } + + def set_objective(self, Op, y, meta): + self.dims = meta["dims"] + self.Op = Op + self.y = y + self.x0 = y.copy() + + def run(self, _): + # the RED term keeps state between calls: build it at every run so + # that repeated runs give the same result (the fixed-point solver + # only uses the operator and data of the L2 term) + proxf = L2(Op=self.Op, b=self.y) + red = REDTerm( + bm3d_denoise, + self.dims, + sigma=self.sigma, + sigmad=self.sigmad, + call=False, + ) + self.x = RED( + proxf, + red, + x0=self.x0, + solver="fixedpoint", + niter=self.niter, + niter_inner=1, + ) + + def get_result(self): + return dict(x=self.x.reshape(self.dims)) From b71deea27bb11f0715425bf8358f6dd3bddf27fb Mon Sep 17 00:00:00 2001 From: mrava87 Date: Thu, 8 Oct 2026 09:48:12 +0100 Subject: [PATCH 3/3] Add PnP and RED solvers to the seismic poststack benchmark Co-Authored-By: Claude Opus 5.5 --- benchmarks/seismic_poststack/README.md | 2 + .../solvers/pnp_admm_bm3d.py | 54 +++++++++++++++ .../seismic_poststack/solvers/red_bm3d.py | 68 +++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 benchmarks/seismic_poststack/solvers/pnp_admm_bm3d.py create mode 100644 benchmarks/seismic_poststack/solvers/red_bm3d.py diff --git a/benchmarks/seismic_poststack/README.md b/benchmarks/seismic_poststack/README.md index 5463dda..d517006 100644 --- a/benchmarks/seismic_poststack/README.md +++ b/benchmarks/seismic_poststack/README.md @@ -25,5 +25,7 @@ Solvers compared: | `ADMML2-TV` | Isotropic total variation regularization, solved with ADMM specialized for an L2 misfit (PyProximal) | | `ADMM-TV` | Total variation regularization, solved with ADMM with an iterative TV proximal operator (PyProximal) | | `PrimalDual-TV` | Isotropic total variation regularization, solved with the primal-dual algorithm (PyProximal) | +| `PnP-ADMM-BM3D` | Plug-and-Play prior with the BM3D denoiser in place of the proximal operator of the regularizer, solved with ADMM (PyProximal) | +| `RED-BM3D` | Regularization by Denoising with the BM3D denoiser, solved with fixed-point iterations (PyProximal) | All total variation solvers use `pylops.Gradient` with forward differences. diff --git a/benchmarks/seismic_poststack/solvers/pnp_admm_bm3d.py b/benchmarks/seismic_poststack/solvers/pnp_admm_bm3d.py new file mode 100644 index 0000000..6a4f7c9 --- /dev/null +++ b/benchmarks/seismic_poststack/solvers/pnp_admm_bm3d.py @@ -0,0 +1,54 @@ +from benchopt import BaseSolver +from pyproximal import L2 +from pyproximal.optimization.pnp import PlugAndPlay +from pyproximal.optimization.primal import ADMM + +from pylops_bench.denoisers import bm3d_denoise + + +class Solver(BaseSolver): + r"""Plug-and-Play prior with the BM3D denoiser, solved with ADMM. + + The proximal operator of the regularizer in + :func:`pyproximal.optimization.primal.ADMM` is replaced by the BM3D + denoiser (:func:`pylops_bench.denoisers.bm3d_denoise`), with noise + standard deviation :math:`\sigma \tau` + (:func:`pyproximal.optimization.pnp.PlugAndPlay`), starting from the + background model. The proximal operator of the data term + :math:`\frac{1}{2} \|y - Op x\|_2^2` is evaluated with 20 warm-started + LSQR iterations. + """ + + name = "PnP-ADMM-BM3D" + + requirements = ["pip::pylops", "pip::pyproximal", "pip::bm3d"] + sampling_strategy = "run_once" + + parameters = { + "sigma": [0.2], + "tau": [1.0], + "niter": [30], + } + + def set_objective(self, Op, y, meta): + self.dims = meta["dims"] + self.Op = Op + self.y = y + self.x0 = meta["mback"].ravel() + + def run(self, _): + # warm-started proximal operators keep state between calls: build + # them at every run so that repeated runs give the same result + proxf = L2(Op=self.Op, b=self.y, x0=self.x0, niter=20, warm=True) + self.x = PlugAndPlay( + proxf, + lambda x, tau: bm3d_denoise(x, self.sigma * tau), + self.dims, + x0=self.x0, + solver=ADMM, + tau=self.tau, + niter=self.niter, + )[0] + + def get_result(self): + return dict(x=self.x.reshape(self.dims)) diff --git a/benchmarks/seismic_poststack/solvers/red_bm3d.py b/benchmarks/seismic_poststack/solvers/red_bm3d.py new file mode 100644 index 0000000..0f5f9e3 --- /dev/null +++ b/benchmarks/seismic_poststack/solvers/red_bm3d.py @@ -0,0 +1,68 @@ +from benchopt import BaseSolver +from pyproximal import L2 +from pyproximal import RED as REDTerm +from pyproximal.optimization.red import RED + +from pylops_bench.denoisers import bm3d_denoise + + +class Solver(BaseSolver): + r"""Regularization by Denoising (RED) with the BM3D denoiser, solved + with fixed-point iterations. + + .. math:: + \min_x \frac{1}{2} \|y - Op x\|_2^2 + + \sigma x^T (x - f_{\sigma_d}(x)) + + where :math:`f_{\sigma_d}` is the BM3D denoiser + (:func:`pylops_bench.denoisers.bm3d_denoise`) with noise standard + deviation :math:`\sigma_d`. + Solved with :func:`pyproximal.optimization.red.RED` and + ``solver="fixedpoint"``: each iteration denoises the current estimate and + solves the normal equations + :math:`(Op^H Op + \sigma I) x = Op^H y + \sigma f_{\sigma_d}(x)` with + ``niter_inner`` LSQR iterations started from the current estimate. The + first estimate is the background model. + """ + + name = "RED-BM3D" + + requirements = ["pip::pylops", "pip::pyproximal", "pip::bm3d"] + sampling_strategy = "run_once" + + parameters = { + "sigma": [0.3], + "sigmad": [0.3], + "niter": [30], + "niter_inner": [20], + } + + def set_objective(self, Op, y, meta): + self.dims = meta["dims"] + self.Op = Op + self.y = y + self.x0 = meta["mback"].ravel() + + def run(self, _): + # the RED term keeps state between calls: build it at every run so + # that repeated runs give the same result (the fixed-point solver + # only uses the operator and data of the L2 term) + proxf = L2(Op=self.Op, b=self.y) + red = REDTerm( + bm3d_denoise, + self.dims, + sigma=self.sigma, + sigmad=self.sigmad, + call=False, + ) + self.x = RED( + proxf, + red, + x0=self.x0, + solver="fixedpoint", + niter=self.niter, + niter_inner=self.niter_inner, + ) + + def get_result(self): + return dict(x=self.x.reshape(self.dims))