ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkWaveletUtilities.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef itkWaveletUtilities_h
19#define itkWaveletUtilities_h
20
21#include <algorithm>
22#include <cmath>
23#include <vector>
24#include <itkFixedArray.h>
25#include <itkMath.h>
26#include <itkSize.h>
27
28#include "IsotropicWaveletsExport.h"
29
30namespace itk
31{
32namespace utils
33{
34using IndexPairType = std::pair<unsigned int, unsigned int>;
35
62IsotropicWavelets_EXPORT IndexPairType
63IndexToLevelBandSteerablePyramid(unsigned int linearIndex, unsigned int levels, unsigned int bands);
64
70template <unsigned int VImageDimension>
71ITK_TEMPLATE_EXPORT unsigned int
72ComputeMaxNumberOfLevels(const Size<VImageDimension> & inputSize, const unsigned int & scaleFactor)
73{
75 // The minimum level is 1.
76 exponentPerAxis.Fill(1);
77 for (unsigned int axis = 0; axis < VImageDimension; ++axis)
78 {
79 size_t sizeAxis = inputSize[axis];
80 double exponent = std::log(static_cast<double>(sizeAxis)) / std::log(static_cast<double>(scaleFactor));
81 // check that exponent is integer: the fractional part is 0
82 double exponentIntPart;
83 double exponentFractionPart = std::modf(exponent, &exponentIntPart);
84 // DEV (phcerdan): Increased epsilon due to numeric errors with Alpine-musl (Travis CI).
85 // Failing test when exponent == log(27) / log(3).
86 if (itk::Math::FloatAlmostEqual(exponentFractionPart, 0.0, 4, 10 * itk::NumericTraits<double>::epsilon()))
87 {
88 exponentPerAxis[axis] = static_cast<unsigned int>(exponent);
89 }
90 else
91 {
92 // increase valid levels until the division size/scale_factor gives a non-integer.
93 auto sizeAtLevel = static_cast<double>(sizeAxis);
94 for (;;)
95 {
96 double division = sizeAtLevel / static_cast<double>(scaleFactor);
97 double intPartDivision;
98 double fractionPartDivision = std::modf(division, &intPartDivision);
99 if (itk::Math::FloatAlmostEqual(fractionPartDivision, 0.0))
100 {
101 exponentPerAxis[axis]++;
102 sizeAtLevel = intPartDivision;
103 }
104 else
105 {
106 break;
107 }
108 }
109 }
110 }
111 // return the min_element of array:
112 // - 1 is any size is not divisible by scale factor
113 return *std::min_element(exponentPerAxis.Begin(), exponentPerAxis.End());
114}
115
116} // end namespace utils
117} // end namespace itk
118
119#endif
Simulate a standard C array with copy semantics.
Iterator End()
Iterator Begin()
void Fill(const ValueType &)
Define additional traits for native types such as int or float.
bool FloatAlmostEqual(T x1, T x2, typename Detail::FloatIEEE< T >::IntType maxUlps=4, typename Detail::FloatIEEE< T >::FloatType maxAbsoluteDifference=0.1 *itk::NumericTraits< T >::epsilon())
Compare two floats and return if they are effectively equal.
Definition itkMath.h:331
ITK_TEMPLATE_EXPORT unsigned int ComputeMaxNumberOfLevels(const Size< VImageDimension > &inputSize, const unsigned int &scaleFactor)
std::pair< unsigned int, unsigned int > IndexPairType
IsotropicWavelets_EXPORT IndexPairType IndexToLevelBandSteerablePyramid(unsigned int linearIndex, unsigned int levels, unsigned int bands)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition itkSize.h:70