Skip to content

Commit

Permalink
Background normalization preprocessing step for autocenter is now o…
Browse files Browse the repository at this point in the history
…ptional (#45)
  • Loading branch information
LaurentRDC committed Jun 20, 2024
1 parent 7134b08 commit a4d438f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

Release 2.1.16
--------------

* Fixed an issue where `autocenter` could return bogus results. A new parameter has been added to address This
problem while maintaining backwards-compatibility (#45).

Release 2.1.15
--------------

Expand Down
2 changes: 1 addition & 1 deletion skued/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
__author__ = "Laurent P. René de Cotret"
__email__ = "[email protected]"
__license__ = "GPLv3"
__version__ = "2.1.14"
__version__ = "2.1.16"

from .affine import (
affine_map,
Expand Down
21 changes: 16 additions & 5 deletions skued/image/center.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Determine the center of diffraction images
==========================================
"""
from os import cpu_count

from math import floor
import numpy as np
from skimage.registration import phase_cross_correlation
Expand All @@ -12,7 +12,7 @@
from warnings import catch_warnings, simplefilter


def autocenter(im, mask=None):
def autocenter(im, mask=None, normalize_bg=True):
"""
Find the center of a diffraction pattern automatically.
Expand All @@ -25,6 +25,13 @@ def autocenter(im, mask=None):
mask : ndarray, shape (N,M), dtype bool, optional
Mask that evaluates to `True` on pixels that
should be used to determine the center.
normalize_bg: bool, optional
If `True` (default), an attempt will be made to remove
asymmetries in the background of `im`. This can sometimes
provide worse results, so you may want to disable this feature.
.. versionadded:: 2.1.16
Returns
-------
Expand Down Expand Up @@ -76,9 +83,13 @@ def autocenter(im, mask=None):
# e.g. (n00) systematically brighter than (-n00)
# For this purpose, we normalize the intensity by some "background",
# i.e. very blurred diffraction pattern
with catch_warnings():
simplefilter("ignore", category=RuntimeWarning)
im /= gaussian_filter(input=im, sigma=min(im.shape) / 25, truncate=2)
# This step is optional because it may negatively affect the results
# on very clean images. See issue #45
# (https://github.com/LaurentRDC/scikit-ued/issues/45#issuecomment-2180808898)
if normalize_bg:
with catch_warnings():
simplefilter("ignore", category=RuntimeWarning)
im /= gaussian_filter(input=im, sigma=min(im.shape) / 25, truncate=2)
im = np.nan_to_num(im, copy=False)

# The comparison between Friedel pairs from [1] is generalized to
Expand Down

0 comments on commit a4d438f

Please sign in to comment.