Go to the documentation of this file.00001 #ifndef OPENTISSUE_UTILITY_IMAGE_ANALYSIS_IMAGE_ANALYSIS_COMPUTE_FEATURE_SPACE_HISTOGRAM_H
00002 #define OPENTISSUE_UTILITY_IMAGE_ANALYSIS_IMAGE_ANALYSIS_COMPUTE_FEATURE_SPACE_HISTOGRAM_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/math/math_is_finite.h>
00013
00014 namespace OpenTissue
00015 {
00016 namespace image_analysis
00017 {
00027 template<
00028 typename feature_grid_type
00029 , typename histogram_type
00030 >
00031 void compute_feature_space_histogram(
00032 feature_grid_type const & feature_grid
00033 , size_t const & I
00034 , size_t const & J
00035 , size_t const & K
00036 , histogram_type & histogram
00037 )
00038 {
00039 using std::min;
00040 using std::max;
00041 using std::floor;
00042
00043 assert(I>0 || !"compute_feature_space_histogram(): I must be positive");
00044 assert(J>0 || !"compute_feature_space_histogram(): J must be positive");
00045 assert(K>0 || !"compute_feature_space_histogram(): K must be positive");
00046
00047 typedef typename feature_grid_type::const_index_iterator feature_iterator;
00048 typedef typename feature_grid_type::value_type vector3_type;
00049 typedef typename vector3_type::value_type real_type;
00050 typedef typename histogram_type::index_iterator histogram_iterator;
00051 typedef typename histogram_type::index_type index_type;
00052
00053 real_type min_x = feature_grid.size();
00054 real_type min_y = feature_grid.size();
00055 real_type min_z = feature_grid.size();
00056 real_type max_x = -min_x;
00057 real_type max_y = -min_y;
00058 real_type max_z = -min_z;
00059
00060 feature_iterator fbegin = feature_grid.begin();
00061 feature_iterator fend = feature_grid.end();
00062 feature_iterator f;
00063 for(f=fbegin; f!=fend;++f)
00064 {
00065 min_x = min( (*f)(0), min_x);
00066 min_y = min( (*f)(1), min_y);
00067 min_z = min( (*f)(2), min_z);
00068 max_x = max( (*f)(0), max_x);
00069 max_y = max( (*f)(1), max_y);
00070 max_z = max( (*f)(2), max_z);
00071 }
00072
00073 assert( is_finite( min_x ) || !"compute_feature_space_histogram(): NaN" );
00074 assert( is_finite( min_y ) || !"compute_feature_space_histogram(): NaN" );
00075 assert( is_finite( min_z ) || !"compute_feature_space_histogram(): NaN" );
00076 assert( is_finite( max_x ) || !"compute_feature_space_histogram(): NaN" );
00077 assert( is_finite( max_y ) || !"compute_feature_space_histogram(): NaN" );
00078 assert( is_finite( max_z ) || !"compute_feature_space_histogram(): NaN" );
00079
00080 histogram.create(vector3_type(min_x,min_y,min_z),vector3_type(max_x,max_y,max_z),I,J,K);
00081 real_type dx = histogram.dx();
00082 real_type dy = histogram.dy();
00083 real_type dz = histogram.dz();
00084
00085 histogram_iterator hbegin = histogram.begin();
00086 histogram_iterator hend = histogram.end();
00087 histogram_iterator h;
00088 for(h=hbegin; h!=hend;++h)
00089 *h = 0;
00090
00091 for(f = fbegin; f!=fend;++f)
00092 {
00093 index_type i = static_cast<index_type>(floor(((*f)(0) - min_x) / dx));
00094 index_type j = static_cast<index_type>(floor(((*f)(1) - min_y) / dy));
00095 index_type k = static_cast<index_type>(floor(((*f)(2) - min_z) / dz));
00096
00097 if(i==I) --i;
00098 if(j==J) --j;
00099 if(k==K) --k;
00100
00101 assert(i>=0 || !"compute_feature_space_histogram(): i must be non-negative" );
00102 assert(j>=0 || !"compute_feature_space_histogram(): j must be non-negative" );
00103 assert(k>=0 || !"compute_feature_space_histogram(): k must be non-negative" );
00104 assert(i<I || !"compute_feature_space_histogram(): i must be less than I" );
00105 assert(j<J || !"compute_feature_space_histogram(): j must be less than J" );
00106 assert(k<K || !"compute_feature_space_histogram(): k must be less than K" );
00107
00108 ++histogram(i,j,k);
00109 }
00110 }
00111
00112 }
00113
00114 }
00115
00116
00117 #endif