48#include <vigra/multi_array.hxx>
49#include <vigra/accumulator.hxx>
50#include <vigra/multi_math.hxx>
63template <
typename T >
64double condense (
const T & t , std::true_type )
66 return std::abs ( t ) ;
69template <
typename T >
70double condense (
const T & t , std::false_type )
72 return sqrt ( sum ( t * t ) ) / t.size() ;
75template <
typename T >
76double condense (
const std::complex<T> & t , std::false_type )
78 return std::abs ( t ) ;
84 < std::is_fundamental < T > :: value ,
89template <
typename T >
95template <
int dim ,
typename T >
96double check_diff ( vigra::MultiArrayView < dim , T > & reference ,
97 vigra::MultiArrayView < dim , T > & candidate )
99 using namespace vigra::multi_math ;
100 using namespace vigra::acc;
102 assert ( reference.shape() == candidate.shape() ) ;
104 vigra::MultiArray < 1 , double >
105 error_array ( vigra::Shape1(reference.size() ) ) ;
107 for (
int i = 0 ; i < reference.size() ; i++ )
109 auto help = candidate[i] - reference[i] ;
112 error_array [ i ] =
condense ( help ) ;
115 AccumulatorChain < double , Select < Mean, Maximum > > ac ;
116 extractFeatures ( error_array.begin() , error_array.end() , ac ) ;
117 double mean = get<Mean>(ac) ;
118 double max = get<Maximum>(ac) ;
121 std::cout <<
"delta Mean: "
122 << mean << std::endl;
123 std::cout <<
"delta Maximum: "
129template <
int dim ,
typename T >
void
134 typedef vigra::MultiArray < dim , T > array_type ;
137 array_type arr ( shape ) ;
138 vigra::TinyVector < vspline::bc_code , dim > bcv { bc } ;
139 spline_type bsp ( shape , spline_degree , bcv , 0.0 ) ;
142 std::cout <<
"created b-spline:" << std::endl << bsp << std::endl ;
144 std::random_device rd ;
145 std::mt19937 gen ( rd() ) ;
147 std::uniform_real_distribution<> dis ( -1.0 , 1.0 ) ;
148 for (
auto & e : arr )
151 array_type reference = arr ;
155 vspline::restore < dim , T > ( bsp , arr ) ;
158 std::cout <<
"after restoration of original data:" << std::endl ;
160 double emax = check_diff < dim , T > ( reference , arr ) ;
166 <<
typeid(T()).name()
170 <<
" " << arr.shape()
172 <<
" DG " << spline_degree
175 << emax << std::endl ;
178 for (
int times = 1 ; times < 5 ; times++ )
183 spline_type polish_spl ( arr.shape() , spline_degree , bcv , 0.0 ) ;
191 vspline::restore < dim , T > ( bsp , arr ) ;
194 std::cout <<
"after polishing run " << times << std::endl ;
196 double emax2 = check_diff < dim , T > ( reference , arr ) ;
202 <<
typeid(T()).name()
206 <<
" " << arr.shape()
208 <<
" DG " << spline_degree
211 << emax2 << std::endl ;
216int main (
int argc ,
char * argv[] )
220 std::cerr <<
"pass the spline degree as parameter" << std::endl ;
224 int degree = std::atoi ( argv[1] ) ;
226 polish_test < 2 , float >
229 polish_test < 2 , double >
232 polish_test < 2 , long double >
vspline::bspline< pixel_type, 2 > spline_type
typename std::conditional< std::is_fundamental< T > ::value, std::true_type, std::false_type > ::type is_singular
const std::string bc_name[]
bc_name is for diagnostic output of bc codes
bc_code
This enumeration is used for codes connected to boundary conditions. There are two aspects to boundar...
int main(int argc, char *argv[])
void polish_test(vigra::TinyVector< int, dim > shape, vspline::bc_code bc, int spline_degree)
double condense(const T &t, std::true_type)
double check_diff(vigra::MultiArrayView< dim, T > &reference, vigra::MultiArrayView< dim, T > &candidate)
class bspline now builds on class bspline_base, adding coefficient storage, while bspline_base provid...
void prefilter(vspline::xlf_type boost=vspline::xlf_type(1), int njobs=vspline::default_njobs)
prefilter converts the knot point data in the 'core' area into b-spline coefficients....
void brace(int axis=-1)
if the spline coefficients are already known, they obviously don't need to be prefiltered....
includes all headers from vspline (most of them indirectly)