sporco.signal¶
Signal and image processing functions.
Functions
|
Return a complex array of samples drawn from a standard normal distribution. |
|
Return image with salt & pepper noise imposed on it. |
|
Return random mask image with values in \(\{0,1\}\). |
|
Convert an RGB image (or images) to grayscale. |
|
Compute gradient of x along axis axis. |
|
Compute transpose of gradient of x along axis axis. |
|
Construct a set of filters for computing gradients in the frequency domain. |
|
Lowpass filter based on Tikhonov regularization. |
|
Sample a multivariate Gaussian pdf, normalised to have unit sum. |
|
Local contrast normalisation of an image. |
Function Descriptions¶
- sporco.signal.complex_randn(*args)[source]¶
Return a complex array of samples drawn from a standard normal distribution.
- Parameters:
- d0, d1, …, dnint
Dimensions of the random array
- Returns:
- andarray
Random array of shape (d0, d1, …, dn)
- sporco.signal.spnoise(s, frc, smn=0.0, smx=1.0)[source]¶
Return image with salt & pepper noise imposed on it.
- Parameters:
- sndarray
Input image
- frcfloat
Desired fraction of pixels corrupted by noise
- smnfloat, optional (default 0.0)
Lower value for noise (pepper)
- smxfloat, optional (default 1.0)
Upper value for noise (salt)
- Returns:
- snndarray
Noisy image
- sporco.signal.rndmask(shp, frc, dtype=None)[source]¶
Return random mask image with values in \(\{0,1\}\).
- Parameters:
- stuple
Mask array shape
- frcfloat
Desired fraction of zero pixels
- dtypedata-type or None, optional (default None)
Data type of mask array
- Returns:
- mskndarray
Mask image
- sporco.signal.rgb2gray(rgb)[source]¶
Convert an RGB image (or images) to grayscale.
- Parameters:
- rgbndarray
RGB image as Nr x Nc x 3 or Nr x Nc x 3 x K array
- Returns:
- gryndarray
Grayscale image as Nr x Nc or Nr x Nc x K array
- sporco.signal.grad(x, axis, zero_pad=False)[source]¶
Compute gradient of x along axis axis.
The form of the gradient operator depends on parameter zero_pad. If it is False, the operator is of the form
\[\begin{split}\left(\begin{array}{rrrrr} -1 & 1 & 0 & \ldots & 0\\ 0 & -1 & 1 & \ldots & 0\\ \vdots & \vdots & \ddots & \ddots & \vdots\\ 0 & 0 & \ldots & -1 & 1\\ 0 & 0 & \dots & 0 & 0 \end{array}\right) \;,\end{split}\]mapping \(\mathbb{R}^N \rightarrow \mathbb{R}^N\). If parameter zero_pad is True, the operator is of the form
\[\begin{split}\left(\begin{array}{rrrrr} 1 & 0 & 0 & \ldots & 0\\ -1 & 1 & 0 & \ldots & 0\\ 0 & -1 & 1 & \ldots & 0\\ \vdots & \vdots & \ddots & \ddots & \vdots\\ 0 & 0 & \ldots & -1 & 1\\ 0 & 0 & \ldots & 0 & -1 \end{array}\right) \;,\end{split}\]mapping \(\mathbb{R}^N \rightarrow \mathbb{R}^{N + 1}\).
- Parameters:
- xarray_like
Input array
- axisint
Axis on which gradient is to be computed
- zero_padboolean
Flag selecting type of gradient
- Returns:
- xgndarray
Output array
- sporco.signal.gradT(x, axis, zero_pad=False)[source]¶
Compute transpose of gradient of x along axis axis.
See
grad
for a description of the dependency of the gradient operator on parameter zero_pad.
- Parameters:
- xarray_like
Input array
- axisint
Axis on which gradient transpose is to be computed
- zero_padboolean
Flag selecting type of gradient
- Returns:
- xgndarray
Output array
- sporco.signal.gradient_filters(ndim, axes, axshp, dtype=None)[source]¶
Construct a set of filters for computing gradients in the frequency domain.
- Parameters:
- ndiminteger
Total number of dimensions in array in which gradients are to be computed
- axestuple of integers
Axes on which gradients are to be computed
- axshptuple of integers
Shape of axes on which gradients are to be computed
- dtypedtype, optional (default np.float32)
Data type of output arrays
- Returns:
- Gfndarray
Frequency domain gradient operators \(\hat{G}_i\)
- GHGfndarray
Sum of products \(\sum_i \hat{G}_i^H \hat{G}_i\)
- sporco.signal.tikhonov_filter(s, lmbda, npd=16)[source]¶
Lowpass filter based on Tikhonov regularization.
Lowpass filter image(s) and return low and high frequency components, consisting of the lowpass filtered image and its difference with the input image. The lowpass filter is equivalent to Tikhonov regularization with lmbda as the regularization parameter and a discrete gradient as the operator in the regularization term, i.e. the lowpass component is the solution to
\[\mathrm{argmin}_\mathbf{x} \; (1/2) \left\|\mathbf{x} - \mathbf{s} \right\|_2^2 + (\lambda / 2) \sum_i \| G_i \mathbf{x} \|_2^2 \;\;,\]where \(\mathbf{s}\) is the input image, \(\lambda\) is the regularization parameter, and \(G_i\) is an operator that computes the discrete gradient along image axis \(i\). Once the lowpass component \(\mathbf{x}\) has been computed, the highpass component is just \(\mathbf{s} - \mathbf{x}\).
- Parameters:
- sarray_like
Input image or array of images.
- lmbdafloat
Regularization parameter controlling lowpass filtering.
- npdint, optional (default=16)
Number of samples to pad at image boundaries.
- Returns:
- slparray_like
Lowpass image or array of images.
- shparray_like
Highpass image or array of images.
- sporco.signal.gaussian(shape, sd=1.0)[source]¶
Sample a multivariate Gaussian pdf, normalised to have unit sum.
- Parameters:
- shapetuple
Shape of output array.
- sdfloat, optional (default 1.0)
Standard deviation of Gaussian pdf.
- Returns:
- gcndarray
Sampled Gaussian pdf.
- sporco.signal.local_contrast_normalise(s, n=7, c=None)[source]¶
Local contrast normalisation of an image.
Perform local contrast normalisation [29] of an image, consisting of subtraction of the local mean and division by the local norm. The original image can be reconstructed from the contrast normalised image as (snrm * scn) + smn.
- Parameters:
- sarray_like
Input image or array of images.
- nint, optional (default 7)
The size of the local region used for normalisation is \(2n+1\).
- cfloat, optional (default None)
The smallest value that can be used in the divisive normalisation. If None, this value is set to the mean of the local region norms.
- Returns:
- scnndarray
Contrast normalised image(s)
- smnndarray
Additive normalisation correction
- snrmndarray
Multiplicative normalisation correction