ndim (int or None (default=None)) – Number of dimensions that array should have. If None, the dimensions
are not checked
dtype (string, type, list of types or None (default='numeric')) – Data type of result. If None, the dtype of the input is preserved.
If ‘numeric’, dtype is preserved unless array.dtype is object.
If dtype is a list of types, conversion on the first type is only
performed if the dtype of the input is not in the list.
force_all_finite (boolean (default=True)) – Whether to raise an error on np.inf and np.nan in array
force_strictly_positive (boolean (default=False)) – Whether to raise an error if any array elements are <= 0
Returns:
array_converted – The converted and validated array.
img (2d array, shape (height, width)) – Image to interpolate.
f (3d array, shape (2, height, width)) – Coordinates of at which img is defined. First dimension f[0] corresponds
to y-coordinates, second dimension f[1] is x-coordinates.
order (int (default=1)) – Order of the interpolation. Must be in the range 0-2.
fill_value (float (default=0.)) – Value used for points outside the boundaries.
Returns:
Image interpolated on to regular gird defined by: x = 0:(width-1),
y = 0:(height-1).
img (2d array, shape (height, width)) – Image to interpolate. This function assumes a grid of sample points:
x = 0:(width-1), y = 0:(height-1).
f (3d array, shape (2, height, width)) – Coordinates of interpolated points. First dimension f[0] corresponds to
y-coordinates, second dimension f[1] is x-coordinates.
order (int (default=1)) – Order of the spline interpolation. Must be in the range 0-5.
fill_value (float (default=0.)) – Value used for points outside the boundaries.
ndim (int or None (default=None)) – Number of dimensions that array should have. If None, the dimensions
are not checked
dtype (string, type, list of types or None (default='numeric')) – Data type of result. If None, the dtype of the input is preserved.
If ‘numeric’, dtype is preserved unless array.dtype is object.
If dtype is a list of types, conversion on the first type is only
performed if the dtype of the input is not in the list.
force_all_finite (boolean (default=True)) – Whether to raise an error on np.inf and np.nan in array
force_strictly_positive (boolean (default=False)) – Whether to raise an error if any array elements are <= 0
Returns:
array_converted – The converted and validated array.
One-dimensional linear interpolation for monotonically increasing sample points.
Returns the one-dimensional piecewise linear interpolant to a function
with given discrete data points (xp, fp), evaluated at x.
Parameters:
x (array_like) – The x-coordinates at which to evaluate the interpolated values.
xp (1-D sequence of floats) – The x-coordinates of the data points, must be increasing if argument
period is not specified. Otherwise, xp is internally sorted after
normalizing the periodic boundaries with xp=xp%period.
fp (1-D sequence of float or complex) – The y-coordinates of the data points, same length as xp.
left (optional float or complex corresponding to fp) – Value to return for x < xp[0], default is fp[0].
right (optional float or complex corresponding to fp) – Value to return for x > xp[-1], default is fp[-1].
period (None or float, optional) –
A period for the x-coordinates. This parameter allows the proper
interpolation of angular x-coordinates. Parameters left and right
are ignored if period is specified.
New in version 1.10.0.
Returns:
y – The interpolated values, same shape as x.
Return type:
float or complex (corresponding to fp) or ndarray
Raises:
ValueError – If xp and fp have different length
If xp or fp are not 1-D sequences
If period == 0
See also
scipy.interpolate
Warning
The x-coordinate sequence is expected to be increasing, but this is not
explicitly enforced. However, if the sequence xp is non-increasing,
interpolation results are meaningless.
Note that, since NaN is unsortable, xp also cannot contain NaNs.
A simple check for xp being strictly increasing is:
Get the (smoothed) probability density function of a signal.
Performs the following operations:
1. Smooth sigma with a Gaussian filter
2. Normalize signal such that it sums to 1
3. Add epsilon to ensure signal is strictly positive
4. Re-normalize signal such that it sums to total
Parameters:
input (ndarray) – Input array
sigma (scalar) – Standard deviation for Gaussian kernel. The standard deviations of the
Gaussian filter are given for each axis as a sequence, or as a single
number, in which case it is equal for all axes.
epsilon (scalar) – Offset to ensure that signal is strictly positive.
ndim (int or None (default=None)) – Number of dimensions that array should have. If None, the dimensions
are not checked
dtype (string, type, list of types or None (default='numeric')) – Data type of result. If None, the dtype of the input is preserved.
If ‘numeric’, dtype is preserved unless array.dtype is object.
If dtype is a list of types, conversion on the first type is only
performed if the dtype of the input is not in the list.
force_all_finite (boolean (default=True)) – Whether to raise an error on np.inf and np.nan in array
force_strictly_positive (boolean (default=False)) – Whether to raise an error if any array elements are <= 0
Returns:
array_converted – The converted and validated array.
Return the Discrete Cosine Transform of arbitrary type sequence x.
Parameters:
x (array_like) – The input array.
type ({1, 2, 3, 4}, optional) – Type of the DCT (see Notes). Default type is 2.
n (int, optional) – Length of the transform. If n<x.shape[axis], x is
truncated. If n>x.shape[axis], x is zero-padded. The
default results in n=x.shape[axis].
axis (int, optional) – Axis along which the dct is computed; the default is over the
last axis (i.e., axis=-1).
norm ({None, 'ortho'}, optional) – Normalization mode (see Notes). Default is None.
overwrite_x (bool, optional) – If True, the contents of x can be destroyed; the default is False.
For a single dimension array x, dct(x,norm='ortho') is equal to
MATLAB dct(x).
There are, theoretically, 8 types of the DCT, only the first 4 types are
implemented in scipy. ‘The’ DCT generally refers to DCT type 2, and ‘the’
Inverse DCT generally refers to DCT type 3.
Type I
There are several definitions of the DCT-I; we use the following
(for norm=None)
The (unnormalized) DCT-III is the inverse of the (unnormalized) DCT-II, up
to a factor 2N. The orthonormalized DCT-III is exactly the inverse of
the orthonormalized DCT-II.
Type IV
There are several definitions of the DCT-IV; we use the following
(for norm=None)
If norm='ortho', y[k] is multiplied by a scaling factor f
\[f = \frac{1}{\sqrt{2N}}\]
New in version 1.2.0: Support for DCT-IV.
References
Examples
The Type 1 DCT is equivalent to the FFT (though faster) for real,
even-symmetrical inputs. The output is also real and even-symmetrical.
Half of the FFT input is used to generate half of the FFT output:
img (2d array, shape (height, width)) – Image to interpolate.
f (3d array, shape (2, height, width)) – Coordinates of at which img is defined. First dimension f[0] corresponds
to y-coordinates, second dimension f[1] is x-coordinates.
order (int (default=1)) – Order of the interpolation. Must be in the range 0-2.
fill_value (float (default=0.)) – Value used for points outside the boundaries.
Returns:
Image interpolated on to regular gird defined by: x = 0:(width-1),
y = 0:(height-1).
Return the Inverse Discrete Cosine Transform of an arbitrary type sequence.
Parameters:
x (array_like) – The input array.
type ({1, 2, 3, 4}, optional) – Type of the DCT (see Notes). Default type is 2.
n (int, optional) – Length of the transform. If n<x.shape[axis], x is
truncated. If n>x.shape[axis], x is zero-padded. The
default results in n=x.shape[axis].
axis (int, optional) – Axis along which the idct is computed; the default is over the
last axis (i.e., axis=-1).
norm ({None, 'ortho'}, optional) – Normalization mode (see Notes). Default is None.
overwrite_x (bool, optional) – If True, the contents of x can be destroyed; the default is False.
For a single dimension array x, idct(x,norm='ortho') is equal to
MATLAB idct(x).
‘The’ IDCT is the IDCT of type 2, which is the same as DCT of type 3.
IDCT of type 1 is the DCT of type 1, IDCT of type 2 is the DCT of type
3, and IDCT of type 3 is the DCT of type 2. IDCT of type 4 is the DCT
of type 4. For the definition of these types, see dct.
Examples
The Type 1 DCT is equivalent to the DFT for real, even-symmetrical
inputs. The output is also real and even-symmetrical. Half of the IFFT
input is used to generate half of the IFFT output:
img (2d array, shape (height, width)) – Image to interpolate. This function assumes a grid of sample points:
x = 0:(width-1), y = 0:(height-1).
f (3d array, shape (2, height, width)) – Coordinates of interpolated points. First dimension f[0] corresponds to
y-coordinates, second dimension f[1] is x-coordinates.
order (int (default=1)) – Order of the spline interpolation. Must be in the range 0-5.
fill_value (float (default=0.)) – Value used for points outside the boundaries.
Get the (smoothed) probability density function of a signal.
Performs the following operations:
1. Smooth sigma with a Gaussian filter
2. Normalize signal such that it sums to 1
3. Add epsilon to ensure signal is strictly positive
4. Re-normalize signal such that it sums to total
Parameters:
input (ndarray) – Input array
sigma (scalar) – Standard deviation for Gaussian kernel. The standard deviations of the
Gaussian filter are given for each axis as a sequence, or as a single
number, in which case it is equal for all axes.
epsilon (scalar) – Offset to ensure that signal is strictly positive.
ndim (int or None (default=None)) – Number of dimensions that array should have. If None, the dimensions
are not checked
dtype (string, type, list of types or None (default='numeric')) – Data type of result. If None, the dtype of the input is preserved.
If ‘numeric’, dtype is preserved unless array.dtype is object.
If dtype is a list of types, conversion on the first type is only
performed if the dtype of the input is not in the list.
force_all_finite (boolean (default=True)) – Whether to raise an error on np.inf and np.nan in array
force_strictly_positive (boolean (default=False)) – Whether to raise an error if any array elements are <= 0
Returns:
array_converted – The converted and validated array.
Reconstruct an image from the radon transform, using the filtered
back projection algorithm.
Parameters:
radon_image (array) – Image containing radon transform (sinogram). Each column of
the image corresponds to a projection along a different
angle. The tomography rotation axis should lie at the pixel
index radon_image.shape[0]//2 along the 0th dimension of
radon_image.
theta (array_like, optional) – Reconstruction angles (in degrees). Default: m angles evenly spaced
between 0 and 180 (if the shape of radon_image is (N, M)).
output_size (int, optional) – Number of rows and columns in the reconstruction.
filter_name (str, optional) – Filter used in frequency domain filtering. Ramp filter used by default.
Filters available: ramp, shepp-logan, cosine, hamming, hann.
Assign None to use no filter.
interpolation (str, optional) – Interpolation method used in reconstruction. Methods available:
‘linear’, ‘nearest’, and ‘cubic’ (‘cubic’ is slow).
circle (boolean, optional) – Assume the reconstructed image is zero outside the inscribed circle.
Also changes the default output_size to match the behaviour of
radon called with circle=True.
reconstructed (ndarray) – Reconstructed image. The rotation axis will be located in the pixel
with indices
(reconstructed.shape[0]//2,reconstructed.shape[1]//2).
.. versionchanged:: 0.19 – In iradon, filter argument is deprecated in favor of
filter_name.
References
Notes
It applies the Fourier slice theorem to reconstruct an image by
multiplying the frequency domain of the filter with the FFT of the
projection data. This algorithm is called filtered back projection.
Calculates the radon transform of an image given specified
projection angles.
Parameters:
image (array_like) – Input image. The rotation axis will be located in the pixel with
indices (image.shape[0]//2,image.shape[1]//2).
theta (array_like, optional) – Projection angles (in degrees). If None, the value is set to
np.arange(180).
circle (boolean, optional) – Assume image is zero outside the inscribed circle, making the
width of each projection (the first dimension of the sinogram)
equal to min(image.shape).
radon_image – Radon transform (sinogram). The tomography rotation axis will lie
at the pixel index radon_image.shape[0]//2 along the 0th
dimension of radon_image.
Get the (smoothed) probability density function of a signal.
Performs the following operations:
1. Smooth sigma with a Gaussian filter
2. Normalize signal such that it sums to 1
3. Add epsilon to ensure signal is strictly positive
4. Re-normalize signal such that it sums to total
Parameters:
input (ndarray) – Input array
sigma (scalar) – Standard deviation for Gaussian kernel. The standard deviations of the
Gaussian filter are given for each axis as a sequence, or as a single
number, in which case it is equal for all axes.
epsilon (scalar) – Offset to ensure that signal is strictly positive.
ndim (int or None (default=None)) – Number of dimensions that array should have. If None, the dimensions
are not checked
dtype (string, type, list of types or None (default='numeric')) – Data type of result. If None, the dtype of the input is preserved.
If ‘numeric’, dtype is preserved unless array.dtype is object.
If dtype is a list of types, conversion on the first type is only
performed if the dtype of the input is not in the list.
force_all_finite (boolean (default=True)) – Whether to raise an error on np.inf and np.nan in array
force_strictly_positive (boolean (default=False)) – Whether to raise an error if any array elements are <= 0
Returns:
array_converted – The converted and validated array.
n (int, optional) – Length of the Fourier transform. If n<x.shape[axis], x is
truncated. If n>x.shape[axis], x is zero-padded. The
default results in n=x.shape[axis].
axis (int, optional) – Axis along which the fft’s are computed; the default is over the
last axis (i.e., axis=-1).
overwrite_x (bool, optional) – If True, the contents of x can be destroyed; the default is False.
The packing of the result is “standard”: If A=fft(a,n), then
A[0] contains the zero-frequency term, A[1:n/2] contains the
positive-frequency terms, and A[n/2:] contains the negative-frequency
terms, in order of decreasingly negative frequency. So ,for an 8-point
transform, the frequencies of the result are [0, 1, 2, 3, -4, -3, -2, -1].
To rearrange the fft output so that the zero-frequency component is
centered, like [-4, -3, -2, -1, 0, 1, 2, 3], use fftshift.
Both single and double precision routines are implemented. Half precision
inputs will be converted to single precision. Non-floating-point inputs
will be converted to double precision. Long-double precision inputs are
not supported.
This function is most efficient when n is a power of two, and least
efficient when n is prime.
Note that if x is real-valued, then A[j]==A[n-j].conjugate().
If x is real-valued and n is even, then A[n/2] is real.
If the data type of x is real, a “real FFT” algorithm is automatically
used, which roughly halves the computation time. To increase efficiency
a little further, use rfft, which does the same calculation, but only
outputs half of the symmetrical spectrum. If the data is both real and
symmetrical, the dct can again double the efficiency by generating
half of the spectrum from half of the signal.
Examples
>>> fromscipy.fftpackimportfft,ifft>>> x=np.arange(5)>>> np.allclose(fft(ifft(x)),x,atol=1e-15)# within numerical accuracy.True
n (int, optional) – Length of the inverse Fourier transform. If n<x.shape[axis],
x is truncated. If n>x.shape[axis], x is zero-padded.
The default results in n=x.shape[axis].
axis (int, optional) – Axis along which the ifft’s are computed; the default is over the
last axis (i.e., axis=-1).
overwrite_x (bool, optional) – If True, the contents of x can be destroyed; the default is False.
Both single and double precision routines are implemented. Half precision
inputs will be converted to single precision. Non-floating-point inputs
will be converted to double precision. Long-double precision inputs are
not supported.
This function is most efficient when n is a power of two, and least
efficient when n is prime.
If the data type of x is real, a “real IFFT” algorithm is automatically
used, which roughly halves the computation time.
Examples
>>> fromscipy.fftpackimportfft,ifft>>> importnumpyasnp>>> x=np.arange(5)>>> np.allclose(ifft(fft(x)),x,atol=1e-15)# within numerical accuracy.True
Get the (smoothed) probability density function of a signal.
Performs the following operations:
1. Smooth sigma with a Gaussian filter
2. Normalize signal such that it sums to 1
3. Add epsilon to ensure signal is strictly positive
4. Re-normalize signal such that it sums to total
Parameters:
input (ndarray) – Input array
sigma (scalar) – Standard deviation for Gaussian kernel. The standard deviations of the
Gaussian filter are given for each axis as a sequence, or as a single
number, in which case it is equal for all axes.
epsilon (scalar) – Offset to ensure that signal is strictly positive.
itransform calculates the inverse of the CDT. It receives a transport displacement
and the reference, and finds the one dimensional distribution I from it.
input:
Transport displacement map
The reference used for calculating the CDT
stransform calculates the transport transform (CDT) of a signal I for signals that may change sign
input:
The original density I
x -> domain of the density I
output:
The 4 components of the transform of signed signals: the CDT of the positive and the negative
part of I, and the total masses of the positive and the negative part of I
One-dimensional linear interpolation for monotonically increasing sample points.
Returns the one-dimensional piecewise linear interpolant to a function
with given discrete data points (xp, fp), evaluated at x.
Parameters:
x (array_like) – The x-coordinates at which to evaluate the interpolated values.
xp (1-D sequence of floats) – The x-coordinates of the data points, must be increasing if argument
period is not specified. Otherwise, xp is internally sorted after
normalizing the periodic boundaries with xp=xp%period.
fp (1-D sequence of float or complex) – The y-coordinates of the data points, same length as xp.
left (optional float or complex corresponding to fp) – Value to return for x < xp[0], default is fp[0].
right (optional float or complex corresponding to fp) – Value to return for x > xp[-1], default is fp[-1].
period (None or float, optional) –
A period for the x-coordinates. This parameter allows the proper
interpolation of angular x-coordinates. Parameters left and right
are ignored if period is specified.
New in version 1.10.0.
Returns:
y – The interpolated values, same shape as x.
Return type:
float or complex (corresponding to fp) or ndarray
Raises:
ValueError – If xp and fp have different length
If xp or fp are not 1-D sequences
If period == 0
See also
scipy.interpolate
Warning
The x-coordinate sequence is expected to be increasing, but this is not
explicitly enforced. However, if the sequence xp is non-increasing,
interpolation results are meaningless.
Note that, since NaN is unsortable, xp also cannot contain NaNs.
A simple check for xp being strictly increasing is: