pylops.signalprocessing.Downsample2D¶
- class pylops.signalprocessing.Downsample2D(dims, factors=2, sigma=None, truncate=4.0, axes=(-2, -1), method='fft', dtype='float64', name='D')[source]¶
2D downsampling operator.
Downsample a two (or more) dimensional array along a pair of
axesby applying an anti-aliasing Gaussian filter followed by subsampling with a given decimation factor in each of the two directions.- Parameters:
- dims
listorint Number of samples for each dimension.
- factors
intortuple, optional Decimation factors along each of the two
axes. If a single value is provided, the same factor is used in both directions.- sigma
floatortuple, optional Standard deviations (in number of samples) of the Gaussian filter along each of the two
axes. If a single value is provided, the same standard deviation is used in both directions. IfNone, the standard deviations are set to(factor - 1) / 2for each direction.- truncate
float, optional Number of standard deviations at which the Gaussian filter is truncated. The filter has
2 * int(truncate * sigma + 0.5) + 1samples along each direction.- axes
tuple, optional Axes along which downsampling is applied.
- method
str, optional Method used to calculate the Gaussian filtering (
auto,directorfft) - seescipy.signal.convolvefor details.- dtype
str, optional Type of elements in input array.
- name
str, optional Name of operator (to be used by
pylops.utils.describe.describe)
- dims
- Attributes:
- h
numpy.ndarray 2d Gaussian filter applied prior to subsampling.
- Cop
pylops.signalprocessing.Convolve2D Gaussian filtering operator.
- dims
tuple Shape of the array after the adjoint, but before flattening.
For example,
x_reshaped = (Op.H * y.ravel()).reshape(Op.dims).- dimsd
tuple Shape of the array after the forward, but before flattening.
For example,
y_reshaped = (Op * x.ravel()).reshape(Op.dimsd).- shape
tuple Operator shape.
- explicit
bool Operator contains a matrix that can be solved explicitly (
True) or not (False).
- h
- Raises:
- ValueError
If
dimshas less than 2 dimensions, ifaxes,factors, orsigmado not contain 2 elements, if any element offactorsis smaller than 1 or larger than half the size of the corresponding axis, or if any element ofsigmais negative.
See also
pylops.signalprocessing.Convolve2D2D convolution operator
pylops.RestrictionRestriction (or sampling) operator
Notes
The Downsample2D operator reduces the size of a two-dimensional array \(\mathbf{x}\) of size \(n_0 \times n_1\) by a factor \(f_0\) and \(f_1\) along the first and second direction, respectively. Direct subsampling of the input array would however lead to aliasing of any energy above the Nyquist wavenumber of the coarse grid; for this reason the array is first smoothed by a separable Gaussian kernel
\[h[p, q] = g_{\sigma_0}[p]\, g_{\sigma_1}[q], \qquad g_\sigma[p] = \frac{e^{-p^2 / (2\sigma^2)}} {\sum_{p'} e^{-p'^2 / (2\sigma^2)}}\]with \(|p| \leq r_0\), \(|q| \leq r_1\), and \(r_i = \lfloor \tau \sigma_i + 0.5 \rfloor\) where \(\tau\) is the
truncateparameter. In forward mode, filtering and subsampling are applied one after the other\[y[i, j] = \sum_{p=-r_0}^{r_0} \sum_{q=-r_1}^{r_1} h[p, q] \, x[f_0 i - p, f_1 j - q] \quad \forall i=0,\ldots,\lceil n_0 / f_0 \rceil - 1, \; j=0,\ldots,\lceil n_1 / f_1 \rceil - 1\]where the input array is assumed to be zero-padded outside of its boundaries. Since the adjoint of subsampling is zero-interleaving and the adjoint of convolution is correlation, in adjoint mode the data is first spread over the fine grid and then correlated with the same kernel
\[\begin{split}x[k, l] = \sum_{p=-r_0}^{r_0} \sum_{q=-r_1}^{r_1} h[p, q] \, \tilde{y}[k + p, l + q], \qquad \tilde{y}[k, l] = \begin{cases} y[k / f_0, l / f_1] & k \bmod f_0 = 0 \land l \bmod f_1 = 0\\ 0 & \text{otherwise} \end{cases}\end{split}\]Note that, as the Gaussian kernel is real and symmetric, the operator is effectively the composition of a self-adjoint smoothing operator and a restriction operator.
Methods
__init__(dims[, factors, sigma, truncate, ...])adjoint()apply_columns(cols)Apply subset of columns of operator
cond([uselobpcg])Condition number of linear operator.
conj()Complex conjugate operator
div(y[, niter, densesolver])Solve the linear problem \(\mathbf{y}=\mathbf{A}\mathbf{x}\).
dot(x)Matrix-matrix or matrix-vector multiplication.
eigs([neigs, symmetric, niter, uselobpcg])Most significant eigenvalues of linear operator.
matmat(X[, pool])Matrix-matrix multiplication.
matvec(x)Matrix-vector multiplication.
reset_count()Reset counters
rmatmat(X[, pool])Matrix-matrix multiplication.
rmatvec(x)Adjoint matrix-vector multiplication.
todense([backend])Return dense matrix.
toimag([forw, adj])Imag operator
toreal([forw, adj])Real operator
tosparse()Return sparse matrix.
trace([neval, method, backend])Trace of linear operator.
transpose()