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