aimsalgo  5.0.5
Neuroimaging image processing
subsamplingimagealgorithm.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 #ifndef AIMSALGO_RESAMPLING_SUBSAMPLINGIMAGEALGORITHM_H
35 #define AIMSALGO_RESAMPLING_SUBSAMPLINGIMAGEALGORITHM_H
36 
37 //--- aims -------------------------------------------------------------------
40 #include <aims/data/data.h>
41 #include <aims/utility/progress.h>
42 #include <aims/vector/vector.h>
43 //--- cartobase --------------------------------------------------------------
45 #include <cartobase/type/types.h>
48 #include <cartobase/smart/rcptr.h>
49 //--- std --------------------------------------------------------------------
50 #include <iostream>
51 //----------------------------------------------------------------------------
52 
53 namespace aims {
54 
55  template <typename T> class SubSamplingImageAlgorithm;
56  namespace singlechannel { template <typename T> class SubSamplingImageAlgorithm; }
57 
58  //==========================================================================
59  // SUBSAMPLING IMAGE ALGORITHM
60  //==========================================================================
66  template <typename T>
68  {
69  public:
70  //----------------------------------------------------------------------
71  // types
72  //----------------------------------------------------------------------
73  typedef T VoxelType;
76 
77  //----------------------------------------------------------------------
78  // image algorithm interface: implementation
79  //----------------------------------------------------------------------
81  {
82  return new SubSamplingImageAlgorithm<T>(*this);
83  }
84 
85  //----------------------------------------------------------------------
86  // constructor (default+copy) & destructor
87  //----------------------------------------------------------------------
88  protected:
90  SubSamplingImageAlgorithm( int sx, int sy, int sz,
92  ImageAlgorithm<T>( SingleChannelImageAlgorithmType(sx, sy, sz, f) )
93  {}
94 
96  ImageAlgorithm<T>( other )
97  {}
98 
100  {
101  ASSERT( typeid(other) == typeid(*this) );
102  if( &other != this )
104  return *this;
105  }
106 
107  public:
109  };
110 
111  namespace singlechannel {
112 
113  //========================================================================
114  // SUBSAMPLING IMAGE ALGORITHM: SINGLE CHANNEL PROCESSING
115  //========================================================================
123  template <typename T>
125  {
126  public:
127  //--------------------------------------------------------------------
128  // types
129  //--------------------------------------------------------------------
130  typedef T VoxelType;
131 
132  //--------------------------------------------------------------------
133  // image algorithm interface: implementation
134  //--------------------------------------------------------------------
135  virtual void execute( const carto::VolumeRef<T> & in,
136  carto::VolumeRef<T> & out ) const;
137 
138  virtual Point4dl getOutputImageDimensions( const Point4dl & dims ) const {
139  return Point4dl( dims[0] / _win_size_x,
140  dims[1] / _win_size_y,
141  dims[2] / _win_size_z,
142  dims[3] );
143  }
144 
145  virtual Point4df getOutputImageVoxelSize( const Point4df & voxelsize ) const {
146  return Point4df( voxelsize[0] * _win_size_x,
147  voxelsize[1] * _win_size_y,
148  voxelsize[2] * _win_size_z,
149  voxelsize[3] );
150  }
151 
153  {
154  return new SubSamplingImageAlgorithm<T>(*this);
155  }
156 
157  //--------------------------------------------------------------------
158  // constructor (default+copy) & destructor
159  //--------------------------------------------------------------------
160  SubSamplingImageAlgorithm( int sx, int sy, int sz,
161  const FilteringFunctionInterface<T> & f ):
163  _win_size_x( sx ),
164  _win_size_y( sy ),
165  _win_size_z( sz ),
166  _func( f.clone() )
167  {}
168 
171  _win_size_x( other._win_size_x ),
172  _win_size_y( other._win_size_y ),
173  _win_size_z( other._win_size_z ),
174  _func( other._func->clone() )
175  {}
176 
178  {
179  ASSERT( typeid(other) == typeid(*this) );
180  if( &other != this ) {
181  _win_size_x = other._win_size_x;
182  _win_size_y = other._win_size_y;
183  _win_size_z = other._win_size_z;
184  _func.reset( other._func->clone() );
185  }
186  return *this;
187  }
188 
190 
191  protected:
196  };
197 
198 
199  template <typename T> inline
201  const carto::VolumeRef<T> & in,
202  carto::VolumeRef<T> & out
203  ) const
204  {
205  int32_t st = (int32_t)out->getSizeT(),
206  sz = (int32_t)out->getSizeZ(),
207  sy = (int32_t)out->getSizeY(),
208  sx = (int32_t)out->getSizeX();
209  if( st * sz * sy > 0 )
210  {
211  // Creates a view in the input volume that has windows dimensions
214  in,
215  typename carto::Volume<VoxelType>::Position4Di( 0, 0, 0, 0 ),
217  _win_size_y,
218  _win_size_z,
219  1 )
220  )
221  );
222 
223  int32_t i, j, k, t;
224  aims::Progression progress( (long) st *
225  (long) sz *
226  (long) sy *
227  (long) sx );
228 
229  if( this->_verbose > 0 )
230  std::cout << "Subsampling progress: ";
231 
232  for( t = 0; t < st; ++t )
233  for( k = 0; k < sz; ++k )
234  for( j = 0; j < sy; ++j )
235  for( i = 0; i < sx; ++i )
236  {
237  if( this->_verbose > 0 )
238  (++progress).print();
239  // Set view position in the volume
241  i * _win_size_x, j * _win_size_y, k * _win_size_z, t) );
242 // std::cout << "Window position: ["
243 // << carto::toString(i * _win_size_x) << ", "
244 // << carto::toString(j * _win_size_y) << ", "
245 // << carto::toString(k * _win_size_z) << ", "
246 // << carto::toString(t) << "]"
247 // << std::endl << std::flush;
248 
249  (*out)( i, j, k, t ) = _func->execute(win);
250  }
251 
252  if( this->_verbose > 0 )
253  std::cout << std::endl;
254  }
255 
256  } // internal::SubSamplingImageAlgorithm::execute()
257 
258  } // namespace internal
259 
260 }
261 
262 #endif
carto::rc_ptr< FilteringFunctionInterface< T > > _func
virtual SubSamplingImageAlgorithm< T > * clone() const
ImageAlgorithmInterface<T> Pure virtual method.
int getSizeX() const
int getSizeY() const
int getSizeZ() const
int getSizeT() const
singlechannel::SubSamplingImageAlgorithm< ChannelType > SingleChannelImageAlgorithmType
aims::SubSamplingImageAlgorithm is the algorithm to subsample image.
virtual Point4dl getOutputImageDimensions(const Point4dl &dims) const
Returns the output dimensions of the processed image.
SubSamplingImageAlgorithm< T > & operator=(const SubSamplingImageAlgorithm &other)
virtual void execute(const carto::VolumeRef< T > &in, carto::VolumeRef< T > &out) const
ImageAlgorithmInterface<T> Pure virtual method.
carto::DataTypeTraits< T >::ChannelType ChannelType
SubSamplingImageAlgorithm(int sx, int sy, int sz, const FilteringFunctionInterface< T > &f)
SubSamplingImageAlgorithm(const SubSamplingImageAlgorithm &other)
SubSamplingImageAlgorithm(const SubSamplingImageAlgorithm &other)
virtual Point4df getOutputImageVoxelSize(const Point4df &voxelsize) const
Returns the output voxel size of the processed image.
Pure virtual class: interface for filtering functions called by aims::FilteringImageAlgorithm and aim...
void setPosInRefVolume(const Position4Di &pos)
SubSamplingImageAlgorithm(int sx, int sy, int sz, const FilteringFunctionInterface< ChannelType > &f)
aims::ImageAlgorithm class used to implement image algorithms
aims::ImageAlgorithmInterface is the interface for an image processing algorithm. ...
ImageAlgorithm & operator=(const ImageAlgorithm &other)
#define ASSERT(EX)
aims::singlechannel::SubSamplingImageAlgorithm is the algorithm to apply subsampling on single channe...
virtual SubSamplingImageAlgorithm< T > * clone() const
ImageAlgorithmInterface<T> Pure virtual method.