DWT API
-
class DWT2D
A two dimensional multiscale discrete wavelet transform (DWT).

Image decomposition (i.e. analysis or forward transformation) is performed by decompose().
Alternatively, instances of this class are callable.cv::Mat image = ...; DWT2D dwt(Wavelet::create("db2")); DWT2D::Coeffs coeffs = dwt.decompose(image);
A third option is the functional interface.DWT2D::Coeffs coeffs = dwt(image);
DWT2D::Coeffs coeffs = dwt2d(image, "db2");
Image reconstruction (i.e. synthesis or inverse transformation) is accomplished with reconstruct()
or DWT2D::Coeffs::reconstruct()cv::Mat reconstructed_image = dwt.reconstruct(coeffs);
cv::Mat reconstructed_image = coeffs.reconstruct();
See also
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.
- inline auto operator()(
- auto&&... args,
Alias of decompose().
- inline Coeffs decompose(
- cv::InputArray image,
- int levels,
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,
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,
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,
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,
Performs an multiscale inverse DWT.
- Parameters:
coeffs – [in] The DWT coefficients.
- void reconstruct(
- const Coeffs &coeffs,
- cv::OutputArray image,
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,
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,
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,
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,
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,
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().
See also
- 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,
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,
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,
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,
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,
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.
-
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):
AH0H1H2H3V0V1V2V3D0D1D2D3The 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
Assignment
- Coeffs &operator=(
- const Coeffs &coeffs,
Copy Assignment.
The reference to the underlying data is copied. After assighment
thisand coeffs will be views onto the same coefficients matrix.
- 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
Subcoefficients
- Coeffs from_level(
- int level,
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.AH0H1H2H3V0V1V2V3D0D1D2D3Note
Assigment semantics depend on is_subcoeffs(). See operator=() for details.
- Parameters:
level – [in]
- Coeffs extract_from_level(
- int level,
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_coeffsof size level_size(2). Callingset_from_level(2, level_coeffs)copieslevel_coeffsto the shaded submatrix comprised of the approximation coefficients A and the detail subbands H2, V2, D2, H3, V3, and D3.AH0H1H2H3V0V1V2V3D0D1D2D3A 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(
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(
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(
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,
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,
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.AH0H1H2H3V0V1V2V3D0D1D2D3- Parameters:
subband – [in] The detail subband. This must be a DetailSubband.
Unnamed Group
- inline cv::Mat horizontal_detail(
- int level,
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(
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,
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(
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,
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(
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,
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
- Parameters:
level – [in]
- cv::Rect level_rect(
- int level,
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
- Parameters:
level – [in]
- inline cv::Size approx_size(
The size of the approximation coefficients.
- cv::Rect approx_rect(
The region containing the approximation coefficients.
- cv::Size detail_size(
- int level,
The size of the each of the detail subbands at the given level.
- Parameters:
level – [in]
- cv::Rect detail_rect(
- int level,
- int subband,
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,
The region containing the horizontal subband coefficients at the given level.
- Parameters:
level – [in]
- cv::Rect vertical_detail_rect(
- int level,
The region containing the vertical subband coefficients at the given level.
- Parameters:
level – [in]
- cv::Rect diagonal_detail_rect(
- int level,
The region containing the diagonal subband coefficients at the given level.
- Parameters:
level – [in]
Subband Masks
- cv::Mat approx_mask(
The mask indicating the approximation coefficients.
- cv::Mat detail_mask(
The mask indicating the detail coefficients.
- cv::Mat detail_mask(
- int level,
The mask indicating the detail coefficients at a level.
- Parameters:
level – [in]
- cv::Mat detail_mask(
- int level,
- int subband,
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,
The mask indicating the detail coefficients at a range of levels.
- Parameters:
levels – [in]
- cv::Mat detail_mask(
- const cv::Range &levels,
- int subband,
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,
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(
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,
The mask indicating the horizontal subband coefficients at the given level.
- Parameters:
level – [in]
- cv::Mat horizontal_detail_mask(
- const cv::Range &levels,
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,
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,
The mask indicating the vertical subband coefficients at the given level.
- Parameters:
level – [in]
- cv::Mat vertical_detail_mask(
- const cv::Range &levels,
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,
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,
The mask indicating the diagonal subband coefficients at the given level.
- Parameters:
level – [in]
- cv::Mat diagonal_detail_mask(
- const cv::Range &levels,
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,
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(
The number of rows.
- inline int cols(
The number of columns.
- inline cv::Size size(
Returns the size of a coefficients matrix.
- inline int type(
Returns the type of a coefficient.
This is a convenience wrapper around cv::Mat::type().
- inline int depth(
Returns the depth of a coefficient.
This is a convenience wrapper around cv::Mat::depth().
- inline int channels(
Returns the number of matrix channels.
This is a convenience wrapper around cv::Mat::channels().
- inline bool empty(
Returns true if the coefficients matrix has no elements.
This is a convenience wrapper around cv::Mat::empty().
- inline size_t total(
Returns the total number of elements in the coefficient matrix.
This is a convenience wrapper around cv::Mat::total().
- inline size_t elemSize(
Returns the matrix element size in bytes.
This is a convenience wrapper around cv::Mat::elemSize().
- inline size_t elemSize1(
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,
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,
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(),
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,
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(
Returns true if the coefficient matrix is stored continuously in memory.
This is a convenience wrapper around cv::Mat::isContinuous().
- inline bool isSubmatrix(
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(
Returns the number of decomposition levels.
- inline cv::BorderTypes border_type(
Returns the border exptrapolation method used during decomposition.
- inline cv::Size image_size(
- int level,
Returns the size of the image reconstructed from the coefficients at the given level.
- Parameters:
level – [in]
- inline cv::Size image_size(
Returns the size of the image reconstructed from the coefficients.
- cv::Mat reconstruct(
Transform from DWT space back to image space.
See also
- void reconstruct(
- cv::OutputArray image,
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
See also
- Parameters:
image – [out] The reconstructed image.
- inline bool is_compatible(
- const Coeffs &other,
Returns true if the coefficients where generated by the same DWT applied to the same sized image.
Compatiblility with other is defined as:
image_size() == other.image_size()border_type() == other.border_type()
- Parameters:
other –
Other
- int total_valid(
Returns the total number of valid coefficients.
This is equal to:
total() - cv::countNonZero(invalid_detail_mask())
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
- int total_details(
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
- DWT2D::Coeffs map_details_to_unit_interval(
- cv::InputArray read_mask = cv::noArray(),
- cv::InputArray write_mask = cv::noArray(),
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(),
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(),
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(),
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,
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
- 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
- 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
- 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
- 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
- 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
- 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
- Parameters:
image – [in]
coeffs – [out]
wavelet – [in]
border_type – [in]