Go to the documentation of this file.00001 #ifndef OPENTISSUE_UTILITY_IMAGE_ANALYSIS_IMAGE_ANALYSIS_COMPUTE_INTENSITY_HISTOGRAM_H
00002 #define OPENTISSUE_UTILITY_IMAGE_ANALYSIS_IMAGE_ANALYSIS_COMPUTE_INTENSITY_HISTOGRAM_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <cmath>
00013
00014 namespace OpenTissue
00015 {
00016 namespace image_analysis
00017 {
00018
00025 template< typename image_type,typename histogram_type >
00026 void compute_intensity_histogram(
00027 image_type const & U
00028 , histogram_type & histogram
00029 , size_t buckets = 256
00030 )
00031 {
00032 typedef typename image_type::const_index_iterator intensity_iterator;
00033 typedef typename image_type::value_type intensity_type;
00034
00035 using std::max;
00036 using std::min;
00037 using std::floor;
00038
00039 histogram.resize(buckets);
00040 for(size_t idx=0;idx<buckets;++idx)
00041 histogram[idx] = 0;
00042
00043 double min_intensity = 1.0*min(U);
00044 double max_intensity = 1.0*max(U);
00045 double i_width = (max_intensity-min_intensity)/buckets;
00046
00047 intensity_iterator i = U.begin();
00048 intensity_iterator end = U.end();
00049 for(;i!=end;++i)
00050 {
00051 size_t i_bucket = static_cast<size_t>( floor((*i - min_intensity)/i_width) );
00052
00053 if(i_bucket==buckets)
00054 --i_bucket;
00055
00056 assert(i_bucket<buckets || !"compute_intensity_histogram(): Illegal bucket index!");
00057
00058 ++(histogram[i_bucket]);
00059 }
00060 }
00061
00062 }
00063
00064 }
00065
00066
00067 #endif