Skip to content

Commit a4d438f

Browse files
committed
Background normalization preprocessing step for autocenter is now optional (#45)
1 parent 7134b08 commit a4d438f

3 files changed

Lines changed: 23 additions & 6 deletions

File tree

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Changelog
22
=========
33

4+
Release 2.1.16
5+
--------------
6+
7+
* Fixed an issue where `autocenter` could return bogus results. A new parameter has been added to address This
8+
problem while maintaining backwards-compatibility (#45).
9+
410
Release 2.1.15
511
--------------
612

skued/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
__author__ = "Laurent P. René de Cotret"
33
__email__ = "laurent.renedecotret@mail.mcgill.ca"
44
__license__ = "GPLv3"
5-
__version__ = "2.1.14"
5+
__version__ = "2.1.16"
66

77
from .affine import (
88
affine_map,

skued/image/center.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Determine the center of diffraction images
44
==========================================
55
"""
6-
from os import cpu_count
6+
77
from math import floor
88
import numpy as np
99
from skimage.registration import phase_cross_correlation
@@ -12,7 +12,7 @@
1212
from 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

Comments
 (0)