ImageEdgeDistance.h
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2016 Imperial College London
5  * Copyright 2016 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 MIRKT_ImageEdgeDistance_H
21 #define MIRKT_ImageEdgeDistance_H
22 
23 #include "mirtk/SurfaceForce.h"
24 
25 #include "mirtk/FastCubicBSplineInterpolateImageFunction.h"
26 
27 
28 namespace mirtk {
29 
30 
31 /**
32  * External surface force which attracts the surface to nearby image edges
33  */
35 {
36  mirtkEnergyTermMacro(ImageEdgeDistance, EM_ImageEdgeDistance);
37 
38  // ---------------------------------------------------------------------------
39  // Types
40 
41 public:
42 
43  /// Type of discrete intensity image
45 
46  /// Type of image used to store local image statistics
48 
49  /// Type of interpolated image / image interpolation function
51 
52  /// Enumeration of edge force modes based on directional derivative of image intensities
53  enum EdgeType
54  {
55  Extremum, ///< Attract points to closest extrema of same sign
56  ClosestMinimum, ///< Attract points to closest minima
57  ClosestMaximum, ///< Attract points to closest maxima
58  ClosestExtremum, ///< Attract points to closest extrema
59  StrongestMinimum, ///< Attract points to strongest minima
60  StrongestMaximum, ///< Attract points to strongest maxima
61  StrongestExtremum, ///< Attract points to strongest extrema
62  NeonatalWhiteSurface, ///< T2-weighted MRI WM/cGM edge at neonatal age
63  NeonatalPialSurface ///< T2-weighted MRI cGM/CSF edge at neonatal age
64  };
65 
66  // ---------------------------------------------------------------------------
67  // Attributes
68 
69 private:
70 
71  /// Type of edge which points are attracted to
72  mirtkPublicAttributeMacro(enum EdgeType, EdgeType);
73 
74  /// Minimum foreground intensity value
75  mirtkPublicAttributeMacro(double, Padding);
76 
77  /// Minimum object intensity value
78  mirtkPublicAttributeMacro(double, MinIntensity);
79 
80  /// Maximum object intensity value
81  mirtkPublicAttributeMacro(double, MaxIntensity);
82 
83  /// Minimum image edge gradient magnitude
84  mirtkPublicAttributeMacro(double, MinGradient);
85 
86  /// Maximum image edge gradient magnitude to consider a point non-stationary
87  mirtkPublicAttributeMacro(double, MaxGradient);
88 
89  /// Minimum T1-weighted image edge gradient magnitude
90  ///
91  /// An image edge in the T2-weighted image with negative gradient must have
92  /// a corresponding positive gradient in the T1-weighted image. The minimum
93  /// gradient magnitude for a T1-weighted edge to be considered is given by
94  /// this parameter.
95  mirtkPublicAttributeMacro(double, MinT1Gradient);
96 
97  /// Maximum T1-weighted image edge gradient magnitude
98  ///
99  /// An image edge in the T2-weighted image with negative gradient may not
100  /// have a corresponding negative gradient in the T1-weighted image. The
101  /// minimum magnitude of these negative T1-weighted intensity gradients
102  /// to discard such T2-weighted edge is specified by this parameter.
103  mirtkPublicAttributeMacro(double, MaxT1Gradient);
104 
105  /// Maximum edge point distance
106  mirtkPublicAttributeMacro(double, MaxDistance);
107 
108  /// When positive, the force magnitude corresponds to a S-shaped map of
109  /// estimated image edge distances, where points further than the specified
110  /// threshold have constant force magnitude of one. Otherwise, the 95th
111  /// percentile of point distances is used at each iteration.
112  mirtkPublicAttributeMacro(double, DistanceThreshold);
113 
114  /// Radius of distance median filter
115  mirtkPublicAttributeMacro(int, MedianFilterRadius);
116 
117  /// Number of edge distance smoothing iterations
118  mirtkPublicAttributeMacro(int, DistanceSmoothing);
119 
120  /// Step length used for ray casting
121  mirtkPublicAttributeMacro(double, StepLength);
122 
123  /// T1-weighted MR image
124  mirtkPublicAggregateMacro(const RealImage, T1WeightedImage);
125 
126  /// White matter mask used by NeonatalWhiteSurface edge force
127  mirtkPublicAggregateMacro(const BinaryImage, WhiteMatterMask);
128 
129  /// Grey matter mask used by NeonatalWhiteSurface edge force
130  mirtkPublicAggregateMacro(const BinaryImage, GreyMatterMask);
131 
132  /// Approximate distance to boundary of cortex used to disable
133  /// WM->dGM->cGM correction near the boundary to avoid accidental
134  /// correction where a WM->cGM->BG transition is given instead
135  ///
136  /// \sa Application subdivide-brain-image.cc option -output-depth.
137  mirtkPublicAggregateMacro(const RealImage, CorticalHullDistance);
138 
139  /// Distance to ventricles used to ignore edges caused by hyper-intense WM
140  mirtkPublicAggregateMacro(const RealImage, VentriclesDistance);
141 
142  /// Distance to cerebellum used to avoid choosing second downhill part
143  /// of WM->GM->BG transition over WM->GM part in case of following bright
144  /// CSF near the cerebellum which is also surrounded by bright CSF
145  mirtkPublicAggregateMacro(const RealImage, CerebellumDistance);
146 
147  /// Width of local white matter intensity statistics window
148  mirtkPublicAttributeMacro(double, WhiteMatterWindowWidth);
149 
150  /// Width of local grey matter intensity statistics window
151  mirtkPublicAttributeMacro(double, GreyMatterWindowWidth);
152 
153  /// Width of local grey matter intensity statistics window
154  mirtkPublicAttributeMacro(double, T1GreyMatterWindowWidth);
155 
156  /// Global white matter intensity mean value
157  mirtkAttributeMacro(double, GlobalWhiteMatterMean);
158 
159  /// Global white matter intensity variance value
160  mirtkAttributeMacro(double, GlobalWhiteMatterVariance);
161 
162  /// Threshold that separates white and grey matter
163  mirtkAttributeMacro(double, GlobalWhiteMatterThreshold);
164 
165  /// Global grey matter intensity mean value
166  mirtkAttributeMacro(double, GlobalGreyMatterMean);
167 
168  /// Global grey matter intensity variance value
169  mirtkAttributeMacro(double, GlobalGreyMatterVariance);
170 
171  /// Image with voxel-wise local white matter intensity mean values
172  mirtkAttributeMacro(LocalStatsImage, LocalWhiteMatterMean);
173 
174  /// Image with voxel-wise local white matter intensity variance values
175  mirtkAttributeMacro(LocalStatsImage, LocalWhiteMatterVariance);
176 
177  /// Image with voxel-wise local grey matter intensity mean values
178  mirtkAttributeMacro(LocalStatsImage, LocalGreyMatterMean);
179 
180  /// Image with voxel-wise local grey matter intensity variance values
181  mirtkAttributeMacro(LocalStatsImage, LocalGreyMatterVariance);
182 
183  /// Image with voxel-wise local grey matter T1 intensity mean values
184  mirtkAttributeMacro(LocalStatsImage, LocalGreyMatterT1Mean);
185 
186  /// Image with voxel-wise local grey matter T1 intensity variance values
187  mirtkAttributeMacro(LocalStatsImage, LocalGreyMatterT1Variance);
188 
189  /// Bounding box within which to allow WM->dGM->cGM correction
190  mirtkAttributeMacro(Array<int>, CorticalDeepGreyMatterBoundingBox);
191 
192  /// Continuous T1-weighted image
193  mirtkAttributeMacro(SharedPtr<ContinuousImage>, T1WeightedImageFunction);
194 
195  /// Continuous T2-weighted image
196  mirtkAttributeMacro(SharedPtr<ContinuousImage>, T2WeightedImageFunction);
197 
198 private:
199 
200  /// Copy attributes of this class from another instance
201  void CopyAttributes(const ImageEdgeDistance &);
202 
203  // ---------------------------------------------------------------------------
204  // Construction/Destruction
205 
206 public:
207 
208  /// Constructor
209  ImageEdgeDistance(const char * = "", double = 1.0);
210 
211  /// Copy constructor
213 
214  /// Assignment operator
216 
217  /// Destructor
218  virtual ~ImageEdgeDistance();
219 
220  // ---------------------------------------------------------------------------
221  // Configuration
222 
223 protected:
224 
225  /// Set parameter value from string
226  virtual bool SetWithoutPrefix(const char *, const char *);
227 
228 public:
229 
230  // Import other overloads
232 
233  /// Get parameter name/value pairs
234  virtual ParameterList Parameter() const;
235 
236  // ---------------------------------------------------------------------------
237  // Initialization
238 
239  /// Initialize external force once input and parameters have been set
240  virtual void Initialize();
241 
242  // ---------------------------------------------------------------------------
243  // Evaluation
244 
245 public:
246 
247  /// Update moving input points and internal state of force term
248  virtual void Update(bool = true);
249 
250 protected:
251 
252  /// Evaluate external force term
253  virtual double Evaluate();
254 
255  /// Evaluate external force
256  virtual void EvaluateGradient(double *, double, double);
257 
258 };
259 
260 ////////////////////////////////////////////////////////////////////////////////
261 // Enum <-> string conversion
262 ////////////////////////////////////////////////////////////////////////////////
263 
264 template <> bool FromString(const char *, enum ImageEdgeDistance::EdgeType &);
265 template <> string ToString(const enum ImageEdgeDistance::EdgeType &, int, char, bool);
266 
267 
268 } // namespace mirtk
269 
270 #endif // MIRKT_ImageEdgeDistance_H
virtual bool SetWithoutPrefix(const char *, const char *)
Set parameter value from string.
virtual void Initialize()
Initialize external force once input and parameters have been set.
T2-weighted MRI WM/cGM edge at neonatal age.
virtual double Evaluate()
Evaluate external force term.
Attract points to strongest maxima.
GenericImage< float > LocalStatsImage
Type of image used to store local image statistics.
GenericImage< double > DiscreteImage
Type of discrete intensity image.
Attract points to closest extrema.
EdgeType
Enumeration of edge force modes based on directional derivative of image intensities.
T2-weighted MRI cGM/CSF edge at neonatal age.
ImageEdgeDistance & operator=(const ImageEdgeDistance &)
Assignment operator.
Attract points to closest minima.
Array< Pair< string, string > > ParameterList
Ordered list of parameter name/value pairs.
Definition: Object.h:38
Attract points to strongest extrema.
virtual ParameterList Parameter() const
Get parameter key/value as string map.
Definition: IOConfig.h:41
ImageEdgeDistance(const char *="", double=1.0)
Constructor.
virtual void Update(bool=true)
Update moving input points and internal state of force term.
Attract points to strongest minima.
GenericFastCubicBSplineInterpolateImageFunction< DiscreteImage > ContinuousImage
Type of interpolated image / image interpolation function.
Image edge distance.
Definition: EnergyMeasure.h:72
virtual void EvaluateGradient(double *, double, double)
Evaluate external force.
string ToString(const EnergyMeasure &value, int w, char c, bool left)
Convert energy measure enumeration value to string.
bool FromString(const char *str, EnergyMeasure &value)
Convert energy measure string to enumeration value.
Attract points to closest extrema of same sign.
virtual ~ImageEdgeDistance()
Destructor.
virtual ParameterList Parameter() const
Get parameter name/value pairs.
Attract points to closest maxima.