-
Notifications
You must be signed in to change notification settings - Fork 12
/
itkDescoteauxSheetnessImageFilter.h
255 lines (227 loc) · 6.01 KB
/
itkDescoteauxSheetnessImageFilter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef itkDescoteauxSheetnessImageFilter_h
#define itkDescoteauxSheetnessImageFilter_h
#include "itkUnaryFunctorImageFilter.h"
#include "itkMath.h"
namespace itk
{
/** \class DescoteauxSheetnessImageFilter
*
* \brief Computes a measure of Sheetness from the Hessian Eigenvalues
*
* Based on the "Sheetness" measure proposed by Decouteaux et. al.
*
* M.Descoteaux, M.Audette, K.Chinzei, el al.:
* "Bone enhancement filtering: Application to sinus bone segmentation
* and simulation of pituitary surgery."
* In: MICCAI. (2005) 9-16
*
* \ingroup IntensityImageFilters Multithreaded
* \ingroup LesionSizingToolkit
*/
namespace Function
{
template <typename TInput, typename TOutput>
class Sheetness
{
public:
Sheetness()
{
m_Alpha = 0.5; // suggested value in the paper
m_Gamma = 0.5; // suggested value in the paper;
m_C = 1.0;
m_DetectBrightSheets = true;
}
~Sheetness() = default;
bool
operator!=(const Sheetness &) const
{
return false;
}
bool
operator==(const Sheetness & other) const
{
return !(*this != other);
}
inline TOutput
operator()(const TInput & A)
{
double sheetness = 0.0;
auto a1 = static_cast<double>(A[0]);
auto a2 = static_cast<double>(A[1]);
auto a3 = static_cast<double>(A[2]);
double l1 = itk::Math::abs(a1);
double l2 = itk::Math::abs(a2);
double l3 = itk::Math::abs(a3);
//
// Sort the values by their absolute value.
// At the end of the sorting we should have
//
// l1 <= l2 <= l3
//
if (l2 > l3)
{
double tmpl = l3;
l3 = l2;
l2 = tmpl;
double tmpa = a3;
a3 = a2;
a2 = tmpa;
}
if (l1 > l2)
{
double tmp = l1;
l1 = l2;
l2 = tmp;
double tmpa = a1;
a1 = a2;
a2 = tmpa;
}
if (l2 > l3)
{
double tmp = l3;
l3 = l2;
l2 = tmp;
double tmpa = a3;
a3 = a2;
a2 = tmpa;
}
if (this->m_DetectBrightSheets)
{
if (a3 > 0.0)
{
return static_cast<TOutput>(sheetness);
}
}
else
{
if (a3 < 0.0)
{
return static_cast<TOutput>(sheetness);
}
}
//
// Avoid divisions by zero (or close to zero)
//
if (static_cast<double>(l3) < itk::Math::eps)
{
return static_cast<TOutput>(sheetness);
}
const double Rs = l2 / l3;
const double Rb = itk::Math::abs(l3 + l3 - l2 - l1) / l3;
const double Rn = std::sqrt(l3 * l3 + l2 * l2 + l1 * l1);
sheetness = std::exp(-(Rs * Rs) / (2.0 * m_Alpha * m_Alpha));
sheetness *= (1.0 - std::exp(-(Rb * Rb) / (2.0 * m_Gamma * m_Gamma)));
sheetness *= (1.0 - std::exp(-(Rn * Rn) / (2.0 * m_C * m_C)));
return static_cast<TOutput>(sheetness);
}
void
SetAlpha(double value)
{
this->m_Alpha = value;
}
void
SetGamma(double value)
{
this->m_Gamma = value;
}
void
SetC(double value)
{
this->m_C = value;
}
void
SetDetectBrightSheets(bool value)
{
this->m_DetectBrightSheets = value;
}
void
SetDetectDarkSheets(bool value)
{
this->m_DetectBrightSheets = !value;
}
private:
double m_Alpha;
double m_Gamma;
double m_C;
bool m_DetectBrightSheets;
};
} // namespace Function
template <typename TInputImage, typename TOutputImage>
class ITK_TEMPLATE_EXPORT DescoteauxSheetnessImageFilter
: public UnaryFunctorImageFilter<
TInputImage,
TOutputImage,
Function::Sheetness<typename TInputImage::PixelType, typename TOutputImage::PixelType>>
{
public:
ITK_DISALLOW_COPY_AND_MOVE(DescoteauxSheetnessImageFilter);
/** Standard class type alias. */
using Self = DescoteauxSheetnessImageFilter;
using Superclass =
UnaryFunctorImageFilter<TInputImage,
TOutputImage,
Function::Sheetness<typename TInputImage::PixelType, typename TOutputImage::PixelType>>;
using Pointer = SmartPointer<Self>;
using ConstPointer = SmartPointer<const Self>;
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Runtime information support. */
itkTypeMacro(DescoteauxSheetnessImageFilter, UnaryFunctorImageFilter);
/** Set the normalization term for sheetness */
void
SetSheetnessNormalization(double value)
{
this->GetFunctor().SetAlpha(value);
}
/** Set the normalization term for bloobiness. */
void
SetBloobinessNormalization(double value)
{
this->GetFunctor().SetGamma(value);
}
/** Set the normalization term for noise. */
void
SetNoiseNormalization(double value)
{
this->GetFunctor().SetC(value);
}
void
SetDetectBrightSheets(bool value)
{
this->GetFunctor().SetDetectBrightSheets(value);
}
void
SetDetectDarkSheets(bool value)
{
this->GetFunctor().SetDetectDarkSheets(value);
}
#ifdef ITK_USE_CONCEPT_CHECKING
/** Begin concept checking */
using InputPixelType = typename TInputImage::PixelType;
itkConceptMacro(BracketOperatorsCheck, (Concept::BracketOperator<InputPixelType, unsigned int, double>));
itkConceptMacro(DoubleConvertibleToOutputCheck, (Concept::Convertible<double, typename TOutputImage::PixelType>));
/** End concept checking */
#endif
protected:
DescoteauxSheetnessImageFilter() = default;
~DescoteauxSheetnessImageFilter() override = default;
};
} // end namespace itk
#endif