Go to the documentation of this file.00001 #ifndef OPENTISSUE_UTILITY_IMAGE_ANALYSIS_IMAGE_ANALYSIS_COMPUTE_FEATURE_SPACE_WHITENING_H
00002 #define OPENTISSUE_UTILITY_IMAGE_ANALYSIS_IMAGE_ANALYSIS_COMPUTE_FEATURE_SPACE_WHITENING_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/utility/image_analysis/feature_space_pca.h>
00013 #include <OpenTissue/core/math/math_eigen_system_decomposition.h>
00014 #include <OpenTissue/core/math/math_is_finite.h>
00015
00016 namespace OpenTissue
00017 {
00018 namespace image_analysis
00019 {
00029 template< typename feature_grid_type, typename matrix3x3_type, typename vector3_type >
00030 void compute_feature_space_whitening(feature_grid_type & feature_grid, matrix3x3_type & R, vector3_type & d )
00031 {
00032 using std::sqrt;
00033
00034 typedef typename feature_grid_type::index_iterator feature_iterator;
00035
00036 matrix3x3_type C;
00037 vector3_type mean;
00038 OpenTissue::image_analysis::feature_space_pca(feature_grid,mean,C);
00039
00040 OpenTissue::math::eigen(C,R,d);
00041
00042
00043
00044 vector3_type inv_d2;
00045 inv_d2(0) = 1.0 / sqrt(d(0));
00046 inv_d2(1) = 1.0 / sqrt(d(1));
00047 inv_d2(2) = 1.0 / sqrt(d(2));
00048 feature_iterator fbegin = feature_grid.begin();
00049 feature_iterator fend = feature_grid.end();
00050 feature_iterator f = fbegin;
00051 for(; f!=fend;++f)
00052 {
00053 (*f) = R*((*f)-mean);
00054 (*f)(0) *= inv_d2(0);
00055 (*f)(1) *= inv_d2(1);
00056 (*f)(2) *= inv_d2(2);
00057 assert( is_finite( (*f)(0) ) || !"compute_feature_space_whitening(): NaN ");
00058 assert( is_finite( (*f)(1) ) || !"compute_feature_space_whitening(): NaN " );
00059 assert( is_finite( (*f)(2) ) || !"compute_feature_space_whitening(): NaN " );
00060 }
00061 }
00062
00063 }
00064
00065 }
00066
00067
00068 #endif