aimsalgo  5.1.2
Neuroimaging image processing
equalizedHisto.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2  * Institut Federatif de Recherche 49
3  * CEA/NeuroSpin, Batiment 145,
4  * 91191 Gif-sur-Yvette cedex
5  * France
6  *
7  * This software is governed by the CeCILL-B license under
8  * French law and abiding by the rules of distribution of free software.
9  * You can use, modify and/or redistribute the software under the
10  * terms of the CeCILL-B license as circulated by CEA, CNRS
11  * and INRIA at the following URL "http://www.cecill.info".
12  *
13  * As a counterpart to the access to the source code and rights to copy,
14  * modify and redistribute granted by the license, users are provided only
15  * with a limited warranty and the software's author, the holder of the
16  * economic rights, and the successive licensors have only limited
17  * liability.
18  *
19  * In this respect, the user's attention is drawn to the risks associated
20  * with loading, using, modifying and/or developing or reproducing the
21  * software by the user in light of its specific status of free software,
22  * that may mean that it is complicated to manipulate, and that also
23  * therefore means that it is reserved for developers and experienced
24  * professionals having in-depth computer knowledge. Users are therefore
25  * encouraged to load and test the software's suitability as regards their
26  * requirements in conditions enabling the security of their systems and/or
27  * data to be ensured and, more generally, to use and operate it in the
28  * same conditions as regards security.
29  *
30  * The fact that you are presently reading this means that you have had
31  * knowledge of the CeCILL-B license and that you accept its terms.
32  */
33 
34 
35 #ifndef AIMS_HISTOGRAM_EQUALIZEDHISTO_H
36 #define AIMS_HISTOGRAM_EQUALIZEDHISTO_H
37 
39 
42 template< class T>
43 class Equalizer
44 {
45  public:
46 
50  Equalizer() {};
52  virtual ~Equalizer() { }
54 
55  //
57  //
58  // Histogram equalization from Volume
59  // return the equalized image
61 };
62 
63 
64 template <class T> inline
66  const carto::rc_ptr<carto::Volume<T> > & thing)
67 {
68 
69  //
70  // Data
71  //
72  int min = int(thing->min()), max = int(thing->max()),
73  nb_tot = thing->getSizeX() * thing->getSizeY() * thing->getSizeZ();
74  float fraction;
75  int tmp;
76 
79 
80  //
81  // Histogram computation
82  //
83  max = max - min;
84  carto::VolumeRef<int32_t> myHisto( max + 1, 1, 1, 1,
85  carto::AllocatorContext::fast() );
86 
87  for(it = thing->begin(); it != thing->end(); ++it)
88  {
89  tmp = ( int32_t ) *it;
90  ++myHisto( tmp - min );
91  }
92 
93  carto::VolumeRef<float> cumul( max + 1, 1, 1, 1,
94  carto::AllocatorContext::fast() );
95  cumul( 0 ) = myHisto( 0 );
96 
98  float * it2 = &*cumul.begin() + 1;
99 
100  for( it1 = myHisto.begin(), ++it1; it1 != myHisto.end(); ++it1, ++it2 )
101  *it2 = *it1 + *( it2 - 1 );
102 
104  for (it4 = cumul.begin(); it4 != cumul.end(); ++it4 )
105  *it4 /= (float) nb_tot;
106 
107  //
108  // Rounded cumulated histogram
109  //
110  carto::VolumeRef<int32_t> roundcumul( max + 1, 1, 1, 1,
111  carto::AllocatorContext::fast() );
112 
113  it2 = &*cumul.begin();
114  for (it1 = roundcumul.begin(); it1 != roundcumul.end(); ++it1 , ++it2)
115  {
116  fraction = *it2 * max;
117  *it1 += int32_t(fraction + 0.5); // round by implicit cast
118  }
119 
120  //
121  // Equalized data computation
122  //
123  typename carto::Volume<T>::iterator it3;
124 
125  for ( it3 = res.begin(); it3 != res.end(); ++it3, ++it)
126  *it3 = static_cast<T> ( roundcumul( int32_t(*it3) ) - roundcumul(0) );
127 
128  return (res);
129 }
130 
131 #endif
Classical histogram container class.
virtual ~Equalizer()
destructor.
carto::VolumeRef< T > doit(const carto::rc_ptr< carto::Volume< T > > &thing)
Equalizer()
constructor. Does nothing.
VolumeRef< T > deepcopy() const
iterator end()
iterator begin()
iterator begin()
blitz::Array< T, Volume< T >::DIM_MAX >::const_iterator const_iterator
iterator end()
blitz::Array< T, Volume< T >::DIM_MAX >::iterator iterator
float min(float x, float y)
Definition: thickness.h:106
float max(float x, float y)
Definition: thickness.h:98