Downsampling.h
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2013-2015 Imperial College London
5  * Copyright 2013-2015 Andreas Schuh
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 #ifndef MIRTK_Downsampling_H
21 #define MIRTK_Downsampling_H
22 
23 #include "mirtk/GenericImage.h"
24 #include "mirtk/ImageToImage.h"
25 #include "mirtk/ScalarFunction.h"
26 
27 
28 namespace mirtk {
29 
30 
31 /**
32  * Filter for downsampling of images by a power of two
33  *
34  * By default, a Gaussian kernel is used to average the voxel intensities within
35  * the neighborhood corresponding to each downsampled voxel. This can be disabled
36  * by specifying a zero sigma value for the Gaussian kernel.
37  */
38 template <class TVoxel>
39 class Downsampling : public ImageToImage<TVoxel>
40 {
41  mirtkImageFilterMacro(Downsampling, TVoxel);
42 
43  // ---------------------------------------------------------------------------
44  // Attributes
45 
46  /// Downsampling factor in x dimension
47  mirtkPublicAttributeMacro(int, DownsampleFactorX);
48 
49  /// Downsampling factor in y dimension
50  mirtkPublicAttributeMacro(int, DownsampleFactorY);
51 
52  /// Downsampling factor in z dimension
53  mirtkPublicAttributeMacro(int, DownsampleFactorZ);
54 
55  /// Custom kernel to be applied at each downsampled voxel or NULL
56  ScalarFunction *_Kernel;
57 
58  /// Extend of discretized kernel
59  int _KernelSize;
60 
61  /// Whether to normalize the discretized kernel weights
62  bool _NormalizeKernel;
63 
64 protected:
65 
66  /// Initialize the filter
67  virtual void Initialize();
68 
69  /// Discretize continious kernel
71 
72 public:
73 
74  /// Constructor
75  Downsampling(int = 2);
76 
77  /// Constructor
78  Downsampling(int, int, int = 1);
79 
80  /// Set downsampling kernel and desired radius of discretized kernel
81  void Kernel(ScalarFunction *, int, bool = true);
82 
83  /// Run the downsampling filter
84  virtual void Run();
85 
86 };
87 
88 
89 } // namespace mirtk
90 
91 #endif // MIRTK_Downsampling_H
virtual void Run()
Run the downsampling filter.
virtual void Initialize()
Initialize the filter.
void DiscreteKernel(GenericImage< RealPixel > &, double)
Discretize continious kernel.
Definition: IOConfig.h:41
Downsampling(int=2)
Constructor.
void Kernel(ScalarFunction *, int, bool=true)
Set downsampling kernel and desired radius of discretized kernel.