Shrinker API
-
class Shrinker
Base class for DWT coefficient shrinkage algorithms.
Subclassed by wtcv::BayesShrinker, wtcv::SureShrinker, wtcv::UniversalShrinker
Public Types
-
enum Partition
The scheme used to split the DWT coefficients into disjoint subsets.
Values:
-
enumerator GLOBALLY
Shrink all coefficients using a single threshold
-
enumerator LEVELS
Shrink each decomposition level using a separate threshold
-
enumerator SUBBANDS
Shrink each subband using a separate threshold
-
enumerator SUBSETS
Shrink coefficients according to a custom partition
-
enumerator GLOBALLY
Public Functions
- virtual ~Shrinker(
Destructor.
- inline ShrinkFunction shrink_function(
The function used to shrink a subset of DWT coefficients.
- inline StdDevFunction stdev_function(
The standard deviation estimator.
- inline DWT2D::Coeffs shrink( ) const
Shrinks DWT coefficients.
This function is equivalent to:
shrink(coeffs, cv::Range::all(), compute_noise_stdev(coeffs), thresholds);
Note
Use this overload when the coefficient noise must be estimated from the coefficients. If the noise is known use this shrink() instead.
- Parameters:
coeffs – [in] The DWT coefficients.
thresholds – [out] The computed thresholds.
- inline void shrink(
- const DWT2D::Coeffs &coeffs,
- DWT2D::Coeffs &shrunk_coeffs,
- cv::OutputArray thresholds = cv::noArray(),
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:
shrink(coeffs, shrunk_coeffs, cv::Range::all(), compute_noise_stdev(coeffs), thresholds);
Note
Use this overload when the coefficient noise must be estimated from the coefficients. If the noise is known use this shrink() instead.
- Parameters:
coeffs – [in] The DWT coefficients.
shrunk_coeffs – [out] The shrunken DWT coefficients.
thresholds – [out] The computed thresholds.
- inline DWT2D::Coeffs shrink( ) 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:
shrink(coeffs, cv::Range::all(), stdev, thresholds);
Note
Use this overload when the coefficient noise is known. If the noise is must be estimated from the coefficients use this shrink() instead.
- Parameters:
coeffs – [in] The DWT coefficients.
stdev – [in] The standard deviation of the coefficient noise.
thresholds – [out] The computed thresholds.
- inline void shrink(
- const DWT2D::Coeffs &coeffs,
- DWT2D::Coeffs &shrunk_coeffs,
- const cv::Scalar &stdev,
- cv::OutputArray thresholds = cv::noArray(),
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:
shrink(coeffs, shrunk_coeffs, cv::Range::all(), stdev, thresholds);
Note
Use this overload when the coefficient noise is known. If the noise is must be estimated from the coefficients use this shrink() instead.
- Parameters:
coeffs – [in] The DWT coefficients.
shrunk_coeffs – [out] The shrunken DWT coefficients.
stdev – [in] The standard deviation of the coefficient noise.
thresholds – [out] The computed thresholds.
- inline DWT2D::Coeffs shrink( ) const
Shrinks DWT coefficients for a subset of levels.
This function is equivalent to:
shrink(coeffs, cv::Range(0, levels), thresholds);
Note
Use this overload when the coefficient noise must be estimated from the coefficients. If the noise is known use this shrink() instead.
- Parameters:
coeffs – [in] The DWT coefficients.
levels – [in] The subset of levels to shrink.
thresholds – [out] The computed thresholds.
- inline void shrink(
- const DWT2D::Coeffs &coeffs,
- DWT2D::Coeffs &shrunk_coeffs,
- int levels,
- cv::OutputArray thresholds = cv::noArray(),
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:
shrink(coeffs, shrunk_coeffs, cv::Range(0, levels), compute_noise_stdev(coeffs), thresholds);
Note
Use this overload when the coefficient noise must be estimated from the coefficients. If the noise is known use this shrink() instead.
- Parameters:
coeffs – [in] The DWT coefficients.
shrunk_coeffs – [out] The shrunken DWT coefficients.
levels – [in] The subset of levels to shrink.
thresholds – [out] The computed thresholds.
- inline DWT2D::Coeffs shrink(
- const DWT2D::Coeffs &coeffs,
- const cv::Scalar &stdev,
- int levels,
- cv::OutputArray thresholds = cv::noArray(),
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:
shrink(coeffs, cv::Range(0, levels), stdev, thresholds);
Note
Use this overload when the coefficient noise is known. If the noise is must be estimated from the coefficients use this shrink() instead.
- Parameters:
coeffs – [in] The DWT coefficients.
levels – [in] The subset of levels to shrink.
stdev – [in] The standard deviation of the coefficient noise.
thresholds – [out] The computed thresholds.
- inline void shrink(
- const DWT2D::Coeffs &coeffs,
- DWT2D::Coeffs &shrunk_coeffs,
- int levels,
- const cv::Scalar &stdev,
- cv::OutputArray thresholds = cv::noArray(),
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:
shrink(coeffs, shrunk_coeffs, cv::Range(0, levels), stdev, thresholds);
Note
Use this overload when the coefficient noise is known. If the noise is must be estimated from the coefficients use this shrink() instead.
- Parameters:
coeffs – [in] The DWT coefficients.
shrunk_coeffs – [out] The shrunken DWT coefficients.
levels – [in] The subset of levels to shrink.
stdev – [in] The standard deviation of the coefficient noise.
thresholds – [out] The computed thresholds.
- inline DWT2D::Coeffs shrink( ) 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:
shrink(coeffs, levels, compute_noise_stdev(coeffs), thresholds);
Note
Use this overload when the coefficient noise must be estimated from the coefficients. If the noise is known use this shrink() instead.
- Parameters:
coeffs – [in] The DWT coefficients.
levels – [in] The subset of levels to shrink.
thresholds – [out] The computed thresholds.
- inline void shrink(
- const DWT2D::Coeffs &coeffs,
- DWT2D::Coeffs &shrunk_coeffs,
- const cv::Range &levels,
- cv::OutputArray thresholds = cv::noArray(),
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:
shrink(coeffs, shrunk_coeffs, levels, compute_noise_stdev(coeffs), thresholds);
Note
Use this overload when the coefficient noise must be estimated from the coefficients. If the noise is known use this shrink() instead.
- Parameters:
coeffs – [in] The DWT coefficients.
shrunk_coeffs – [out] The shrunken DWT coefficients.
levels – [in] The subset of levels to shrink.
thresholds – [out] The computed thresholds.
- inline DWT2D::Coeffs shrink(
- const DWT2D::Coeffs &coeffs,
- const cv::Range &levels,
- const cv::Scalar &stdev,
- cv::OutputArray thresholds = cv::noArray(),
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Note
Use this overload when the coefficient noise is known. If the noise is must be estimated from the coefficients use this shrink() instead.
- Parameters:
coeffs – [in] The DWT coefficients.
levels – [in] The subset of levels to shrink.
stdev – [in] The standard deviation of the coefficient noise.
thresholds – [out] The computed thresholds.
- void shrink(
- const DWT2D::Coeffs &coeffs,
- DWT2D::Coeffs &shrunk_coeffs,
- const cv::Range &levels,
- const cv::Scalar &stdev,
- cv::OutputArray thresholds = cv::noArray(),
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Note
Use this overload when the coefficient noise is known. If the noise is must be estimated from the coefficients use this shrink() instead.
- Parameters:
coeffs – [in] The DWT coefficients.
shrunk_coeffs – [out] The shrunken DWT coefficients.
levels – [in] The subset of levels to shrink.
stdev – [in] The standard deviation of the coefficient noise.
thresholds – [out] The computed thresholds.
- inline cv::Mat4d compute_thresholds( ) const
Computes the threshold for each of the partitioned subsets.
This function is equivalent to:
compute_thresholds(coeffs, levels, compute_noise_stdev(coeffs));
Note
Use this overload when the coefficient noise must be estimated from the coefficients. If the noise is known use this compute_thresholds() instead.
- Parameters:
coeffs – [in] The DWT coefficients.
levels – [in] The subset of levels to compute thresholds for.
- cv::Mat4d compute_thresholds( ) const
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Note
Use this overload when the coefficient noise is known. If the noise is must be estimated from the coefficients use this compute_thresholds() instead.
- Parameters:
coeffs – [in] The DWT coefficients.
levels – [in] The subset of levels to compute thresholds for.
stdev – [in] The standard deviation of the coefficient noise.
- inline cv::Mat4d compute_thresholds( ) 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:
compute_thresholds(coeffs, cv::Range(0, levels), compute_noise_stdev(coeffs));
Note
Use this overload when the coefficient noise must be estimated from the coefficients. If the noise is known use this compute_thresholds() instead.
- Parameters:
coeffs – [in] The DWT coefficients.
levels – [in] The subset of levels to compute thresholds for.
- inline cv::Mat4d compute_thresholds( ) 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:
compute_thresholds(coeffs, cv::Range(0, levels), stdev);
Note
Use this overload when the coefficient noise is known. If the noise is must be estimated from the coefficients use this compute_thresholds() instead.
- Parameters:
coeffs – [in] The DWT coefficients.
levels – [in] The subset of levels to compute thresholds for.
stdev – [in] The standard deviation of the coefficient noise.
- inline cv::Mat4d compute_thresholds( ) 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:
compute_thresholds(coeffs, cv::Range::all(), compute_noise_stdev(coeffs));
Note
Use this overload when the coefficient noise must be estimated from the coefficients. If the noise is known use this compute_thresholds() instead.
- Parameters:
coeffs – [in] The DWT coefficients.
- inline cv::Mat4d compute_thresholds( ) 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:
compute_thresholds(coeffs, cv::Range::all(), stdev);
Note
Use this overload when the coefficient noise is known. If the noise is must be estimated from the coefficients use this compute_thresholds() instead.
- Parameters:
coeffs – [in] The DWT coefficients.
stdev – [in] The standard deviation of the coefficient noise.
- inline cv::Mat expand_thresholds( ) const
Expands the subset thresholds to a threshold matrix of the same size as the given coefficients.
This function expands the matrix of subset thresholds to a matrix that is the same size as coeffs where each entry is the threshold for the corresponding coefficient.
- Parameters:
coeffs – [in] The DWT coefficients.
subset_thresholds – [in] The thresholds returned by compute_threshold().
levels – [in] The subset of levels to compute thresholds for.
- void expand_thresholds(
- const DWT2D::Coeffs &coeffs,
- const cv::Mat4d &subset_thresholds,
- cv::OutputArray expanded_thresholds,
- const cv::Range &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 expands the matrix of subset thresholds to a matrix that is the same size as coeffs where each entry is the threshold for the corresponding coefficient.
- Parameters:
coeffs – [in] The DWT coefficients.
subset_thresholds – [in] The thresholds returned by compute_threshold().
expanded_thresholds – [out]
levels – [in] The subset of levels to compute thresholds for.
- inline cv::Mat expand_thresholds( ) 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:
expand_thresholds(coeffs, thresholds, cv::Range(0, levels));
- Parameters:
coeffs – [in]
subset_thresholds – [in]
levels – [in]
- inline void expand_thresholds(
- const DWT2D::Coeffs &coeffs,
- cv::OutputArray expanded_thresholds,
- const cv::Mat4d &subset_thresholds,
- 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:
expand_thresholds(coeffs, thresholds, cv::Range(0, levels));
- Parameters:
coeffs – [in]
subset_thresholds – [in]
expanded_thresholds – [out]
levels – [in]
- inline cv::Mat expand_thresholds( ) 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:
expand_thresholds(coeffs, thresholds, cv::Range::all());
- Parameters:
coeffs – [in]
subset_thresholds – [in]
- inline void expand_thresholds(
- const DWT2D::Coeffs &coeffs,
- const cv::Mat4d &subset_thresholds,
- cv::OutputArray expanded_thresholds,
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:
expand_thresholds(coeffs, thresholds, cv::Range::all());
- Parameters:
coeffs – [in]
subset_thresholds – [in]
expanded_thresholds – [out]
- inline virtual cv::Scalar compute_noise_stdev( ) const
Estimates the coefficient noise standard deviation.
The default implementation calls stdev_function() on the diagonal subband at the finest resolution (i.e. coeffs.diagonal_detail(0)).
The default stdev_function() is mad_stdev(), which gives a statistically robust estimate of the standard deviation.
Subclasses can override this function to change which coefficients are used to esitmate the coefficient noise standard deviation. Subclasses should change the standard deviation estimator by passing a different estimator to the constructor.
- Parameters:
coeffs – [in] The entire set of DWT coefficients.
Protected Functions
- inline Shrinker(
- Shrinker::Partition partition,
- ShrinkFunction shrink_function,
- StdDevFunction stdev_function,
Construct a new Shrinker object.
- Parameters:
partition – [in] The scheme used to partition the coefficients.
shrink_function – [in] The function used to shrink coefficients.
stdev_function – [in] The function used to compute an estimate of the standard deviation of coefficient noise.
- inline Shrinker(
- Shrinker::Partition partition,
- ShrinkFunction shrink_function,
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:
Shrinker(partition, shrink_function, mad_stdev)
- Parameters:
partition – [in] The scheme used to partition the coefficients.
shrink_function – [in] The function used to shrink coefficients.
-
template<typename T, typename W>
inline Shrinker( - Shrinker::Partition partition,
- PrimitiveShrinkFunction<T, W> shrink_function,
- StdDevFunction stdev_function,
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:
Shrinker(partition, make_shrink_function(shrink_function), stdev_function)
- Template Parameters:
T –
W –
- Parameters:
partition – [in] The scheme used to partition the coefficients.
shrink_function – [in] The function used to shrink coefficients.
stdev_function – [in] The function used to compute an estimate of the standard deviation of coefficient noise.
-
template<typename T, typename W>
inline Shrinker( - Shrinker::Partition partition,
- PrimitiveShrinkFunction<T, W> shrink_function,
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:
Shrinker(partition, make_shrink_function(shrink_function), mad_stdev)
- Template Parameters:
T –
W –
- Parameters:
partition – [in] The scheme used to partition the coefficients.
shrink_function – [in] The function used to shrink coefficients.
- inline virtual void start_partitioning( ) const
Prepares for a call to shrink() or compute_thresholds().
Most subclasses do not need to override this function.
A subclass should override this function if it requires temporary values that must be accessed by
Or compute_subband_threshold() for every subband
Or compute_level_threshold() for every level
The temporary values should be stored as data members.
One potential use case involves computing a set of partition masks that are used by both compute_subset_thresholds() and shrink_subsets(). Another use case is computing global statistics that are used to compute the threshold for each partitioned subset (i.e. used in compute_level_threshold() or compute_subband_threshold()).
Note
Any data members set in this function must be declared mutable and must be cleaned up in finish_partitioning().
- Parameters:
coeffs – [in] The DWT coefficients.
levels – [in] The subset of levels to compute thresholds for.
stdev – [in] The standard deviation of the coefficient noise.
- inline virtual void finish_partitioning(
- const DWT2D::Coeffs &coeffs,
- const cv::Range &levels,
- const cv::Scalar &stdev,
- const DWT2D::Coeffs &shrunk_coeffs,
- const cv::Mat4d &thresholds,
Finishes a call to shrink() or compute_thresholds().
Implementations should cleanup temporary data members created in start_partitioning(). This function is guaranteed to be called by shrink() and compute_thresholds() as long as start_partitioning() did not throw an exception. If necessary, std::current_exception() can be used to determine if this function was called normally or because an exception occured. In the latter case, shrunk_coeffs or thresholds may be empty depending on when the exception was thrown.
void MyShrinker::finish_partitioning( const DWT2D::Coeffs& coeffs, const cv::Range& levels, const cv::Scalar& stdev, const DWT2D::Coeffs& shrunk_coeffs, const cv::Mat4d& thresholds ) const { if (std::current_exception()) { // finishing up because an exception was thrown } else { // finishing up normally } }
- Parameters:
coeffs – [in] The DWT coefficients.
levels – [in] The subset of levels to compute thresholds for.
stdev – [in] The standard deviation of the coefficient noise.
shrunk_coeffs – [in] The shrunken DWT coefficients. This is empty when called from compute_thresholds().
thresholds – [in] The computed thresholds.
- cv::Mat4d compute_partition_thresholds( ) const
Computes the thresholds for all subsets.
This function:
Calls compute_global_threshold(), compute_level_thresholds(), compute_subband_thresholds(), or compute_subset_thresholds() depending on the value of partition().
Is called by shrink() and compute_thresholds()
Does not call start_partitioning() and finish_partitioning()
Subclasses do not typically need to call this function.
- Parameters:
coeffs – [in]
levels – [in]
stdev – [in]
- virtual cv::Scalar compute_global_threshold( ) const
Computes the threshold on a single global subset of coefficients.
- Parameters:
coeffs – [in] The entire set of DWT coefficients.
levels – [in] The subset of levels over which to compute the threshold.
stdev – [in] The standard deviation of the coefficient noise.
- virtual cv::Scalar compute_level_threshold(
- const cv::Mat &detail_coeffs,
- int level,
- const cv::Scalar &stdev,
Computes the threshold for a single level subset of coefficients.
- Parameters:
detail_coeffs – [in] The level detail coefficients.
level – [in] The decomposition level of the given coefficients.
stdev – [in] The standard deviation of the coefficient noise.
- virtual cv::Scalar compute_subband_threshold(
- const cv::Mat &detail_coeffs,
- int level,
- int subband,
- const cv::Scalar &stdev,
Computes the threshold for a single subband subset of coefficients.
- Parameters:
detail_coeffs – [in] The subband detail coefficients.
level – [in] The decomposition level of the given coefficients.
subband – [in] The subband of the coefficients.
stdev – [in] The standard deviation of the coefficient noise.
- virtual cv::Mat4d compute_subset_thresholds( ) const
Computes the thresholds for an implementation defined partition.
- Parameters:
coeffs – [in] The entire set of coefficients.
levels – [in] The subset of levels over which to compute the threshold.
stdev – [in] The standard deviation of the coefficient noise.
- virtual void expand_subset_thresholds(
- const DWT2D::Coeffs &coeffs,
- const cv::Mat4d &subset_thresholds,
- const cv::Range &levels,
- cv::Mat &expanded_thresholds,
Expands the thresholds for an implementation defined partition.
- Parameters:
coeffs – [in] The entire set of coefficients.
subset_thresholds – [in] The subset thresholds.
levels – [in] The subset of levels over which to compute the threshold.
expanded_thresholds – [out] The expanded thresholds.
- virtual void shrink_subsets( ) const
Shrinks the coefficients using a implementation defined partition.
Implentations should partition the coefficients into one or more subsets and call shrink_coeffs() for each subset in the partition.
- Parameters:
coeffs – [in] The entire set of coefficients.
subset_thresholds – [in] The thresholds returned by compute_subbset_thresholds().
levels – [in] The subset of levels to shrink.
- inline void shrink_coeffs(
- cv::InputArray coeffs,
- cv::OutputArray thresholded_coeffs,
- const cv::Scalar &threshold,
- cv::InputArray mask = cv::noArray(),
Applies the shrink_function() to the given coefficients.
- Parameters:
coeffs – [in] The coefficients.
thresholded_coeffs – [out] The shrunken coefficients.
threshold – [in] The threshold parameter.
mask – [in] Indicates which coefficients to apply the threshold function to.
- inline void shrink_coeffs(
- cv::InputOutputArray coeffs,
- const cv::Scalar &threshold,
- cv::InputArray 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.
This is an inplace version of shrink_coeffs().
- Parameters:
coeffs – [inout] The coefficients.
threshold – [in] The threshold parameter.
mask – [in] Indicates which coefficients to shrink.
- inline cv::Scalar compute_stdev(
- cv::InputArray array,
Applies the stdev_function() to given array.
- Parameters:
array – [in]
- inline void set_shrink_function(
- ShrinkFunction shrink_function,
Sets the shrink function.
- Parameters:
shrink_function – [in]
- inline void set_stdev_function(
- StdDevFunction stdev_function,
Sets the standard deviation function.
- Parameters:
stdev_function – [in]
- cv::Mat4d compute_level_thresholds( ) const
Calls compute_level_threshold() for each level subset.
- Parameters:
coeffs – [in] The entire set of DWT coefficients.
levels – [in] The subset of levels to compute thresholds for.
stdev – [in] The standard deviation of the coefficient noise.
- cv::Mat4d compute_subband_thresholds( ) const
Calls compute_subband_threshold() for each subband subset.
- Parameters:
coeffs – [in] The entire set of DWT coefficients.
levels – [in] The subset of levels to compute thresholds for.
stdev – [in] The standard deviation of the coefficient noise.
-
enum Partition
-
using wtcv::ShrinkFunction = std::function<void(cv::InputArray, cv::OutputArray, cv::Scalar, cv::InputArray)>
A function that shrinks matrix elements towards zero.
Multichannel, masked
- Param array:
[in] The array the shrink
- Param shrunk_array:
[out] The shrunk array
- Param threshold:
[in] The threshold
- Param mask:
[in] The mask
-
template<typename Value, typename Threshold>
using wtcv::PrimitiveShrinkFunction = std::function<Value(Value, Threshold)> A function that shrinks fundamental types towards zero.
See also
-
using wtcv::StdDevFunction = std::function<cv::Scalar(cv::InputArray)>
A function that estimates the population standard deviation from samples.
Universal Threshold Shrinker
-
class UniversalShrinker : public wtcv::Shrinker
Shrink using the universal threshold.
Subclassed by wtcv::VisuShrinker
Public Functions
- inline UniversalShrinker(
- Shrinker::Partition partition,
- ShrinkFunction shrink_function,
- StdDevFunction stdev_function,
Construct a new Universal Shrinker object.
- Parameters:
partition – [in]
shrink_function – [in]
stdev_function – [in]
- inline UniversalShrinker(
- ShrinkFunction shrink_function,
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Parameters:
shrink_function – [in]
-
template<typename T, typename W>
inline UniversalShrinker( - PrimitiveShrinkFunction<T, W> shrink_function,
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Template Parameters:
T –
W –
- Parameters:
shrink_function – [in]
- inline UniversalShrinker(
- Shrinker::Partition partition,
- ShrinkFunction shrink_function,
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Parameters:
partition – [in]
shrink_function – [in]
-
template<typename T, typename W>
inline UniversalShrinker( - Shrinker::Partition partition,
- PrimitiveShrinkFunction<T, W> shrink_function,
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Template Parameters:
T –
W –
- Parameters:
partition – [in]
shrink_function – [in]
- inline UniversalShrinker(
- ShrinkFunction shrink_function,
- StdDevFunction stdev_function,
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Parameters:
shrink_function – [in]
stdev_function – [in]
-
template<typename T, typename W>
inline UniversalShrinker( - PrimitiveShrinkFunction<T, W> shrink_function,
- StdDevFunction stdev_function,
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Template Parameters:
T –
W –
- Parameters:
shrink_function – [in]
stdev_function – [in]
-
template<typename T, typename W>
inline UniversalShrinker( - Shrinker::Partition partition,
- PrimitiveShrinkFunction<T, W> shrink_function,
- StdDevFunction stdev_function,
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Template Parameters:
T –
W –
- Parameters:
partition – [in]
shrink_function – [in]
stdev_function – [in]
- UniversalShrinker(
- const UniversalShrinker &other,
Copy Constructor.
- UniversalShrinker(
- UniversalShrinker &&other,
Move Constructor.
Public Static Functions
- static cv::Scalar compute_universal_threshold(
- int num_elements,
- const cv::Scalar &stdev = cv::Scalar::all(1.0),
Computes the universal shrinkage threshold.
The universal multichannel threshold \(\lambda\) is defined by
\[\begin{equation} \lambda_k = \sigma_k \, \sqrt{2 \log{N}} \end{equation}\]https://computing.llnl.gov/sites/default/files/jei2001.pdf
- Parameters:
num_elements – [in] The number of detail coefficients.
stdev – [in] The standard deviations of the detail coefficients channels.
- static cv::Scalar compute_universal_threshold( )
Computes the universal shrinkage threshold.
This function is equivalent to:
compute_universal_threshold(coeffs, coeffs.detail_mask(), stdev);
https://computing.llnl.gov/sites/default/files/jei2001.pdf
- Parameters:
coeffs – [in] The discrete wavelet transform coefficients.
stdev – [in] The standard deviations of the detail coefficients channels.
- static cv::Scalar compute_universal_threshold(
- cv::InputArray detail_coeffs,
- const cv::Scalar &stdev = cv::Scalar::all(1.0),
Computes the universal shrinkage threshold.
This function is equivalent to:
compute_universal_threshold(details.total(), stdev);
- Parameters:
detail_coeffs – [in] The discrete wavelet transform detail coefficients.
stdev – [in] The standard deviations of the detail coefficients channels.
- static cv::Scalar compute_universal_threshold(
- cv::InputArray detail_coeffs,
- cv::InputArray mask,
- const cv::Scalar &stdev = cv::Scalar::all(1.0),
Computes the universal shrinkage threshold.
This function is equivalent to:
compute_universal_threshold(collect_masked(details, mask), stdev);
- Parameters:
detail_coeffs – [in] The discrete wavelet transform detail coefficients.
mask – [in] A single channel matrix of type CV_8U where nonzero entries indicate which input locations are used in the computation.
stdev – [in] The standard deviations of the detail coefficients channels.
VisuShrink Algorithm
-
class VisuShrinker : public wtcv::UniversalShrinker
Gobal shrinkage using the universal threshold, the soft threshold. function, and the MAD standard deviation estimator.
Public Functions
- inline VisuShrinker(
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- inline VisuShrinker( )
Construct a new VisuShrinker object.
- Parameters:
partition – [in]
- VisuShrinker(
- const VisuShrinker &other,
Copy Constructor.
- VisuShrinker(
- VisuShrinker &&other,
Move Constructor.
Functional Interface
- DWT2D::Coeffs wtcv::visu_shrink( )
Shrinks detail coefficients using the VisuShrink algorithm.
- Parameters:
coeffs – [in] The discrete wavelet transform coefficients.
- void wtcv::visu_shrink( )
Shrinks detail coefficients using the VisuShrink algorithm.
- Parameters:
coeffs – [in] The discrete wavelet transform coefficients.
shrunk_coeffs – [out] The shrunk discrete wavelet transform coefficients.
- DWT2D::Coeffs wtcv::visu_shrink( )
Shrinks detail coefficients using the VisuShrink algorithm.
- Parameters:
coeffs – [in] The discrete wavelet transform coefficients.
levels – [in] The maximum number of levels to shrink. Shrinking is applied starting at the lowest level (i.e. smallest scale).
- void wtcv::visu_shrink( )
Shrinks detail coefficients using the VisuShrink algorithm.
- Parameters:
coeffs – [in] The discrete wavelet transform coefficients.
shrunk_coeffs – [out] The shrunk discrete wavelet transform coefficients.
levels – [in] The maximum number of levels to shrink. Shrinking is applied starting at the lowest level (i.e. smallest scale).
SureShrink Algorithm
-
class SureShrinker : public wtcv::Shrinker
Implements the SureShrink algorithm for shrinking DWT coefficients.
The coefficients can be partitioned Shrinker::GLOBALLY into a single subset, by Shrinker::LEVELS into level subsets, or by Shrinker::SUBBANDS into subband subsets. The default is Shrinker::SUBBANDS.
This algorithm uses soft_threshold(). There are two possible methods used to compute the thresholds. The SureShrink::STRICT variant always computes each subset threshold by minimizing the SURE risk. The SureShrink::HYBRID variant chooses between the SURE risk minimizer or the universal_threshold() depending on the coefficients L2 norm. See https://computing.llnl.gov/sites/default/files/jei2001.pdf for the details.
The thresholds are determined by minimizing the SURE risk. The optimization algorithm is set by passing a SureShrink::Optimizer to the constructor. When the optimization algorithm is SureShrink::BRUTE_FORCE each subset’s threshold is computed by evaluating the risk using the absolute value of each coefficient in that subset (i.e. \(O(rows \cdot cols \cdot channels)\) runtime). Although this is the most accurate method, it can be prohibitively slow for larger subsets of coefficients. SureShrink::AUTO is the default optimization algorithm. It uses the algorithm set by SureShrink::AUTO_OPTIMIZER for larger subsets and SureShrink::BRUTE_FORCE for smaller subsets. The cutoff size between these two modes is set with SureShrink::AUTO_BRUTE_FORCE_SIZE_LIMIT.
Public Types
-
enum Variant
The variant of the SureShrink algorithm.
Values:
-
enumerator STRICT
Always use the threshold that minimizes the SURE risk
-
enumerator HYBRID
Use the threshold that minimizes the SURE risk unless the L2 norm of the coefficient subset is less than a certain limit. In which case, use the universal_threshold().
-
enumerator STRICT
-
enum Optimizer
The optimizer used to compute thresholds.
Values:
-
enumerator AUTO
Use BRUTE_FORCE or AUTO_OPTIMIZER depending on the size of the coefficient subset
-
enumerator NELDER_MEAD
-
enumerator COBYLA
-
enumerator BOBYQA
-
enumerator DIRECT
-
enumerator DIRECT_L
-
enumerator BRUTE_FORCE
Compute the SURE risk for all possible thresholds
-
enumerator AUTO
Public Functions
- inline SureShrinker(
Default constructor.
Equiqualent to:
SureShrink(Shrinker::SUBBANDS, SureShrink::HYBRID, SureShrink::AUTO)
- inline SureShrinker(
- SureShrinker::Variant variant,
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Equiqualent to:
SureShrink(Shrinker::SUBBANDS, variant, SureShrink::AUTO)
- Parameters:
variant – [in] The variant of the algorithm.
- inline SureShrinker( )
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Equiqualent to:
SureShrink(partition, SureShrink::HYBRID, SureShrink::AUTO)
- Parameters:
partition – [in]
- inline SureShrinker(
- Shrinker::Partition partition,
- SureShrinker::Variant variant,
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Equiqualent to:
SureShrink(partition, variant, SureShrink::AUTO)
- Parameters:
partition – [in]
variant – [in]
- inline SureShrinker(
- Shrinker::Partition partition,
- SureShrinker::Variant variant,
- SureShrinker::Optimizer optimizer,
Construct a SureShrinker object.
- Parameters:
partition – [in] How the coefficients are partitioned.
variant – [in] The variant of the algorithm to use.
optimizer – [in] The optimization algorithm used to compute the thresholds.
- inline SureShrinker(
- Shrinker::Partition partition,
- SureShrinker::Variant variant,
- SureShrinker::Optimizer optimizer,
- const OptimizerStopConditions &stop_conditions,
Construct a SureShrinker object with specified optimizer stopping conditions.
- Parameters:
partition – [in] How the coefficients are partitioned.
variant – [in] The variant of the algorithm to use.
optimizer – [in] The optimization algorithm used to compute the thresholds.
stop_conditions – [in] The conditions used to determine optimizer convergence.
- SureShrinker(
- const SureShrinker &other,
Copy Constructor.
- SureShrinker(
- SureShrinker &&other,
Move Constructor.
- inline void fail_on_timeout(
Throw an exception when the optimizer runs for the maximum allowed time.
- inline void warn_on_timeout(
Issue a warning when the optimizer runs for the maximum allowed time.
- inline bool is_timeout_an_error(
Returns true if an exception is thrown when the optimizer runs for the maximum allowed time.
- inline void fail_on_max_evaluations(
Throw an exception when the optimizer performs the maximum number of allowed evaluations.
- inline void warn_on_max_evaluations(
Issue a warning when the optimizer performs the maximum number of allowed evaluations.
- inline bool is_max_evaluations_reached_an_error(
Returns true if an exception is thrown when the optimizer performs the maximum number of allowed evaluations.
- cv::Scalar compute_sure_threshold(
- cv::InputArray detail_coeffs,
- const cv::Scalar &stdev,
- cv::InputArray mask = cv::noArray(),
Computes the SureShrink algorithm threshold.
For a single channel with \(\sigma = 1\), the SURE threshold is defined by
\[\begin{equation} \lambda_{SURE} = \argmin_{\lambda \ge 0} \SURE(\lambda, w) \end{equation}\]where the input \(w\) is a subset of noisy detail coefficients measurements drawn from an unknown normal distribution. \(\SURE(\lambda, w)\) is an unbiased estimator of the MSE between the true detail coefficients and the soft thresholded coefficients using the threshold \(\lambda\).Specifically,
\[\begin{equation} \SURE(\lambda, w) = N - 2 [\# \, \mathrm{of} \, |w_n| < \lambda] + \sum_{n = 1}^{N} [\min(|w_n|, \lambda)]^2 \end{equation}\]where \(N\) is the number of coefficients and \([\# \, \mathrm{of} \, |w_n| < \lambda]\) is the number of coefficients lesser than \(\lambda\) in magnitude.When the detail coefficients are sparse it is preferable to employ hybrid algorithm that chooses the compute_universal_threshold() when
\[\begin{equation} \frac{1}{N} \sum_{n = 1}^{N} \left( \frac{w_n}{\sigma} - 1 \right)^2 \le \frac{\left(\log_2(N)\right)^{3/2}}{\sqrt{N}} \end{equation}\]and \(\lambda_{SURE}\) otherwise. Pass SureShrinker::HYBRID as the variant argument to use this implementation.When the standard deviation of each input channel is not one, each channel standard deviation must be passed in using the stdev argument. In which case, the resulting threshold will be suitably scaled to work on the non-standardized coefficients.
This function returns a multichannel threshold by applying the single channel algorithm to each channel of the given detail_coeffs.
- Parameters:
detail_coeffs – [in] The detail coefficients.
stdev – [in] The standard deviations of each of the detail coefficients channels.
mask – [in] Indicates which coefficients are used to compute the threshold. This must be a single channel with type CV_8U1 or CV_8S1.
- cv::Scalar compute_sure_risk(
- cv::InputArray detail_coeffs,
- const cv::Scalar &threshold,
- const cv::Scalar &stdev,
- cv::InputArray mask = cv::noArray(),
Computes the SURE risk estimate.
- Parameters:
detail_coeffs – [in]
threshold – [in]
stdev – [in]
mask – [in]
Public Static Attributes
-
static int AUTO_BRUTE_FORCE_SIZE_LIMIT
The number of primitive array elements at which the AUTO optimization algorithm switches from BRUTE_FORCE to AUTO_OPTIMIZER.
The defaults is 32 * 32 * 3 (i.e. a 3 channel, 32x32 image).
-
class MaxEvaluationsReached : public wtcv::SureShrinker::StoppedEarly
Exception thrown when optimization reaches the maximum allowed number of evaluations.
See also
optimizer_stop_conditions, set_optimizer_stop_conditions, fail_on_max_evaluations, warn_on_max_evaluations
-
struct OptimizerStopConditions
The conditions that define optimizer convergence.
-
class StoppedEarly : public std::runtime_error
Base for exceptions that occur when optimization is stopped before converging.
Subclassed by wtcv::SureShrinker::MaxEvaluationsReached, wtcv::SureShrinker::TimeoutOccured
-
class TimeoutOccured : public wtcv::SureShrinker::StoppedEarly
Exception thrown when optimization reaches the maximum allowed time.
See also
optimizer_stop_conditions, set_optimizer_stop_conditions, fail_on_timeout, warn_on_timeout
-
enum Variant
Functional Interface
- DWT2D::Coeffs wtcv::sure_shrink( )
Shrinks detail coefficients using the SureShrink algorithm.
- Parameters:
coeffs – [in] The discrete wavelet transform coefficients.
- void wtcv::sure_shrink( )
Shrinks detail coefficients using the SureShrink algorithm.
- Parameters:
coeffs – [in] The discrete wavelet transform coefficients.
shrunk_coeffs – [out] The shrunk discrete wavelet transform coefficients.
- DWT2D::Coeffs wtcv::sure_shrink( )
Shrinks detail coefficients using the SureShrink algorithm.
- Parameters:
coeffs – [in] The discrete wavelet transform coefficients.
levels – [in] The maximum number of levels to shrink. Shrinking is applied starting at the lowest level (i.e. smallest scale).
- void wtcv::sure_shrink( )
Shrinks detail coefficients using the SureShrink algorithm.
- Parameters:
coeffs – [in] The discrete wavelet transform coefficients.
shrunk_coeffs – [out] The shrunk discrete wavelet transform coefficients.
levels – [in] The maximum number of levels to shrink. Shrinking is applied starting at the lowest level (i.e. smallest scale).
- DWT2D::Coeffs wtcv::sure_shrink_levelwise( )
Shrinks detail coefficients using the SureShrink algorithm.
- Parameters:
coeffs – [in] The discrete wavelet transform coefficients.
- void wtcv::sure_shrink_levelwise( )
Shrinks detail coefficients using the SureShrink algorithm.
- Parameters:
coeffs – [in] The discrete wavelet transform coefficients.
shrunk_coeffs – [out] The shrunk discrete wavelet transform coefficients.
- DWT2D::Coeffs wtcv::sure_shrink_levelwise( )
Shrinks detail coefficients using the SureShrink algorithm.
- Parameters:
coeffs – [in] The discrete wavelet transform coefficients.
levels – [in] The maximum number of levels to shrink. Shrinking is applied starting at the lowest level (i.e. smallest scale).
- void wtcv::sure_shrink_levelwise( )
Shrinks detail coefficients using the SureShrink algorithm.
- Parameters:
coeffs – [in] The discrete wavelet transform coefficients.
shrunk_coeffs – [out] The shrunk discrete wavelet transform coefficients.
levels – [in] The maximum number of levels to shrink. Shrinking is applied starting at the lowest level (i.e. smallest scale).
BayesShrink Algorithm
-
class BayesShrinker : public wtcv::Shrinker
Implements the BayesShrink algorithm for shrinking DWT coefficients.
The threshold for subband \(s\) is
\[\begin{equation} \lambda_s = \frac{\hat\sigma^2}{\hat\sigma^2_X} \end{equation}\]where \(\hat\sigma^2\) is the estimated noise variance and \(\hat\sigma_X\) is the estimated signal variance on subband \(s\).The estimated signal variance is
\[\begin{equation} \hat\sigma^2_X = \max(\hat\sigma^2_Y - \hat\sigma^2, 0) \end{equation}\]where\[\begin{equation} \hat\sigma^2_Y = \frac{1}{N_s} \sum_{n = 1}^{N_s} w^2_n \end{equation}\]is the estimate of the variance of the observations.When \(\hat\sigma^2 \gt \hat\sigma_Y^2\), the threshold becomes \(\lambda_s = \max(|w_n|)\) and all subband coefficients are shrunk to zero.
Public Functions
- inline BayesShrinker(
- Shrinker::Partition partition,
- ShrinkFunction shrink_function,
Construct a new BayesShrinker object.
- Parameters:
partition – [in]
shrink_function – [in]
- inline BayesShrinker(
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- inline BayesShrinker( )
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Parameters:
partition – [in]
-
template<typename T, typename W>
inline BayesShrinker( - Shrinker::Partition partition,
- PrimitiveShrinkFunction<T, W> shrink_function,
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Template Parameters:
T –
W –
- Parameters:
partition – [in]
shrink_function – [in]
- BayesShrinker(
- const BayesShrinker &other,
Copy Constructor.
- BayesShrinker(
- BayesShrinker &&other,
Move Constructor.
- cv::Scalar compute_bayes_threshold(
- cv::InputArray detail_coeffs,
- const cv::Scalar &stdev,
Computes the BayesShrink threshold.
- Parameters:
detail_coeffs – [in]
stdev – [in]
- cv::Scalar compute_bayes_threshold(
- cv::InputArray detail_coeffs,
- cv::InputArray mask,
- const cv::Scalar &stdev,
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Parameters:
detail_coeffs – [in]
mask – [in]
stdev – [in]
Functional Interface
Low Level API
- void wtcv::soft_threshold(
- cv::InputArray array,
- cv::OutputArray result,
- const cv::Scalar &threshold,
- cv::InputArray mask = cv::noArray(),
Multichannel masked soft threshold.
Given input \(x\), mask \(m\), and threshold \(\lambda\) the output at row \(i\), column \(j\), and channel \(k\) is
\[\begin{split}\begin{equation} y_{ijk} = \begin{cases} \indicator{|x_{ijk}| > \lambda_k} \, \sgn(x_{ijk}) \, (|x_{ijk}| - \lambda_k) & \textrm{if} \,\, m_{ij} \ne 0 \\ |x_{ijk}| & \textrm{if} \,\, m_{ij} = 0 \end{cases} \end{equation}\end{split}\]- Parameters:
array – [in]
result – [out]
threshold – [in]
mask – [in] A single channel matrix of type CV_8U where nonzero entries indicate which input locations are thresholded. The identity function is applied to inputs at corresponding zero entries.
- void wtcv::hard_threshold(
- cv::InputArray array,
- cv::OutputArray result,
- const cv::Scalar &threshold,
- cv::InputArray mask = cv::noArray(),
Multichannel masked hard threshold.
Given input \(x\), mask \(m\), and threshold \(\lambda\) the output at row \(i\), column \(j\), and channel \(k\) is
\[\begin{split}\begin{equation} y_{ij} = \begin{cases} \indicator{|x_{ij}| > \lambda} \, x_{ij} & \textrm{if} \,\, m_{ij} \ne 0 \\ |x_{ij}| & \textrm{if} \,\, m_{ij} = 0 \end{cases} \end{equation}\end{split}\]where \(i\) is the row, \(j\) is the column and \(k\) is the channel.- Parameters:
array – [in]
result – [out]
threshold – [in]
mask – [in] A single channel matrix of type CV_8U where nonzero entries indicate which input locations are thresholded. The identity function is applied to inputs at corresponding zero entries.
-
template<typename PrimitiveShrinkFunctor>
ShrinkFunction wtcv::make_shrink_function( Creates a multichannel shrink function from a primitive shrink functor.
struct MyPrimitiveShrinkFunctor { template <typename T, typename W> T operator(T value, W threshold); }; auto my_shrink_function = make_shrink_function<MyPrimitiveShrinkFunctor>(); cv::Mat image = ...; cv::Mat thresholded_image; cv::Scalar threshold = ...; my_shrink_function(image, thresholded_image, threshold);
- Template Parameters:
ThresholdFunctor –
-
template<typename T, typename W = T>
ShrinkFunction wtcv::make_shrink_function( - PrimitiveShrinkFunction<T, W> shrink_function,
Creates a multichannel shrink function from a primitive shrink function.
template <typename T, typename W> T my_primitive_shrink_function(T value, W threshold); auto my_shrink_function = make_shrink_function(my_primitive_shrink_function); cv::Mat image = ...; cv::Mat thresholded_image; cv::Scalar threshold = ...; my_shrink_function(image, thresholded_image, threshold);
- Template Parameters:
T – The primitive value type.
W – The primitive threshold type.
- Parameters:
shrink_function – [in] The threshold function that acts on primitive types.
- void wtcv::shrink_globally(
- DWT2D::Coeffs &coeffs,
- const cv::Scalar &threshold,
- ShrinkFunction shrink_function,
- const cv::Range &levels = cv::Range::all(),
Shrinks DWT detail coefficients using a single threshold.
The coefficients are shrunk in place.
Use the levels argument to limit shrinking to a subset of decomposition levels.
See also
Shrinker, shrink_levels, shrink_subbands, make_shrink_function
- Parameters:
coeffs – [inout]
threshold – [in]
shrink_function – [in]
levels – [in]
- void wtcv::shrink_levels(
- DWT2D::Coeffs &coeffs,
- cv::InputArray level_thresholds,
- ShrinkFunction shrink_function,
- const cv::Range &levels = cv::Range::all(),
Shrinks DWT coefficients using separate thresholds for each decomposition level.
The coefficients are shrunk in place.
Use the levels argument to limit shrinking to a subset of decomposition levels. If levels is cv::Range::all(), level_thresholds.rows must equal coeffs.levels(). Otherwise, level_thresholds.rows must equal levels.size().
See also
Shrinker, shrink_globally, shrink_subbands, make_shrink_function
- Parameters:
coeffs – [inout] The DWT coefficients.
level_thresholds – [in] The threshold paramaters for each level. This must be an array with N rows, 1 column, and 4 channels (where N is the number of levels to be shrunk). Each row corresponds to a decomposition level.
shrink_function – [in] The function that shrinks the coefficients.
levels – [in] The decomposition levels that are shrunk.
- void wtcv::shrink_subbands(
- DWT2D::Coeffs &coeffs,
- cv::InputArray subband_thresholds,
- ShrinkFunction shrink_function,
- const cv::Range &levels = cv::Range::all(),
Shrinks DWT coefficients using separate thresholds for each decomposition subband.
The coefficients are shrunk in place.
Use the levels argument to limit shrinking to a subset of decomposition levels. If levels is cv::Range::all(), subband_thresholds.rows must equal coeffs.levels(). Otherwise, subband_thresholds.rows must equal levels.size().
See also
Shrinker, shrink_globally, shrink_levels, make_shrink_function
- Parameters:
coeffs – [inout] The DWT coefficients.
subband_thresholds – [in] The threshold paramaters for each subband. This must be an array with N rows, 3 columns, and 4 channels (where N is the number of levels to be shrunk). Each row corresponds to a decomposition level. The first column contains horizontal subband thresholds, the second column contains vertical subband thresholds, and the third column contains diagonal subband thresholds.
shrink_function – [in] The function that shrinks the coefficients.
levels – [in] The decomposition levels that are shrunk.