DWT API

class DWT2D

A two dimensional multiscale discrete wavelet transform (DWT).

../_images/dwt2d.png

Image decomposition (i.e. analysis or forward transformation) is performed by decompose().

cv::Mat image = ...;
DWT2D dwt(Wavelet::create("db2"));
DWT2D::Coeffs coeffs = dwt.decompose(image);
Alternatively, instances of this class are callable.
DWT2D::Coeffs coeffs = dwt(image);
A third option is the functional interface.
DWT2D::Coeffs coeffs = dwt2d(image, "db2");

Image reconstruction (i.e. synthesis or inverse transformation) is accomplished with reconstruct()

cv::Mat reconstructed_image = dwt.reconstruct(coeffs);
or DWT2D::Coeffs::reconstruct()
cv::Mat reconstructed_image = coeffs.reconstruct();

See also

FilterBank, dwt2d

Public Functions

DWT2D(
const Wavelet &wavelet,
cv::BorderTypes border_type = cv::BORDER_DEFAULT,
)

Construct a new DWT2D object.

Parameters:
  • wavelet[in] The wavelet.

  • border_type[in] The border exptrapolation method.

DWT2D(
const DWT2D &other,
) = default

Copy Constructor.

DWT2D(
DWT2D &&other,
) = default

Move Constructor.

inline auto operator()(
auto&&... args,
) const

Alias of decompose().

inline Coeffs decompose(
cv::InputArray image,
int levels,
) const

Performs a multiscale DWT.

Parameters:
  • image[in] The image to be transformed.

  • levels[in] The number of decomposition levels. Must be levels \(\gt\) 1.

Throws:

cv::Exception – If levels is out of range.

