33Determine the center of diffraction images
44==========================================
55"""
6- from os import cpu_count
6+
77from math import floor
88import numpy as np
99from skimage .registration import phase_cross_correlation
1212from warnings import catch_warnings , simplefilter
1313
1414
15- def autocenter (im , mask = None ):
15+ def autocenter (im , mask = None , normalize_bg = True ):
1616 """
1717 Find the center of a diffraction pattern automatically.
1818
@@ -25,6 +25,13 @@ def autocenter(im, mask=None):
2525 mask : ndarray, shape (N,M), dtype bool, optional
2626 Mask that evaluates to `True` on pixels that
2727 should be used to determine the center.
28+ normalize_bg: bool, optional
29+ If `True` (default), an attempt will be made to remove
30+ asymmetries in the background of `im`. This can sometimes
31+ provide worse results, so you may want to disable this feature.
32+
33+ .. versionadded:: 2.1.16
34+
2835
2936 Returns
3037 -------
@@ -76,9 +83,13 @@ def autocenter(im, mask=None):
7683 # e.g. (n00) systematically brighter than (-n00)
7784 # For this purpose, we normalize the intensity by some "background",
7885 # i.e. very blurred diffraction pattern
79- with catch_warnings ():
80- simplefilter ("ignore" , category = RuntimeWarning )
81- im /= gaussian_filter (input = im , sigma = min (im .shape ) / 25 , truncate = 2 )
86+ # This step is optional because it may negatively affect the results
87+ # on very clean images. See issue #45
88+ # (https://github.com/LaurentRDC/scikit-ued/issues/45#issuecomment-2180808898)
89+ if normalize_bg :
90+ with catch_warnings ():
91+ simplefilter ("ignore" , category = RuntimeWarning )
92+ im /= gaussian_filter (input = im , sigma = min (im .shape ) / 25 , truncate = 2 )
8293 im = np .nan_to_num (im , copy = False )
8394
8495 # The comparison between Friedel pairs from [1] is generalized to
0 commit comments