Go to the documentation of this file.00001 #ifndef OPENTISSUE_UTILITY_IMAGE_ANALYSIS_IMAGE_ANALYSIS_COMPUTE_HISTOGRAM_EQUALIZATION_H
00002 #define OPENTISSUE_UTILITY_IMAGE_ANALYSIS_IMAGE_ANALYSIS_COMPUTE_HISTOGRAM_EQUALIZATION_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 namespace OpenTissue
00013 {
00014 namespace image_analysis
00015 {
00020 template<
00021 typename grid_type_in
00022 , typename equalized_histogram_type
00023 >
00024 void compute_histogram_equalization(
00025 grid_type_in const & image
00026 , equalized_histogram_type & equal_histogram
00027 )
00028 {
00029 typedef typename grid_type_in::value_type image_value;
00030 typedef typename grid_type_in::const_index_iterator image_iterator;
00031 typedef typename equalized_histogram_type::index_iterator equal_histogram_iterator;
00032
00033 using std::min;
00034 using std::max;
00035
00036 equal_histogram.create(image.min_coord(),image.max_coord(),image.I(),image.J(),image.K());
00037
00038 image_value max_val = max(image);
00039 image_value min_val = min(image);
00040
00041 image_value cnt_values = (max_val - min_val)+1;
00042 std::vector<size_t> n(cnt_values,0);
00043
00044 image_iterator ibegin = image.begin();
00045 image_iterator iend = image.end();
00046 image_iterator i;
00047 size_t N = 0;
00048 for(i=ibegin;i!=iend;++i)
00049 {
00050 ++n[ *i - min_val];
00051 ++N;
00052 }
00053
00054 equal_histogram_iterator ebegin = equal_histogram.begin();
00055 equal_histogram_iterator eend = equal_histogram.end();
00056 equal_histogram_iterator e;
00057 for(e=ebegin,i=ibegin;i!=iend;++i,++e)
00058 {
00059 size_t nk = 0;
00060 for(size_t k=min_val;k<=*i;++k)
00061 nk += n[ k - min_val];
00062 *e = (1.0*nk)/N;
00063 }
00064 }
00065
00066 }
00067
00068 }
00069
00070
00071 #endif