void decompose(
cv::InputArray image,
Coeffs &coeffs,
int levels,
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:
  • image[in] The image to be transformed.

  • coeffs[out] The resulting DWT coefficients.

  • levels[in] The number of decomposition levels. Must be levels \(\gt\) 1.

Throws:

cv::Exception – If levels is out of range.

inline Coeffs decompose(
cv::InputArray image,
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This function is equivalent to:

decompose(image, max_reconstructable_levels(image));

Parameters:

image[in] The image to be transformed.

inline void decompose(
cv::InputArray image,
Coeffs &coeffs,
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This function is equivalent to:

decompose(image, coeffs, max_reconstructable_levels(image));

Parameters:
  • image[in] The image to be transformed.

  • coeffs[out] The resulting DWT coefficients.

inline cv::Mat reconstruct(
const Coeffs &coeffs,
) const

Performs an multiscale inverse DWT.

Parameters:

coeffs[in] The DWT coefficients.

void reconstruct(
const Coeffs &coeffs,
cv::OutputArray image,
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:
  • coeffs[in] The DWT coefficients.

  • image[out] The reconstructed image.

Coeffs create_empty_coeffs(
const cv::Size &image_size,
int levels,
) const

Creates an empty DWT2D::Coeffs object.

Parameters:
  • image_size[in] The size of the reconstructed image.

  • levels[in] The number of decomposition levels. Must be levels \(\gt\) 1.

Coeffs create_coeffs(
cv::InputArray coeffs_matrix,
const cv::Size &image_size,
int levels,
) const

Creates a DWT2D::Coeffs object.

Parameters:
  • coeffs_matrix[in] The DWT coefficients. Must have size equal to coeffs_size_for_image().

  • image_size[in] The size of the reconstructed image.

  • levels[in] The number of decomposition levels. Must be levels \(\gt\) 1.

Throws:

cv::Exception – If levels is out of range or coeffs_matrx.size() and image_size are incompatible.

Coeffs create_coeffs(
const cv::Size &image_size,
int type,
int levels,
) const

Creates a zero initialized DWT2D::Coeffs object.

Parameters:
  • image_size[in] The size of the reconstructed image.

  • type[in] The coefficients matrix type.

  • levels[in] The number of decomposition levels. Must be levels \(\gt\) 1.

Throws:

cv::Exception – If levels is out of range.

inline Coeffs create_coeffs(
int image_rows,
int image_cols,
int type,
int levels,
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This function is equivalent to:

create_coeffs(cv::Size(image_cols, image_rows), type, levels);

Parameters:
  • image_rows[in] The number of rows in the reconstructed image.

  • image_cols[in] The number of columns in the reconstructed image.

  • type[in] The coefficients matrix type.

  • levels[in] The number of decomposition levels. Must be levels \(\gt\) 1.

Throws:

cv::Exception – If levels is out of range.

cv::Size coeffs_size_for_image(
const cv::Size &image_size,
int levels,
) const

Returns the size of the DWT2D::Coeffs that reconstruct an image of a given size.

Decomposing an image typically produces a coefficients matrix that is larger than the image itself because the filter bank must extrapolate the image along the border.

The size of the decomposition coefficients is a function of the image size, the number of decomposition levels, and the Wavelet::filter_length().

Parameters:
  • image_size[in] The size of the reconstructed image.

  • levels[in] The number of decomposition levels. Must be levels \(\gt\) 1.

Throws:

cv::Exception – If levels is out of range.

inline cv::Size coeffs_size_for_image(
cv::InputArray image,
int levels,
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This function is equivalent to:

coeffs_size_for_image(image.size(), levels);

Parameters:
  • image[in] The reconstructed image.

  • levels[in] The number of decomposition levels. Must be levels \(\gt\) 1.

Throws:

cv::Exception – If levels is out of range.

inline cv::Size coeffs_size_for_image(
int image_rows,
int image_cols,
int levels,
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This function is equivalent to:

coeffs_size_for_image(cv::Size(image_cols, image_rows), levels);

Parameters:
  • image_rows[in] The number of rows in the reconstructed image.

  • image_cols[in] The number of columns in the reconstructed image.

  • levels[in] The number of decomposition levels. Must be levels \(\gt\) 1.

Throws:

cv::Exception – If levels is out of range.

int max_reconstructable_levels(
const cv::Size &image_size,
) const

Returns the maximum number of decomposition levels that can be perfectly reconstructed.

Parameters:

image_size[in] The size of the image to be decomposed.

inline int max_reconstructable_levels(
int image_rows,
int image_cols,
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This function is equivalent to:

max_reconstructable_levels(cv::Size(image_cols, image_rows));

Parameters:
  • image_rows[in] The number of rows in the image to be decomposed.

  • image_cols[in] The number of columns in the image to be decomposed.

inline int max_reconstructable_levels(
cv::InputArray image,
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This function is equivalent to:

max_reconstructable_levels(image.size());

Parameters:

image[in] The image to be decomposed.

inline bool operator==(
const DWT2D &other,
) const

Two transforms are equal if their wavelets are equal and their border types are equal.

class Coeffs

The result of a multiscale discrete wavelet transformation (DWT).

This class is a view onto a cv::Mat containing the DWT coefficients. The coefficients at each decomposition level are comprised of three submatrices: the horizontal detail subband, the vertical detail subband, and the horizontal detail subband. There is a single submatrix of approximation coefficients stored alongside the coarsest details. Smaller level indices correspond to smaller scales (i.e. higher resolutions). The submatrices are layed out as (a 4-level decomposition is shown for illustration):

A
H0
H1
H2
H3
V0
V1
V2
V3
D0
D1
D2
D3

The regions labeled H0, V0, and D0 are the level 0 (i.e. finest) horizontal, vertical, and diagonal detail subbands, respectively. Likewise, H1, V1, and D1 are the level 1 coefficients, H2, V2, and D2 are the level 2 coefficients, and H3, V3, and D3 are the level 3 (i.e. coarsest) coefficients. The approximation coefficients are labeled A.

Constructors

Coeffs()

Construct an empty Coeffs object.

Coeffs(
const Coeffs &other,
) = default

Copy Constructor.

Coeffs(
Coeffs &&other,
) = default

Move Constructor.

Assignment

Coeffs &operator=(
const Coeffs &coeffs,
) = default

Copy Assignment.

The reference to the underlying data is copied. After assighment this and coeffs will be views onto the same coefficients matrix.

Coeffs &operator=(
Coeffs &&coeffs,
) = default

Move Assignment.

Coeffs &operator=(
cv::InputArray coeffs,
)

Assignment from a matrix or scalar.

Assignment behaves the same as cv::Mat whenever is_subcoeffs() is false.

If is_subcoeffs() is true, the coeffs data is always copied to this object. That is, data is always copied to coefficients returned by from_level().

Parameters:

coeffs[in] The coefficients. This must be one of:

  • A matrix of size level_size(0) with channels() number of channels

  • A fundamental type (e.g. float, double, etc.)

  • A vector scalar containing channels() elements (e.g. cv::Vec, std::vector, array, etc.)

  • A cv::Scalar if channels() is less than or equal to 4

Throws:

cv::Exception – If coeffs is an incompatible matrix or scalar.

Copy

Coeffs clone(
) const

Returns a deep copy of the coefficients matrix and metadata.

Coeffs empty_clone(
) const

Returns a Coeffs with an empty coefficients matrix and a deep copy of the metadata.

Coeffs clone_and_assign(
cv::InputArray coeff_matrix,
) const

Returns a Coeffs with a given coefficients matrix and a deep copy of the metadata.

Subcoefficients

Coeffs from_level(
int level,
) const

Returns the coefficients at and above a decomposition level.

The returned Coeffs have is_subcoeffs() set to true and level() set to level.

Consider a coefficient matrix returned by a four level DWT2D. The result of from_level(2) is the shaded submatrix comprised of the approximation coefficients A and the detail subbands H2, V2, D2, H3, V3, and D3.

A
H0
H1
H2
H3
V0
V1
V2
V3
D0
D1
D2
D3

Note

Assigment semantics depend on is_subcoeffs(). See operator=() for details.

Parameters:

level[in]

Coeffs extract_from_level(
int level,
) const

Returns the coefficients at and above a decomposition level.

This function is the same as from_level() except that the result has is_subcoeffs() set to false and level() set to zero.

Note

Assigment semantics depend on is_subcoeffs(). See operator=() for details.

Parameters:

level[in]

void set_from_level(
int level,
cv::InputArray coeffs,
)

Sets the coefficients at and above a decomposition level.

Consider a coefficient matrix returned by a four level DWT2D and a given matrix level_coeffs of size level_size(2). Calling set_from_level(2, level_coeffs) copies level_coeffs to the shaded submatrix comprised of the approximation coefficients A and the detail subbands H2, V2, D2, H3, V3, and D3.

A
H0
H1
H2
H3
V0
V1
V2
V3
D0
D1
D2
D3

  • A vector scalar containing channels() elements (e.g. cv::Vec, std::vector, array, etc.)

  • A cv::Scalar if channels() is less than or equal to 4

Throws:

cv::Exception – If coeffs is an incompatible matrix or scalar.

Parameters:
  • level[in]

  • coeffs[in] The coefficients. This must be one of:

    • A matrix of size level_size() “level_size(level)” with channels() number of channels

    • A fundamental type (e.g. float, double, etc.)

inline int level(
) const

The level of the finest scale coefficients.

This is the value passed to from_level(). It is 0 for default constructed objects and objects returned by DWT2D::decompose(), DWT2D::create_coeffs(), DWT2D::create_empty_coeffs(), and extract_from_level().

inline bool is_subcoeffs(
) const

Returns true if this was created by from_level().

Note

Assigment semantics depend on is_subcoeffs(). See operator=() for details.

Subband Accessors

inline cv::Mat approx(
) const

Returns the approximation coefficients.

void set_approx(
cv::InputArray coeffs,
)

Sets the approximation coefficients.

Parameters:

coeffs[in] The approximation coefficients. This must be one of:

  • A matrix of size approx_size() with channels() number of channels

  • A fundamental type (e.g. float, double, etc.)

  • A vector scalar containing channels() elements (e.g. cv::Vec, std::vector, array, etc.)

  • A cv::Scalar if channels() is less than or equal to 4

Throws:

cv::Exception – If coeffs is an incompatible matrix or scalar.

Unnamed Group

cv::Mat detail(
int level,
int subband,
) const

Returns the detail coefficients at a given level and subband.

Parameters:
  • level[in]

  • subband[in] The detail subband. This must be a DetailSubband.

void set_all_detail_levels(
cv::InputArray coeffs,
)

Sets all detail coefficients.

Only the elements indicated by detail_mask() are copied from coeffs.

Parameters:

coeffs[in] The detail coefficients. This must be one of:

  • A matrix of size size() with channels() number of channels

  • A fundamental type (e.g. float, double, etc.)

  • A vector scalar containing channels() elements (e.g. cv::Vec, std::vector, array, etc.)

  • A cv::Scalar if channels() is less than or equal to 4

Throws:

cv::Exception – If coeffs is an incompatible matrix or scalar.

void set_detail(
int level,
int subband,
cv::InputArray coeffs,
)

Sets the detail coefficients at a given level and subband.

Parameters:
  • level[in] The scale level.

  • subband[in] The detail subband. This must be a DetailSubband.

  • coeffs[in] The detail subband coefficients. This must be one of:

    • A matrix of size detail_size() with channels() number of channels

    • A fundamental type (e.g. float, double, etc.)

    • A vector scalar containing channels() elements (e.g. cv::Vec, std::vector, array, etc.)

    • A cv::Scalar if channels() is less than or equal to 4

Throws:

cv::Exception

  • If coeffs is an incompatible matrix or scalar.

  • If subband is not a valid DetailSubband.

std::vector<cv::Mat> collect_details(
int subband,
) const

Returns a collection of detail coefficients at each level in a given subband.

This function is equivalent to:

std::vector<cv::Mat> collected_details(this->levels());
for (int level = 0; level < this->levels(); ++level)
    collected_details[level] = this->detail(level, subband);

Consider a coefficient matrix returned by a four level DWT2D. The result of collect_details(DetailSubband::HORIZONTAL) is a vector containing the shaded submatrices H0, H1, H2, and H3.

A
H0
H1
H2
H3
V0
V1
V2
V3
D0
D1
D2
D3

Parameters:

subband[in] The detail subband. This must be a DetailSubband.

Unnamed Group

inline cv::Mat horizontal_detail(
int level,
) const

Returns the horizontal subband detail coefficients at a given level.

Parameters:

level[in]

void set_horizontal_detail(
int level,
cv::InputArray coeffs,
)

Sets the horizontal subband detail coefficients at a given level.

Parameters:
  • level[in] The scale level.

  • coeffs[in] The detail coefficients. This must be one of:

    • A matrix of size detail_size() with channels() number of channels

    • A fundamental type (e.g. float, double, etc.)

    • A vector scalar containing channels() elements (e.g. cv::Vec, std::vector, array, etc.)

    • A cv::Scalar if channels() is less than or equal to 4

Throws:

cv::Exception – If coeffs is an incompatible matrix or scalar.

inline std::vector<cv::Mat> collect_horizontal_details(
) const

Returns a collection of horizontal subband detail coefficients at each level.

This function is equivalent to: collect_details(DetailSubband::HORIZONTAL).

Unnamed Group

inline cv::Mat vertical_detail(
int level,
) const

Returns the vertical subband detail coefficients at a given level.

Parameters:

level[in]

void set_vertical_detail(
int level,
cv::InputArray coeffs,
)

Sets the vertical subband detail coefficients at a given level.

Parameters:
  • level[in] The scale level.

  • coeffs[in] The detail coefficients. This must be one of:

    • A matrix of size detail_size() with channels() number of channels

    • A fundamental type (e.g. float, double, etc.)

    • A vector scalar containing channels() elements (e.g. cv::Vec, std::vector, array, etc.)

    • A cv::Scalar if channels() is less than or equal to 4

Throws:

cv::Exception – If coeffs is an incompatible matrix or scalar.

inline std::vector<cv::Mat> collect_vertical_details(
) const

Returns a collection of vertical subband detail coefficients at each level.

This function is equivalent to: collect_details(DetailSubband::VERTICAL).

Unnamed Group

inline cv::Mat diagonal_detail(
int level,
) const

Returns the diagonal subband detail coefficients at a given level.

Parameters:

level[in]

void set_diagonal_detail(
int level,
cv::InputArray coeffs,
)

Sets the diagonal subband detail coefficients at a given level.

Parameters:
  • level[in] The scale level.

  • coeffs[in] The detail coefficients. This must be one of:

    • A matrix of size detail_size() with channels() number of channels

    • A fundamental type (e.g. float, double, etc.)

    • A vector scalar containing channels() elements (e.g. cv::Vec, std::vector, array, etc.)

    • A cv::Scalar if channels() is less than or equal to 4

Throws:

cv::Exception – If coeffs is an incompatible matrix or scalar.

inline std::vector<cv::Mat> collect_diagonal_details(
) const

Returns a collection of diagonal subband detail coefficients at each level.

This function is equivalent to: collect_details(DetailSubband::DIAGONAL).

Subband Regions

cv::Size level_size(
int level,
) const

The size of the coefficents starting at the given level.

The level size will be empty if and only if the image_size() is empty. This differs from size(), which equals level_size(0) when this is nonempty and empty when this is empty().

The difference is that size() measures the size of the coefficients matrix, whereas level_size() is effectively the sum of subband sizes, which are stored as metadata.

The distinction only applies to coefficients created by empty_clone() or DWT2D::create_empty_coeffs().

See also

level_rect

Parameters:

level[in]

cv::Rect level_rect(
int level,
) const

The region containing the coefficients starting at the given level.

The level rect will be empty if and only if the image_size() is empty.

See also

level_size

Parameters:

level[in]

inline cv::Size approx_size(
) const

The size of the approximation coefficients.

cv::Rect approx_rect(
) const

The region containing the approximation coefficients.

cv::Size detail_size(
int level,
) const

The size of the each of the detail subbands at the given level.

Parameters:

level[in]

cv::Rect detail_rect(
int level,
int subband,
) const

The region containing the coefficients for the given level and subband.

Parameters:
  • level[in]

  • subband[in] The detail subband. This must be a DetailSubband.

cv::Rect horizontal_detail_rect(
int level,
) const

The region containing the horizontal subband coefficients at the given level.

Parameters:

level[in]

cv::Rect vertical_detail_rect(
int level,
) const

The region containing the vertical subband coefficients at the given level.

Parameters:

level[in]

cv::Rect diagonal_detail_rect(
int level,
) const

The region containing the diagonal subband coefficients at the given level.

Parameters:

level[in]

Subband Masks

cv::Mat approx_mask(
) const

The mask indicating the approximation coefficients.

cv::Mat detail_mask(
) const

The mask indicating the detail coefficients.

cv::Mat detail_mask(
int level,
) const

The mask indicating the detail coefficients at a level.

Parameters:

level[in]

cv::Mat detail_mask(
int level,
int subband,
) const

The mask indicating the subband coefficients at a level.

Parameters:
  • level[in]

  • subband[in] The detail subband. This must be a DetailSubband.

cv::Mat detail_mask(
const cv::Range &levels,
) const

The mask indicating the detail coefficients at a range of levels.

Parameters:

levels[in]

cv::Mat detail_mask(
const cv::Range &levels,
int subband,
) const

The mask indicating the subband coefficients at a range of levels.

Parameters:
  • levels[in]

  • subband[in] The detail subband. This must be a DetailSubband.

cv::Mat detail_mask(
int lower_level,
int upper_level,
int subband,
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:
  • lower_level[in]

  • upper_level[in]

  • subband[in] The detail subband. This must be a DetailSubband.

cv::Mat invalid_detail_mask(
) const

The mask indicating the invalid detail coefficients.

Invalid detail coefficients are half rows or columns of zeros that result from odd sized detail rects. These are simply internal padding and are not the result of an image decomposition and are not used during reconstruction.

Users should typically use detail_mask() when operating on coefficients over one or more levels or subbands.

cv::Mat horizontal_detail_mask(
int level,
) const

The mask indicating the horizontal subband coefficients at the given level.

Parameters:

level[in]

cv::Mat horizontal_detail_mask(
const cv::Range &levels,
) const

The mask indicating the horizontal subband coefficients at a range of levels.

Parameters:

levels[in]

cv::Mat horizontal_detail_mask(
int lower_level,
int upper_level,
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:
  • lower_level[in]

  • upper_level[in]

cv::Mat vertical_detail_mask(
int level,
) const

The mask indicating the vertical subband coefficients at the given level.

Parameters:

level[in]

cv::Mat vertical_detail_mask(
const cv::Range &levels,
) const

The mask indicating the vertical subband coefficients at a range of levels.

Parameters:

levels[in]

cv::Mat vertical_detail_mask(
int lower_level,
int upper_level,
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:
  • lower_level[in]

  • upper_level[in]

cv::Mat diagonal_detail_mask(
int level,
) const

The mask indicating the diagonal subband coefficients at the given level.

Parameters:

level[in]

cv::Mat diagonal_detail_mask(
const cv::Range &levels,
) const

The mask indicating the diagonal subband coefficients at a range of levels.

Parameters:

levels[in]

cv::Mat diagonal_detail_mask(
int lower_level,
int upper_level,
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:
  • lower_level[in]

  • upper_level[in]

cv::Mat Wrappers

inline int rows(
) const

The number of rows.

inline int cols(
) const

The number of columns.

inline cv::Size size(
) const

Returns the size of a coefficients matrix.

inline int type(
) const

Returns the type of a coefficient.

This is a convenience wrapper around cv::Mat::type().

inline int depth(
) const

Returns the depth of a coefficient.

This is a convenience wrapper around cv::Mat::depth().

inline int channels(
) const

Returns the number of matrix channels.

This is a convenience wrapper around cv::Mat::channels().

inline bool empty(
) const

Returns true if the coefficients matrix has no elements.

This is a convenience wrapper around cv::Mat::empty().

inline size_t total(
) const

Returns the total number of elements in the coefficient matrix.

This is a convenience wrapper around cv::Mat::total().

inline size_t elemSize(
) const

Returns the matrix element size in bytes.

This is a convenience wrapper around cv::Mat::elemSize().

inline size_t elemSize1(
) const

Returns the size of each matrix element channel in bytes.

This is a convenience wrapper around cv::Mat::elemSize1().

inline void copyTo(
cv::OutputArray destination,
) const

Copies the coefficients to another matrix.

This is a convenience wrapper around cv::Mat::copyTo().

Parameters:

destination[in] Destination matrix. If it does not have a proper size or type before the operation, it is reallocated.

inline void copyTo(
cv::OutputArray destination,
cv::InputArray mask,
) const

Copies the coefficients to another matrix.

This is a convenience wrapper around cv::Mat::copyTo().

Parameters:
  • destination[in] Destination matrix. If it does not have a proper size or type before the operation, it is reallocated.

  • mask[in] Operation mask of the same size as *this. Its non-zero elements indicate which matrix elements need to be copied. The mask has to be of type CV_8U and can have 1 or multiple channels.

inline void setTo(
cv::InputArray value,
cv::InputArray mask = cv::noArray(),
) const

Sets all or some of the coefficients to the specified value.

This is a convenience wrapper around cv::Mat::setTo().

Parameters:
  • value – Assigned scalar converted to the type().

  • mask – Operation mask of the same size as *this. Its non-zero elements indicate which matrix elements need to be copied. The mask has to be of type CV_8U and can have 1 or multiple channels.

inline void convertTo(
cv::OutputArray destination,
int type,
double alpha = 1.0,
double beta = 0.0,
) const

Converts the coefficients to another data type with optional scaling.

This is a convenience wrapper around cv::Mat::convertTo().

Parameters:
  • destination[in] The destination matrix. If it does not have a proper size or type before the operation, it is reallocated.

  • type[in] The destination matrix type or, rather, the depth since the destination will have channels() number of channels. If negative, the destination type will be type().

  • alpha[in] Optional scale factor.

  • beta[in] Optional delta added to the scaled values.

inline bool isContinuous(
) const

Returns true if the coefficient matrix is stored continuously in memory.

This is a convenience wrapper around cv::Mat::isContinuous().

inline bool isSubmatrix(
) const

Returns true if the coefficient matrix is a submatrix of another matrix.

This is a convenience wrapper around cv::Mat::isSubmatrix().

DWT

inline int levels(
) const

Returns the number of decomposition levels.

inline Wavelet wavelet(
) const

Returns the wavelet used to generate the coefficients.

inline cv::BorderTypes border_type(
) const

Returns the border exptrapolation method used during decomposition.

DWT2D dwt() const

Returns the DWT2D transformation object used to compute the coefficients.

inline cv::Size image_size(
int level,
) const

Returns the size of the image reconstructed from the coefficients at the given level.

Parameters:

level[in]

inline cv::Size image_size(
) const

Returns the size of the image reconstructed from the coefficients.

cv::Mat reconstruct(
) const

Transform from DWT space back to image space.

void reconstruct(
cv::OutputArray image,
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:

image[out] The reconstructed image.

inline bool is_compatible(
const Coeffs &other,
) const

Returns true if the coefficients where generated by the same DWT applied to the same sized image.

Compatiblility with other is defined as:

Parameters:

other

Other

int total_valid(
) const

Returns the total number of valid coefficients.

This is equal to:

Invalid detail coefficients are half rows or columns of zeros that result from odd sized detail rects. These are simply internal padding and are not the result of an image decomposition and are not used during reconstruction.

See also

total_details

int total_details(
) const

Returns the total number of valid detail coefficients.

This is equal to total() - cv::countNonZero(invalid_detail_mask()) - approx().total()

Invalid detail coefficients are half rows or columns of zeros that result from odd sized detail rects. These are simply internal padding and are not the result of an image decomposition and are not used during reconstruction.

See also

total_valid

DWT2D::Coeffs map_details_to_unit_interval(
cv::InputArray read_mask = cv::noArray(),
cv::InputArray write_mask = cv::noArray(),
) const

Scales and shifts detail coefficients to [0, 1].

This function maps detail coefficients centered at 0.5 to detail coefficients centered at 0.

The normalized coefficients \(\tilde\w\) are

\[\begin{equation} \tilde\w = \alpha w + \frac{1}{2} \end{equation}\]
where
\[\begin{equation} \alpha = \frac{1}{2 \max(|w|)} \end{equation}\]

Note

This function is useful for displaying and saving coefficients as a normal image. Only the detail coefficients are transformed. The approximation coefficients are left unchanged, thereby changing the relative scale between the approximation and detail coefficients. Reconstruction from the normalized coefficients will result in distortion.

Parameters:
  • read_mask[in] Indicates which coefficients are used to compute the map parameters. This can be a single channel or multichannel matrix with depth CV_8U.

  • write_mask[in] Indicates which coefficients are mapped. This can be a single channel or multichannel matrix with depth CV_8U.

DWT2D::Coeffs map_details_to_unit_interval(
double &scale_output,
cv::InputArray read_mask = cv::noArray(),
cv::InputArray write_mask = cv::noArray(),
) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:
  • scale_output[out] The computed scaling parameter used to map the detail coefficients into the interval [0, 1].

  • read_mask[in] Indicates which coefficients are used to compute the map parameters. This can be a single channel or multichannel matrix with depth CV_8U.

  • write_mask[in] Indicates which coefficients are mapped. This can be a single channel or multichannel matrix with depth CV_8U.

DWT2D::Coeffs map_details_from_unit_interval(
double scale,
cv::InputArray write_mask = cv::noArray(),
) const

Scales and shifts detail coefficients from [0, 1].

This function maps detail coefficients centered at 0.5 to detail coefficients centered at 0.

Given the scale parameter \(\alpha\) and the normalized coefficients \(\tilde\w\), this function computes the coefficents \(w\) by

\[\begin{equation} w = \frac{\tilde\w - \frac{1}{2}}{\alpha} \end{equation}\]

For a particular \(\max(|w|\), the scale parameter \(\alpha\) must be

\[\begin{equation} \alpha = \frac{1}{2 \max(|w|)} \end{equation}\]

This is the inverse to map_details_to_unit_interval(). For perfect inversion, write_mask must be the same and scale must be the value outputted by map_details_to_unit_interval(double&, cv::InputArray, cv::InputArray).

DWT2D::Coeffs coeffs = ...;

// Map the details to [0, 1] such that 0 gets mapped to 0.5
DWT2D::Coeffs unit_interval_detail_coeffs;
double scale = coeffs.map_details_to_unit_interval(unit_interval_detail_coeffs);

// Invert the mapping, i.e. coeffs2 == coeffs element-wise
auto coeffs2 = unit_interval_detail_coeffs.map_details_from_unit_interval(scale);

Parameters:
  • scale[in]

  • write_mask[in] Indicates which coefficients are mapped. This can be a single channel or multichannel matrix with depth CV_8U.

double map_detail_to_unit_interval_scale(
cv::InputArray read_mask = cv::noArray(),
) const

Returns the scaling parameter used to map the detail coefficients into the interval [0, 1].

\[\begin{equation} \alpha = \frac{1}{2 \max(|w|)} \end{equation}\]

Parameters:

read_mask[in] Indicates which coefficients are used to compute the scale parameter. This can be a single channel or multichannel matrix with depth CV_8U.

inline cv::Range resolve_level_range(
const cv::Range &levels,
) const

Resolves the endpoints of a range with negative values or a cv::Range::all().

This function maps cv::Range::all() to cv::Range(0, levels()).

If levels.start is negative, it is mapped to levels() + levels.start. The same applies to levels.end.

Parameters:

levels[in] The range of levels.

Functional Interface

DWT2D::Coeffs wtcv::dwt2d(
cv::InputArray image,
const Wavelet &wavelet,
int levels,
cv::BorderTypes border_type = cv::BORDER_DEFAULT,
)

Performs a two dimensional multiscale discrete wavelet transform (DWT).

This function is equivalent to:

DWT2D dwt(wavelet, border_type);
return dwt.decompose(image, levels);

See also

DWT2D

Parameters:
  • image[in]

  • wavelet[in]

  • levels[in]

  • border_type[in]

void wtcv::dwt2d(
cv::InputArray image,
DWT2D::Coeffs &coeffs,
const Wavelet &wavelet,
int levels,
cv::BorderTypes border_type = cv::BORDER_DEFAULT,
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This function is equivalent to:

DWT2D dwt(wavelet, border_type);
dwt.decompose(image, output, levels);

See also

DWT2D

Parameters:
  • image[in]

  • coeffs[out]

  • wavelet[in]

  • levels[in]

  • border_type[in]

DWT2D::Coeffs wtcv::dwt2d(
cv::InputArray image,
const std::string &wavelet,
int levels,
cv::BorderTypes border_type = cv::BORDER_DEFAULT,
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This function is equivalent to:

dwt2d(image, Wavelet::create(wavelet), levels, border_type);

Parameters:
  • image[in]

  • wavelet[in]

  • levels[in]

  • border_type[in]

void wtcv::dwt2d(
cv::InputArray image,
DWT2D::Coeffs &coeffs,
const std::string &wavelet,
int levels,
cv::BorderTypes border_type = cv::BORDER_DEFAULT,
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This function is equivalent to:

dwt2d(image, output, Wavelet::create(wavelet), levels, border_type);

See also

DWT2D

Parameters:
  • image[in]

  • coeffs[out]

  • wavelet[in]

  • levels[in]

  • border_type[in]

DWT2D::Coeffs wtcv::dwt2d(
cv::InputArray image,
const Wavelet &wavelet,
cv::BorderTypes border_type = cv::BORDER_DEFAULT,
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This function is equivalent to:

DWT2D dwt(wavelet, border_type);
return dwt.decompose(image);

See also

DWT2D

Parameters:
  • image[in]

  • wavelet[in]

  • border_type[in]

void wtcv::dwt2d(
cv::InputArray image,
DWT2D::Coeffs &coeffs,
const Wavelet &wavelet,
cv::BorderTypes border_type = cv::BORDER_DEFAULT,
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This function is equivalent to:

DWT2D dwt(wavelet, border_type);
dwt.decompose(image, output);

See also

DWT2D

Parameters:
  • image[in]

  • coeffs[out]

  • wavelet[in]

  • border_type[in]

DWT2D::Coeffs wtcv::dwt2d(
cv::InputArray image,
const std::string &wavelet,
cv::BorderTypes border_type = cv::BORDER_DEFAULT,
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This function is equivalent to:

dwt2d(image, Wavelet::create(wavelet), border_type);

See also

DWT2D

Parameters:
  • image[in]

  • wavelet[in]

  • border_type[in]

void wtcv::dwt2d(
cv::InputArray image,
DWT2D::Coeffs &coeffs,
const std::string &wavelet,
cv::BorderTypes border_type = cv::BORDER_DEFAULT,
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This function is equivalent to:

dwt2d(image, output, Wavelet::create(wavelet), border_type);

See also

DWT2D

Parameters:
  • image[in]

  • coeffs[out]

  • wavelet[in]

  • border_type[in]