Commit 6d77466d authored by Pierre Paleo's avatar Pierre Paleo
Browse files

Add division normalization. Rename 'array_X' with 'X'

parent 85541f67
......@@ -274,8 +274,13 @@ class SinoNormalization:
kinds = [
"chebyshev",
"subtract_array"
"subtraction",
"division",
]
operations = {
"subtraction": np.subtract,
"division": np.divide
}
def __init__(self, kind="chebyshev", sinos_shape=None, radios_shape=None, normalization_array=None):
"""
......@@ -287,8 +292,9 @@ class SinoNormalization:
Normalization type. They can be the following:
- chebyshev: Each sinogram line is estimated by a Chebyshev polynomial
of degree 2. This estimation is then subtracted from the sinogram.
- subtract_array: Each sinogram is subtracted with a user-provided array.
- subtraction: Each sinogram is subtracted with a user-provided array.
The array can be 1D (angle-independent) and 2D (angle-dependent)
- division: same as previously, but with a division operation.
Default is "chebyshev"
sinos_shape: tuple, optional
Shape of the sinogram or sinogram stack.
......@@ -297,7 +303,7 @@ class SinoNormalization:
Shape of the projections or projections stack.
Either this parameter or 'sinos_shape' has to be provided.
normalization_array: numpy.ndarray, optional
Normalization array when kind='subtract_array'.
Normalization array when kind='subtraction' or kind='division'.
"""
self._get_shapes(sinos_shape, radios_shape)
self._set_kind(kind, normalization_array)
......@@ -309,10 +315,14 @@ class SinoNormalization:
def _set_kind(self, kind, normalization_array):
check_supported(kind, self.kinds, "sinogram normalization kind")
self.normalization_kind = kind
if "array" in kind and not isinstance(normalization_array, np.ndarray):
raise ValueError(
"Expected 'normalization_array' to be provided as a numpy array for normalization kind='%s'" % kind
)
self._normalization_instance_method = self._normalize_chebyshev # default
if kind in ["subtraction", "division"]:
if not isinstance(normalization_array, np.ndarray):
raise ValueError(
"Expected 'normalization_array' to be provided as a numpy array for normalization kind='%s'" % kind
)
self.norm_operation = self.operations[kind]
self._normalization_instance_method = self._normalize_op
self.normalization_array = normalization_array
#
......@@ -351,31 +361,25 @@ class SinoNormalization:
#
# Array subtraction
# Array subtraction/division
#
def _normalize_subtract_array(self, sino):
def _normalize_op(self, sino):
if sino.ndim == 2:
sino -= self.normalization_array
self.norm_operation(sino, self.normalization_array, out=sino)
else:
for i in range(sino.shape[0]):
sino[i] -= self.normalization_array
self.norm_operation(sino[i], self.normalization_array, out=sino[i])
return sino
#
# Dispatch
#
def _get_norm_func_name(self, prefix=""):
return prefix + "normalize_" + self.normalization_kind
def normalize(self, sino):
"""
Normalize a sinogram or stack of sinogram.
The process is done in-place, meaning that the sinogram content is overwritten.
"""
norm_func = getattr(self, self._get_norm_func_name(prefix="_"))
return norm_func(sino)
return self._normalization_instance_method(sino)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment