Python API

This section includes information for using the pure Python API of bob.sp.

class bob.sp.BorderType

Bases: object

BorderType (C++ enumeration) - cannot be instantiated from Python

Use of the values available in this class as input for BorderType when required:

  • Zero

  • Constant

  • NearestNeighbour

  • Circular

  • Mirror

A dictionary containing all names and values available for this enumeration is available through the attribute entries.

Circular = 3
Constant = 1
Mirror = 4
NearestNeighbour = 2
Zero = 0
entries = {'Circular': 3, 'Constant': 1, 'Mirror': 4, 'NearestNeighbour': 2, 'Zero': 0}
class bob.sp.DCT1D(shape) new DCT1D operator

Bases: object

Calculates the direct DCT of a 1D array/signal. Input and output arrays are 1D NumPy arrays of type float64.

length

The length of the output vector

shape

A tuple that represents the size of the output vector

class bob.sp.DCT2D(shape) new DCT2D operator

Bases: object

Calculates the direct DCT of a 2D array/signal. Input and output arrays are 2D NumPy arrays of type float64.

height

The height of the output vector

shape

A tuple that represents the size of the output vector

width

The width of the output vector

class bob.sp.FFT1D(shape) new FFT1D operator

Bases: object

Calculates the direct FFT of a 1D array/signal. Input and output arrays are 1D NumPy arrays of type complex128.

length

The length of the output vector

shape

A tuple that represents the size of the output vector

class bob.sp.FFT2D(shape) new FFT2D operator

Bases: object

Calculates the direct FFT of a 2D array/signal. Input and output arrays are 2D NumPy arrays of type complex128.

height

The height of the output vector

shape

A tuple that represents the size of the output vector

width

The width of the output vector

class bob.sp.IDCT1D(shape) new IDCT1D operator

Bases: object

Calculates the inverse DCT of a 1D array/signal. Input and output arrays are 1D NumPy arrays of type float64.

length

The length of the output vector

shape

A tuple that represents the size of the output vector

class bob.sp.IDCT2D(shape) new IDCT2D operator

Bases: object

Calculates the inverse DCT of a 2D array/signal. Input and output arrays are 2D NumPy arrays of type float64.

height

The height of the output vector

shape

A tuple that represents the size of the output vector

width

The width of the output vector

class bob.sp.IFFT1D(shape) new IFFT1D operator

Bases: object

Calculates the inverse FFT of a 1D array/signal. Input and output arrays are 1D NumPy arrays of type complex128.

length

The length of the output vector

shape

A tuple that represents the size of the output vector

class bob.sp.IFFT2D(shape) new IFFT2D operator

Bases: object

Calculates the inverse FFT of a 2D array/signal. Input and output arrays are 2D NumPy arrays of type complex128.

height

The height of the output vector

shape

A tuple that represents the size of the output vector

width

The width of the output vector

class bob.sp.Quantization(dtype[, rounding=False[, num_levels=-1[, min_level=None[, max_level=None]]]])
class bob.sp.Quantization(quantization_table) None
class bob.sp.Quantization(other) None

Bases: object

Functor to quantize 1D or 2D signals into different number of levels. At the moment, only uint8 and uint16 data types are supported. The output array returned by this functor will always have a uint32 data type.

Parameters:

dtype

(numpy.dtype) The data type of arrays that are going to be input by this functor. Currently supported values are uint8 and uint16.

rounding

(bool) If set to True (defaults to False), performs Matlab-like uniform quantization with rounding (see http://www.mathworks.com/matlabcentral/newsreader/view_thread/275291).

num_levels

(int) the number of quantization levels. The default is the total number of discrete values permitted by the data type. For example, uint8 allows for 256 levels.

min_level

(scalar) Input values smaller than or equal to this value are scaled to this value prior to quantization. As a result, they will be scaled in the lowest quantization level. The data type of this scalar should be coercible to the datatype of the input.

max_level

(scalar) Input values higher than this value are scaled to this value prior to quantization. As a result, they will be scaled in the highest qunatization level. The data type of this scalar should be coercible to the datatype of the input.

quantization_table

(array) A 1-dimensional array matching the data type of input containing user-specified thresholds for the quantization. If Each element corresponds to the lower boundary of the particular quantization level. Eg. array([ 0,  5, 10]) means quantization in 3 levels. Input values in the range \([0,4]\) will be quantized to level 0, input values in the range \([5,9]\) will be quantized to level 1 and input values in the range \([10-\text{max}]\) will be quantized to level 2.

other

(Quantization) You can also initialize a Quantization object by passing another Quantization object as constructor parameter. This will create a deep-copy of this Quantization object.

Once this object has been created, it can be used through its () operator, by passing input and output parameters:

input

(array) a 1 or 2-dimensional uint8 or uint16 array of any size.

output

(array) The array where to store the output. This array should have the same dimensions of the input array, but have data type uint32. If this array is not provided, a new one is allocated internally and returned.

dtype

(numpy.dtype) The data type of arrays that are going to be input by this functor. Currently supported values are uint8 and uint16.

max_level

(scalar) Input values higher than this value are scaled to this value prior to quantization. As a result, they will be scaled in the highest qunatization level. The data type of this scalar should be coercible to the datatype of the input.

min_level

Input values smaller than or equal to this value are scaled to this value prior to quantization. As a result, they will be scaled in the lowest quantization level. The data type of this scalar should be coercible to the datatype of the input.

num_levels

(int) the number of quantization levels. The default is the total number of discrete values permitted by the data type. For example, uint8 allows for 256 levels.

quantization_level()

Calculates the quantization level for a single input value, given the current threshold table.

quantization_table

(array) A 1-dimensional array matching the data type of input containing user-specified thresholds for the quantization. If Each element corresponds to the lower boundary of the particular quantization level. Eg. array([ 0,  5, 10]) means quantization in 3 levels. Input values in the range \([0,4]\) will be quantized to level 0, input values in the range \([5,9]\) will be quantized to level 1 and input values in the range \([10-\text{max}]\) will be quantized to level 2.

quantization_type

(str) Possible values of this parameter:

uniform

uniform quantization of the input signal within the range between min_level and max_level

uniform_rounding

same as uniform above, but implemented in a similar way to Matlab quantization (see http://www.mathworks.com/matlabcentral/newsreader/view_thread/275291);

user_spec

quantization according to user-specified quantization table of thresholds.

bob.sp.dct(src[, dst]) array

Computes the direct Discrete Cosine Transform of a 1D or 2D array/signal of type float64. Allocates a new output array if dst is not provided. If it is, then it must be of the same type and shape as src.

Parameters:

src

[array] A 1 or 2-dimensional array of type float64 in which the DCT operation will be performed.

dst

[array, optional] A 1 or 2-dimensional array of type float64 and matching dimensions to src in which the result of the operation will be stored.

Returns a 1 or 2-dimensional array, of the same dimension as src, of type float64, containing the DCT of the input signal.

bob.sp.extrapolate(src, dst[[, border=bob.sp.BorderType.Zero], value=0.]) None

Extrapolates values in the given array using the specified border type. Works for 1 or 2D input arrays. The parameter value is only used if the border type is set to bob.sp.BorderType.Constant. It is, by default, set to 0., or the equivalent on the datatype passed as input. For example, False, if the input is boolean and 0+0j, if it is complex.

bob.sp.extrapolate_circular(src, dst)[source]

Extrapolates the values in src to dst, using circular extrapolation.

Input src (and dst) arrays can be 1 or 2-dimensional. For more details, read the help for extrapolate().

Parameters:

src

(array) A 1 or 2D array that is going to be extrapolated

dst

(array) A pre-allocated array, with the same number of dimensions as in src, where the extrapolation results will be placed.

Returns None, raises in case of errors.

bob.sp.extrapolate_constant(src, dst, constant)[source]

Extrapolates the values in src to dst, with a constant value.

Input src (and dst) arrays can be 1 or 2-dimensional. For more details, read the help for extrapolate().

Parameters:

src

(array) A 1 or 2D array that is going to be extrapolated

dst

(array) A pre-allocated array, with the same number of dimensions as in src, where the extrapolation results will be placed.

constant

(scalar) A scalar with matching type of src and dst, containing the value that will be used to extrapolate src into dst.

Returns None, raises in case of errors.

bob.sp.extrapolate_mirror(src, dst)[source]

Extrapolates the values in src to dst, mirroring src.

Input src (and dst) arrays can be 1 or 2-dimensional. For more details, read the help for extrapolate().

Parameters:

src

(array) A 1 or 2D array that is going to be extrapolated

dst

(array) A pre-allocated array, with the same number of dimensions as in src, where the extrapolation results will be placed.

Returns None, raises in case of errors.

bob.sp.extrapolate_nearest(src, dst)[source]

Extrapolates the values in src to dst, with nearest values.

Input src (and dst) arrays can be 1 or 2-dimensional. For more details, read the help for extrapolate().

Parameters:

src

(array) A 1 or 2D array that is going to be extrapolated

dst

(array) A pre-allocated array, with the same number of dimensions as in src, where the extrapolation results will be placed.

Returns None, raises in case of errors.

bob.sp.extrapolate_zero(src, dst)[source]

Extrapolates the values in src to dst with zeros.

Input src (and dst) arrays can be 1 or 2-dimensional. For more details, read the help for extrapolate().

Parameters:

src

(array) A 1 or 2D array that is going to be extrapolated

dst

(array) A pre-allocated array, with the same number of dimensions as in src, where the extrapolation results will be placed.

Returns None, raises in case of errors.

bob.sp.fft(src[, dst]) array

Computes the direct Fast Fourier Transform of a 1D or 2D array/signal of type complex128. Allocates a new output array if dst is not provided. If it is, then it must be of the same type and shape as src.

Parameters:

src

[array] A 1 or 2-dimensional array of type complex128 in which the FFT operation will be performed.

dst

[array, optional] A 1 or 2-dimensional array of type complex128 and matching dimensions to src in which the result of the operation will be stored.

Returns a 1 or 2-dimensional array, of the same dimension as src, of type complex128, containing the FFT of the input signal.

bob.sp.fftshift(src[, dst]) array

If a 1D complex128 array is passed, inverses the two halves of that array and returns the result as a new array. If a 2D complex128 array is passed, swaps the four quadrants of the array and returns the result as a new array.

Parameters:

src [array] A 1 or 2-dimensional array of type complex128 with the signal to be shifted.

dst [array, optional] A 1 or 2-dimensional array of type complex128 and matching dimensions to src in which the result of the operation will be stored.

Returns a 1 or 2-dimensional array, of the same dimension as src, of type complex128, containing the shifted version of theinput.

bob.sp.get_config()[source]

Returns a string containing the configuration information.

bob.sp.idct(src[, dst]) array

Computes the inverse Discrete Cosinte Transform of a 1D or 2D transform of type float64. Allocates a new output array if dst is not provided. If it is, then it must be of the same type and shape as src.

Parameters:

src

[array] A 1 or 2-dimensional array of type float64 in which the inverse DCT operation will be performed.

dst

[array, optional] A 1 or 2-dimensional array of type float64 and matching dimensions to src in which the result of the operation will be stored.

Returns a 1 or 2-dimensional array, of the same dimension as src, of type float64, containing the inverse DCT of the input transform.

bob.sp.ifft(src[, dst]) array

Computes the inverse Fast Fourier Transform of a 1D or 2D transform of type complex128. Allocates a new output array if dst is not provided. If it is, then it must be of the same type and shape as src.

Parameters:

src

[array] A 1 or 2-dimensional array of type complex128 in which the inverse FFT operation will be performed.

dst

[array, optional] A 1 or 2-dimensional array of type complex128 and matching dimensions to src in which the result of the operation will be stored.

Returns a 1 or 2-dimensional array, of the same dimension as src, of type complex128, containing the inverse FFT of the input transform.

bob.sp.ifftshift(src[, dst]) array

This method undoes what fftshift() does. It accepts 1 or 2-dimensional arrays of type complex128.

Parameters:

src [array] A 1 or 2-dimensional array of type complex128 with the signal to be shifted.

dst [array, optional] A 1 or 2-dimensional array of type complex128 and matching dimensions to src in which the result of the operation will be stored.

Returns a 1 or 2-dimensional array, of the same dimension as src, of type complex128, containing the shifted version of theinput.