aimsalgo  5.1.2
Neuroimaging image processing
ggradient.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 
36 #ifndef AIMS_SIGNALFILTER_GGRADIENT_H
37 #define AIMS_SIGNALFILTER_GGRADIENT_H
38 
43 
44 
45 template< class T >
47 {
48 public:
49 
50  GaussianGradient( float sx=1.0f, float sy=1.0f, float sz=1.0f );
51  virtual ~GaussianGradient() { }
52 
55  const carto::rc_ptr<carto::Volume< T > >& data ) ;
56 private:
57 
58  float sigx;
59  float sigy;
60  float sigz;
61 };
62 
63 
64 template< class T > inline
65 GaussianGradient< T >::GaussianGradient( float sx, float sy, float sz )
66  : sigx( sx ), sigy( sy ), sigz( sz )
67 {
68  ASSERT( sigx >= 0.1f && sigx <= 100.0f );
69  ASSERT( sigy >= 0.1f && sigy <= 100.0f );
70  ASSERT( sigz >= 0.1f && sigz <= 100.0f );
71 }
72 
73 
74 template< class T > inline carto::VolumeRef< float >
76 {
77  int x,y,z;
78  std::vector<float> vs = data->getVoxelSize();
79  float sx = sigx / vs[0];
80  float sy = sigy / vs[1];
81  float sz = sigz / vs[2];
82 
85 
87  imaF=carto::VolumeRef<float>( data->getSize() );
88  conv.convert( data, imaF );
89 
90  for ( int i=0; i<3; i++ )
91  res[i]=imaF.copy();
92 
93 
94 
96  grad=carto::VolumeRef<float>( data->getSize() );
97 
98  GaussianSlices gsli;
99  GaussianLines glin;
100  GaussianColumns gcol;
101 
102  // d / dx
103  glin.doit( res[ 0 ], GCoef( sx, GCoef::gradient ) );
104  gcol.doit( res[ 0 ], GCoef( sy ) ); // because default is smoothing
105  gsli.doit( res[ 0 ], GCoef( sz ) );
106 
107  // d / dy
108  glin.doit( res[ 1 ], GCoef( sx ) );
109  gcol.doit( res[ 1 ], GCoef( sy, GCoef::gradient ) );
110  gsli.doit( res[ 1 ], GCoef( sz ) );
111 
112  // d / dz
113  glin.doit( res[ 2 ], GCoef( sx ) );
114  gcol.doit( res[ 2 ], GCoef( sy ) );
115  gsli.doit( res[ 2 ], GCoef( sz, GCoef::gradient ) );
116 
117  for (z=0; z< data->getSizeZ(); z++)
118  for (y=0; y< data->getSizeY(); y++)
119  for(x=0; x< data->getSizeX(); x++)
120  {
121  grad(x,y,z)=sqrt ( (res[0](x,y,z)*res[0](x,y,z))
122  + (res[1](x,y,z)*res[1](x,y,z))
123  + (res[2](x,y,z)*res[2](x,y,z)) );
124  }
125 
126  return grad;
127 }
128 
129 template< class T > inline AimsVector< carto::VolumeRef< float >, 3 >
131  const carto::rc_ptr<carto::Volume< T > >& data )
132 {
133  std::vector<float> vs = data->getVoxelSize();
134  float sx = sigx / vs[0];
135  float sy = sigy / vs[1];
136  float sz = sigz / vs[2];
137 
140 
142  imaF=carto::VolumeRef<float>( data->getSize() );
143  conv.convert( data, imaF );
144 
145  for ( int i=0; i<3; i++ )
146  res[i]=imaF.copy();
147 
148 
149 
151  grad=carto::VolumeRef<float>( data->getSize() );
152 
153  GaussianSlices gsli;
154  GaussianLines glin;
155  GaussianColumns gcol;
156 
157  // d / dx
158  glin.doit( res[ 0 ], GCoef( sx, GCoef::gradient ) );
159  gcol.doit( res[ 0 ], GCoef( sy ) ); // because default is smoothing
160  gsli.doit( res[ 0 ], GCoef( sz ) );
161 
162  // d / dy
163  glin.doit( res[ 1 ], GCoef( sx ) );
164  gcol.doit( res[ 1 ], GCoef( sy, GCoef::gradient ) );
165  gsli.doit( res[ 1 ], GCoef( sz ) );
166 
167  // d / dz
168  glin.doit( res[ 2 ], GCoef( sx ) );
169  gcol.doit( res[ 2 ], GCoef( sy ) );
170  gsli.doit( res[ 2 ], GCoef( sz, GCoef::gradient ) );
171 
172  return res ;
173 }
174 #endif
#define ASSERT(EX)
Definition: gcoef.h:42
@ gradient
Definition: gcoef.h:49
void doit(carto::rc_ptr< carto::Volume< float > > &)
carto::VolumeRef< float > doit(const carto::rc_ptr< carto::Volume< T > > &)
Definition: ggradient.h:75
virtual ~GaussianGradient()
Definition: ggradient.h:51
AimsVector< carto::VolumeRef< float >, 3 > doitGradientVector(const carto::rc_ptr< carto::Volume< T > > &data)
Definition: ggradient.h:130
GaussianGradient(float sx=1.0f, float sy=1.0f, float sz=1.0f)
Definition: ggradient.h:65
void doit(carto::rc_ptr< carto::Volume< float > > &)
void doit(carto::rc_ptr< carto::Volume< float > > &)
virtual void convert(const INP &in, OUTP &out) const
std::vector< float > getVoxelSize() const
VolumeRef< T > copy() const