corrct.operators
Operators module.
@author: Nicola VIGANÒ, Computational Imaging group, CWI, The Netherlands, and ESRF - The European Synchrotron, Grenoble, France
Module Contents
Classes
Base operator class. |
|
Transform class that uses callables. |
|
Base projector class that fixes the projection interface. |
|
Identity operator. |
|
Diagonal scaling operator. |
|
Convolution operator. |
|
Base Wavelet transform. |
|
Decimated wavelet Transform operator. |
|
Stationary wavelet Transform operator. |
|
Gradient operator. |
|
Fourier transform operator. |
|
Laplacian transform operator. |
|
Singular value decomposition based decomposition operator. |
Data
API
- corrct.operators.NDArrayInt
None
- class corrct.operators.BaseTransform[source]
Bases:
scipy.sparse.linalg.LinearOperator
,abc.ABC
Base operator class.
It implements the linear operator behavior that can be used with the solvers in the
.solvers
module, and by the solvers inscipy.sparse.linalg
.Parameters
dir_shape : NDArrayInt Shape of the direct space. adj_shape : NDArrayInt Shape of the adjoint space
Attributes
is_dir_operator : bool Flag indicating if the operator is a direct operator.
Notes
It assumes that the fields `dir_shape` and `adj_shape` have been set during the initialization of the derived classes.
Initialization
Initialize the base operator class.
- dir_shape: corrct.operators.NDArrayInt
None
- adj_shape: corrct.operators.NDArrayInt
None
- _matvec(x: numpy.typing.NDArray) numpy.typing.NDArray [source]
Implement the direct operator for column vectors from the right.
Parameters
x : NDArray Either row from the left or column from the right.
Returns
NDArray Result of applying the direct operator.
- rmatvec(x: numpy.typing.NDArray) numpy.typing.NDArray [source]
Implement the direct operator for row vectors from the left.
Parameters
x : NDArray Either row from the left or column from the right on transpose.
Returns
NDArray Result of applying the direct operator for row vectors.
- _transpose() corrct.operators.BaseTransform [source]
Create the transpose operator.
Returns
BaseTransform The transpose operator.
- _adjoint() corrct.operators.BaseTransform [source]
Create the adjoint operator.
Returns
BaseTransform The adjoint operator.
- absolute() corrct.operators.BaseTransform [source]
Return the absolute value of the operator.
Returns
BaseTransform The absolute value operator.
- explicit() numpy.typing.NDArray [source]
Return the explicit transformation matrix associated with the operator.
Returns
NDArray The explicit transformation matrix, as a NumPy array.
- __call__(x: numpy.typing.NDArray) numpy.typing.NDArray [source]
Apply the operator to the input vector
x
.Parameters
x : NDArray Input vector.
Returns
result : NDArray The result of applying the operator to
x
.
- class corrct.operators.TransformFunctions(dir_shape: Union[numpy.typing.ArrayLike, numpy.typing.NDArray], adj_shape: Union[numpy.typing.ArrayLike, numpy.typing.NDArray], A: Callable[[numpy.typing.NDArray], numpy.typing.NDArray], At: Optional[Callable[[numpy.typing.NDArray], numpy.typing.NDArray]] = None)[source]
Bases:
corrct.operators.BaseTransform
Transform class that uses callables.
Initialization
Initialize the callable transform.
If the adjoint of the function is not given, the function is considered symmetric.
Parameters
dir_shape : ArrayLike Shape of the direct space. adj_shape : ArrayLike Shape of the adjoint space. A : Callable[[NDArray], NDArray] The transform function. At : Optional[Callable[[NDArray], NDArray]], optional The adjoint transform function, by default None
- _op_direct(x: numpy.typing.NDArray) numpy.typing.NDArray [source]
Apply the operator to the data.
Parameters
x : NDArray Data to process.
Returns
NDArray The processed data.
- _op_adjoint(x: numpy.typing.NDArray) numpy.typing.NDArray [source]
Apply the adjoint operator to the data.
Parameters
x : NDArray Data to process.
Returns
NDArray The processed data.
- absolute() corrct.operators.TransformFunctions [source]
Compute the absolute value of the operator. Raise an error, because not supported.
Raises
AttributeError Not supported operation.
- class corrct.operators.ProjectorOperator[source]
Bases:
corrct.operators.BaseTransform
Base projector class that fixes the projection interface.
Initialization
Initialize the base operator class.
- property vol_shape: corrct.operators.NDArrayInt
Expose the direct space shape as volume shape.
Returns
NDArray The volume shape.
- property prj_shape: corrct.operators.NDArrayInt
Expose the adjoint space shape as projection shape.
Returns
NDArray The projection shape.
- abstract fp(x: numpy.typing.NDArray) numpy.typing.NDArray [source]
Define the interface of the forward-projection.
Parameters
x : NDArray Input volume.
Returns
NDArray The projection data.
- class corrct.operators.TransformIdentity(x_shape: Union[numpy.typing.ArrayLike, numpy.typing.NDArray])[source]
Bases:
corrct.operators.BaseTransform
Identity operator.
Initialization
Identity operator.
Parameters
x_shape : ArrayLike | NDArray Shape of the data.
- class corrct.operators.TransformDiagonalScaling(x_shape: Union[numpy.typing.ArrayLike, numpy.typing.NDArray], scale: Union[numpy.typing.ArrayLike, numpy.typing.NDArray])[source]
Bases:
corrct.operators.BaseTransform
Diagonal scaling operator.
Initialization
Diagonal scaling operator.
Parameters
x_shape : ArrayLike Shape of the data. scale : float or ArrayLike Operator diagonal.
- scale: numpy.typing.NDArray
None
- absolute() corrct.operators.TransformDiagonalScaling [source]
Return the projection operator using the absolute value of the projection coefficients.
Returns
TransformDiagonalScaling The absolute value operator
- class corrct.operators.TransformConvolution(x_shape: numpy.typing.ArrayLike, kernel: numpy.typing.ArrayLike, pad_mode: str = 'edge', is_symm: bool = True, flip_adjoint: bool = False)[source]
Bases:
corrct.operators.BaseTransform
Convolution operator.
Parameters
x_shape : ArrayLike Shape of the direct space. kernel : ArrayLike The convolution kernel. pad_mode: str, optional The padding mode to use for the linear convolution. The default is “edge”. is_symm : bool, optional Whether the operator is symmetric or not. The default is True. flip_adjoint : bool, optional Whether the adjoint kernel should be flipped. The default is False. This is useful when the kernel is not symmetric.
Initialization
Initialize the base operator class.
- kernel: numpy.typing.NDArray
None
- pad_mode: str
None
- is_symm: bool
None
- flip_adjoint: bool
None
- absolute() corrct.operators.TransformConvolution [source]
Return the convolution operator using the absolute value of the kernel coefficients.
Returns
TransformConvolution The absolute value of the convolution operator.
- class corrct.operators.BaseWaveletTransform[source]
Bases:
corrct.operators.BaseTransform
,abc.ABC
Base Wavelet transform.
Initialization
Initialize the base operator class.
- axes: corrct.operators.NDArrayInt
None
- wavelet: str
None
- labels: list[str]
None
- class corrct.operators.TransformDecimatedWavelet(x_shape: Union[numpy.typing.ArrayLike, numpy.typing.NDArray], wavelet: str, level: int, axes: Optional[numpy.typing.ArrayLike] = None, pad_on_demand: str = 'edge')[source]
Bases:
corrct.operators.BaseWaveletTransform
Decimated wavelet Transform operator.
Initialization
Decimated wavelet Transform operator.
Parameters
x_shape : ArrayLike Shape of the data to be wavelet transformed. wavelet : str Wavelet type. level : int Number of wavelet decomposition levels. axes : int or tuple of int, optional Axes along which to do the transform. Defaults to None. pad_on_demand : str, optional Padding type to fit the
2 ** level
shape requirements. Defaults to ‘edge’. Options are all thenumpy.pad
padding modes.Raises
ValueError If the pywavelets package is not available or its version is not adequate.
- direct_dwt(x: numpy.typing.NDArray) list [source]
Perform the direct wavelet transform.
Parameters
x : NDArray Data to transform.
Returns
list Transformed data.
- class corrct.operators.TransformStationaryWavelet(x_shape: numpy.typing.ArrayLike, wavelet: str, level: int, axes: Optional[numpy.typing.ArrayLike] = None, pad_on_demand: str = 'edge', normalized: bool = True)[source]
Bases:
corrct.operators.BaseWaveletTransform
Stationary wavelet Transform operator.
Initialization
Stationary wavelet Transform operator.
Parameters
x_shape : ArrayLike The shape of the data to be wavelet transformed. wavelet : str The type of wavelet to use. level : int Number of wavelet decomposition levels. axes : int or tuple of int, optional Axes along which to perform the transform. Default is None. pad_on_demand : str, optional The padding type to fit the
2 ** level
shape requirements. Default is ‘constant’. Options are all thenumpy.pad
padding modes. normalized : bool, optional Whether to use a normalized transform. Default is True.Raises
ValueError If the pywavelets package is not available or its version is not adequate.
- direct_swt(x: numpy.typing.NDArray) list [source]
Perform the direct wavelet transform.
Parameters
x : NDArray Data to transform.
Returns
list Transformed data.
- class corrct.operators.TransformGradient(x_shape: numpy.typing.ArrayLike, axes: Optional[numpy.typing.ArrayLike] = None, pad_mode: str = 'edge')[source]
Bases:
corrct.operators.BaseTransform
Gradient operator.
Parameters
x_shape : ArrayLike Shape of the data to be transformed. axes : Optional[ArrayLike], optional Axes along which to do the gradient. The default is None. pad_mode : str, optional Padding mode of the gradient. The default is “edge”.
Initialization
Initialize the base operator class.
- gradient(x: numpy.typing.NDArray) numpy.typing.NDArray [source]
Compute the gradient.
Parameters
x : NDArray Input data.
Returns
NDArray Gradient of data.
- class corrct.operators.TransformFourier(x_shape: numpy.typing.ArrayLike, axes: Optional[numpy.typing.ArrayLike] = None)[source]
Bases:
corrct.operators.BaseTransform
Fourier transform operator.
Initialization
Fourier transform.
Parameters
x_shape : ArrayLike Shape of the data to be Fourier transformed. axes : Optional[ArrayLike], optional Axes along which to do the Fourier transform.
Returns
None
- fft(x: numpy.typing.NDArray) numpy.typing.NDArray [source]
Compute the fft.
Parameters
x : NDArray Input data.
Returns
NDArray FFT of data.
- class corrct.operators.TransformLaplacian(x_shape: numpy.typing.ArrayLike, axes: Optional[numpy.typing.ArrayLike] = None, pad_mode: str = 'edge')[source]
Bases:
corrct.operators.BaseTransform
Laplacian transform operator.
Parameters
x_shape : ArrayLike Shape of the data to be transformed. axes : ArrayLike, optional Axes along which to do the Laplacian. The default is None. pad_mode : str, optional Padding mode of the Laplacian. The default is “edge”.
Initialization
Initialize the base operator class.
- class corrct.operators.TransformSVD(x_shape, axes_rows=(0,), axes_cols=(-1,), rescale: bool = False)[source]
Bases:
corrct.operators.BaseTransform
Singular value decomposition based decomposition operator.
Initialization
Singular value decomposition operator.
The SVD decomposition will be done over the flattened rows vs flatted cols. This means that the channels should always be the rows (expected to be only one dimension, usually), while the volume dimensions should always be the columns (expected to be the last two or three dimensions).
Parameters
x_shape : numpy.array_like Shape of the data to be wavelet transformed. axes_rows : tuple of int, optional Axes expanded in rows of the SVD. Defaults to (0, ). axes_cols : tuple of int, optional Axes expanded in cols of the SVD. Defaults to (-1, ).
Raises
IndexError In case the axes are outside the range.
- U: Optional[numpy.typing.NDArray]
None
- Vt: Optional[numpy.typing.NDArray]
None
- direct_svd(x)[source]
Performs the SVD decomposition.
Parameters
x :
numpy.array_like
Data to transform.Returns
tuple(U, s, Vt) Transformed data.