A.I.M.S algorithms


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,
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>
124  class SubSamplingImageAlgorithm: public ImageAlgorithmInterface<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 ):
162  _win_size_x( sx ),
163  _win_size_y( sy ),
164  _win_size_z( sz ),
165  _func( f.clone() )
166  {}
167 
169  _win_size_x( other._win_size_x ),
170  _win_size_y( other._win_size_y ),
171  _win_size_z( other._win_size_z ),
172  _func( other._func->clone() )
173  {}
174 
176  {
177  ASSERT( typeid(other) == typeid(*this) );
178  if( &other != this ) {
179  _win_size_x = other._win_size_x;
180  _win_size_y = other._win_size_y;
181  _win_size_z = other._win_size_z;
182  _func.reset( other._func->clone() );
183  }
184  return *this;
185  }
186 
188 
189  protected:
194  };
195 
196 
197  template <typename T> inline
199  const carto::VolumeRef<T> & in,
200  carto::VolumeRef<T> & out
201  ) const
202  {
203  if( out->getSizeT() * out->getSizeZ() * out->getSizeY() > 0 )
204  {
205  // Creates a view in the input volume that has windows dimensions
208  in,
209  typename carto::Volume<VoxelType>::Position4Di( 0, 0, 0, 0 ),
210  typename carto::Volume<VoxelType>::Position4Di( _win_size_x,
211  _win_size_y,
212  _win_size_z,
213  1 )
214  )
215  );
216 
217  int32_t i, j, k, t;
218  unsigned m, n, l;
219  aims::Progression progress( out->getSizeT() *
220  out->getSizeZ() *
221  out->getSizeY() - 1 );
222 
223  if( this->_verbose > 0 )
224  std::cout << "Subsampling progress: ";
225 
226  for( t = 0; t < (int32_t)out->getSizeT(); ++t )
227  for( k = 0; k < (int32_t)out->getSizeZ(); ++k )
228  for( j = 0; j < (int32_t)out->getSizeY(); ++j, ++progress )
229  {
230  // Display progression
231  // The "normal" operator << should be as:
232  // std::cout << progress << std::flush;
233  // but it doesn't work in gcc 4.0, there is a namespace
234  // confusion, so we have to specify ::operator <<
236  ::operator << ( std::cout, progress ) << std::flush;
237 
238  for( i = 0; i < (int32_t)out->getSizeX(); ++i ) {
239  // Set view position in the volume
241  i * _win_size_x, j * _win_size_y, k * _win_size_z, t) );
242  (*out)( i, j, k, t ) = _func->execute(win);
243  }
244  }
245 
246  if( this->_verbose > 0 )
247  std::cout << std::endl;
248  }
249 
250  } // internal::SubSamplingImageAlgorithm::execute()
251 
252  } // namespace internal
253 
254 }
255 
256 #endif
carto::rc_ptr< FilteringFunctionInterface< T > > _func
int getSizeY() const
SubSamplingImageAlgorithm & operator=(const SubSamplingImageAlgorithm &other)
int getSizeZ() const
singlechannel::SubSamplingImageAlgorithm< ChannelType > SingleChannelImageAlgorithmType
virtual void execute(const carto::VolumeRef< T > &in, carto::VolumeRef< T > &out) const
ImageAlgorithmInterface Pure virtual method.
aims::SubSamplingImageAlgorithm is the algorithm to subsample image.
virtual SubSamplingImageAlgorithm< T > * clone() const
ImageAlgorithmInterface Pure virtual method.
SubSamplingImageAlgorithm< T > & operator=(const SubSamplingImageAlgorithm &other)
virtual Point4df getOutputImageVoxelSize(const Point4df &voxelsize) const
Returns the output voxel size of the processed image.
int getSizeT() const
virtual Point4dl getOutputImageDimensions(const Point4dl &dims) const
Returns the output dimensions of the processed image.
carto::DataTypeTraits< T >::ChannelType ChannelType
SubSamplingImageAlgorithm(int sx, int sy, int sz, const FilteringFunctionInterface< T > &f)
SubSamplingImageAlgorithm(const SubSamplingImageAlgorithm &other)
SubSamplingImageAlgorithm(const SubSamplingImageAlgorithm &other)
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
virtual SubSamplingImageAlgorithm< T > * clone() const
ImageAlgorithmInterface Pure virtual method.
aims::ImageAlgorithmInterface is the interface for an image processing algorithm. ...
int getSizeX() const
ImageAlgorithm & operator=(const ImageAlgorithm &other)
#define ASSERT(EX)
aims::singlechannel::SubSamplingImageAlgorithm is the algorithm to apply subsampling on single channe...