From b1b0fc0f0ba4077f5a71a5b4e7c5ee0c2a60c60b Mon Sep 17 00:00:00 2001 From: IainHammond Date: Thu, 18 Jun 2026 10:31:36 +0200 Subject: [PATCH 1/2] fix for frame_deconvolution --- src/vip_hci/var/filters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vip_hci/var/filters.py b/src/vip_hci/var/filters.py index 6db423641..6fdddbd6c 100644 --- a/src/vip_hci/var/filters.py +++ b/src/vip_hci/var/filters.py @@ -648,7 +648,7 @@ def frame_deconvolution(array, psf, n_it=30): min_I = np.amin(array) drange = max_I-min_I - deconv = richardson_lucy((array-min_I)/drange, psf, iterations=n_it) + deconv = richardson_lucy((array-min_I)/drange, psf, num_iter=n_it) deconv *= drange deconv += min_I From 6bf54b317673d26a1d30e57c3f6c41a99b1387f4 Mon Sep 17 00:00:00 2001 From: IainHammond Date: Fri, 19 Jun 2026 14:38:56 +0200 Subject: [PATCH 2/2] clean up frame_deconvolution, minor improvements --- src/vip_hci/var/filters.py | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/vip_hci/var/filters.py b/src/vip_hci/var/filters.py index 6fdddbd6c..cdb2a0844 100644 --- a/src/vip_hci/var/filters.py +++ b/src/vip_hci/var/filters.py @@ -613,7 +613,12 @@ def cube_filter_lowpass(array, mode='gauss', median_size=5, fwhm_size=5, return array_out -def frame_deconvolution(array, psf, n_it=30): +def frame_deconvolution( + array: np.ndarray, + psf: np.ndarray, + num_iter: int = 30, + clip: bool = False, +) -> np.ndarray: """ Iterative image deconvolution following the scikit-image implementation of the Richardson-Lucy algorithm, described in [RIC72]_ and [LUC74]_. @@ -626,16 +631,21 @@ def frame_deconvolution(array, psf, n_it=30): Parameters ---------- - array : numpy ndarray + array : numpy.ndarray Input image, 2d frame. - psf : numpy ndarray + psf : numpy.ndarray Input psf, 2d frame. - n_it : int, optional + num_iter : int, optional Number of iterations. + clip : bool, optional + Passed to scikit-image to control whether the final image should cap + pixel intensities between [-1, 1]. Default is False, because + Richardson-Lucy on a point source can cause iterations to go above 1 at + the peak. Returns ------- - deconv : numpy ndarray + deconv : numpy.ndarray Deconvolved image. """ @@ -644,12 +654,15 @@ def frame_deconvolution(array, psf, n_it=30): if psf.ndim != 2: raise TypeError('Input psf is not a frame or 2d array.') - max_I = np.amax(array) - min_I = np.amin(array) - drange = max_I-min_I + if not np.isclose(psf.sum(), 1.0, atol=1e-2): + psf = psf / psf.sum() # skimage assumes the psf is normalized already + + max_val = float(np.amax(array)) + min_val = float(np.amin(array)) + drange = max_val - min_val - deconv = richardson_lucy((array-min_I)/drange, psf, num_iter=n_it) + deconv = richardson_lucy((array - min_val) / drange, psf, num_iter=num_iter, clip=clip) deconv *= drange - deconv += min_I + deconv += min_val return deconv