@@ -613,7 +613,12 @@ def cube_filter_lowpass(array, mode='gauss', median_size=5, fwhm_size=5,
613613 return array_out
614614
615615
616- def frame_deconvolution (array , psf , n_it = 30 ):
616+ def frame_deconvolution (
617+ array : np .ndarray ,
618+ psf : np .ndarray ,
619+ num_iter : int = 30 ,
620+ clip : bool = False ,
621+ ) -> np .ndarray :
617622 """
618623 Iterative image deconvolution following the scikit-image implementation
619624 of the Richardson-Lucy algorithm, described in [RIC72]_ and [LUC74]_.
@@ -626,16 +631,21 @@ def frame_deconvolution(array, psf, n_it=30):
626631
627632 Parameters
628633 ----------
629- array : numpy ndarray
634+ array : numpy. ndarray
630635 Input image, 2d frame.
631- psf : numpy ndarray
636+ psf : numpy. ndarray
632637 Input psf, 2d frame.
633- n_it : int, optional
638+ num_iter : int, optional
634639 Number of iterations.
640+ clip : bool, optional
641+ Passed to scikit-image to control whether the final image should cap
642+ pixel intensities between [-1, 1]. Default is False, because
643+ Richardson-Lucy on a point source can cause iterations to go above 1 at
644+ the peak.
635645
636646 Returns
637647 -------
638- deconv : numpy ndarray
648+ deconv : numpy. ndarray
639649 Deconvolved image.
640650
641651 """
@@ -644,12 +654,15 @@ def frame_deconvolution(array, psf, n_it=30):
644654 if psf .ndim != 2 :
645655 raise TypeError ('Input psf is not a frame or 2d array.' )
646656
647- max_I = np .amax (array )
648- min_I = np .amin (array )
649- drange = max_I - min_I
657+ if not np .isclose (psf .sum (), 1.0 , atol = 1e-2 ):
658+ psf = psf / psf .sum () # skimage assumes the psf is normalized already
659+
660+ max_val = float (np .amax (array ))
661+ min_val = float (np .amin (array ))
662+ drange = max_val - min_val
650663
651- deconv = richardson_lucy ((array - min_I ) / drange , psf , num_iter = n_it )
664+ deconv = richardson_lucy ((array - min_val ) / drange , psf , num_iter = num_iter , clip = clip )
652665 deconv *= drange
653- deconv += min_I
666+ deconv += min_val
654667
655668 return deconv
0 commit comments