26
26
27
27
namespace itk
28
28
{
29
+ template <typename TInputImage, typename TOutputImage>
30
+ void
31
+ DiscreteGaussianImageFilter<TInputImage, TOutputImage>::GenerateKernel(const unsigned int dimension,
32
+ KernelType & oper) const
33
+ {
34
+ // Determine the size of the operator in this dimension. Note that the
35
+ // Gaussian is built as a 1D operator in each of the specified directions.
36
+ oper.SetDirection (dimension);
37
+ oper.SetMaximumError (m_MaximumError[dimension]);
38
+ oper.SetMaximumKernelWidth (m_MaximumKernelWidth);
39
+
40
+ oper.SetVariance (this ->GetKernelVarianceArray ()[dimension]);
41
+
42
+ oper.CreateDirectional ();
43
+ }
44
+
45
+ template <typename TInputImage, typename TOutputImage>
46
+ unsigned int
47
+ DiscreteGaussianImageFilter<TInputImage, TOutputImage>::GetKernelRadius(const unsigned int dimension) const
48
+ {
49
+ KernelType oper;
50
+ this ->GenerateKernel (dimension, oper);
51
+ return oper.GetRadius (dimension);
52
+ }
53
+
54
+ template <typename TInputImage, typename TOutputImage>
55
+ typename DiscreteGaussianImageFilter<TInputImage, TOutputImage>::ArrayType
56
+ DiscreteGaussianImageFilter<TInputImage, TOutputImage>::GetKernelVarianceArray() const
57
+ {
58
+ if (m_UseImageSpacing)
59
+ {
60
+ if (this ->GetInput () == nullptr )
61
+ {
62
+ itkExceptionMacro (" UseImageSpacing is ON but no input image was provided" );
63
+ }
64
+
65
+ ArrayType adjustedVariance;
66
+ // Adjusted variance = var / (spacing ^ 2)
67
+ for (unsigned int dim = 0 ; dim < ImageDimension; ++dim)
68
+ {
69
+ // convert the variance from physical units to pixels
70
+ double s = this ->GetInput ()->GetSpacing ()[dim];
71
+ s = s * s;
72
+ adjustedVariance[dim] = m_Variance[dim] / s;
73
+ }
74
+ return adjustedVariance;
75
+ }
76
+ else
77
+ {
78
+ return this ->GetVariance ();
79
+ }
80
+ }
81
+
29
82
template <typename TInputImage, typename TOutputImage>
30
83
void
31
84
DiscreteGaussianImageFilter<TInputImage, TOutputImage>::GenerateInputRequestedRegion()
@@ -42,39 +95,18 @@ DiscreteGaussianImageFilter<TInputImage, TOutputImage>::GenerateInputRequestedRe
42
95
return ;
43
96
}
44
97
45
- // Build an operator so that we can determine the kernel size
46
- GaussianOperator<OutputPixelValueType, ImageDimension> oper;
47
-
48
- typename TInputImage::SizeType radius;
49
-
98
+ // Determine the kernel size in each direction
99
+ RadiusType radius;
50
100
for (unsigned int i = 0 ; i < TInputImage::ImageDimension; ++i)
51
101
{
52
- // Determine the size of the operator in this dimension. Note that the
53
- // Gaussian is built as a 1D operator in each of the specified directions.
54
- oper.SetDirection (i);
55
- if (m_UseImageSpacing == true )
102
+ if (i < m_FilterDimensionality)
56
103
{
57
- if (this ->GetInput ()->GetSpacing ()[i] == 0.0 )
58
- {
59
- itkExceptionMacro (<< " Pixel spacing cannot be zero" );
60
- }
61
- else
62
- {
63
- // convert the variance from physical units to pixels
64
- double s = this ->GetInput ()->GetSpacing ()[i];
65
- s = s * s;
66
- oper.SetVariance (m_Variance[i] / s);
67
- }
104
+ radius[i] = GetKernelRadius (i);
68
105
}
69
106
else
70
107
{
71
- oper. SetVariance (m_Variance [i]) ;
108
+ radius [i] = 0 ;
72
109
}
73
- oper.SetMaximumError (m_MaximumError[i]);
74
- oper.SetMaximumKernelWidth (m_MaximumKernelWidth);
75
- oper.CreateDirectional ();
76
-
77
- radius[i] = oper.GetRadius (i);
78
110
}
79
111
80
112
// get a copy of the input requested region (should equal the output
@@ -86,26 +118,9 @@ DiscreteGaussianImageFilter<TInputImage, TOutputImage>::GenerateInputRequestedRe
86
118
inputRequestedRegion.PadByRadius (radius);
87
119
88
120
// crop the input requested region at the input's largest possible region
89
- if (inputRequestedRegion.Crop (inputPtr->GetLargestPossibleRegion ()))
90
- {
91
- inputPtr->SetRequestedRegion (inputRequestedRegion);
92
- return ;
93
- }
94
- else
95
- {
96
- // Couldn't crop the region (requested region is outside the largest
97
- // possible region). Throw an exception.
98
-
99
- // store what we tried to request (prior to trying to crop)
100
- inputPtr->SetRequestedRegion (inputRequestedRegion);
101
-
102
- // build an exception
103
- InvalidRequestedRegionError e (__FILE__, __LINE__);
104
- e.SetLocation (ITK_LOCATION);
105
- e.SetDescription (" Requested region is (at least partially) outside the largest possible region." );
106
- e.SetDataObject (inputPtr);
107
- throw e;
108
- }
121
+ inputRequestedRegion.Crop (inputPtr->GetLargestPossibleRegion ());
122
+
123
+ inputPtr->SetRequestedRegion (inputRequestedRegion);
109
124
}
110
125
111
126
template <typename TInputImage, typename TOutputImage>
@@ -160,9 +175,8 @@ DiscreteGaussianImageFilter<TInputImage, TOutputImage>::GenerateData()
160
175
using SingleFilterPointer = typename SingleFilterType::Pointer;
161
176
162
177
// Create a series of operators
163
- using OperatorType = GaussianOperator<RealOutputPixelValueType, ImageDimension>;
164
178
165
- std::vector<OperatorType > oper;
179
+ std::vector<KernelType > oper;
166
180
oper.resize (filterDimensionality);
167
181
168
182
// Create a process accumulator for tracking the progress of minipipeline
@@ -177,30 +191,7 @@ DiscreteGaussianImageFilter<TInputImage, TOutputImage>::GenerateData()
177
191
// the largest dimension will be split slice wise for streaming
178
192
unsigned int reverse_i = filterDimensionality - i - 1 ;
179
193
180
- // Set up the operator for this dimension
181
- oper[reverse_i].SetDirection (i);
182
- if (m_UseImageSpacing == true )
183
- {
184
- if (localInput->GetSpacing ()[i] == 0.0 )
185
- {
186
- itkExceptionMacro (<< " Pixel spacing cannot be zero" );
187
- }
188
- else
189
- {
190
- // convert the variance from physical units to pixels
191
- double s = localInput->GetSpacing ()[i];
192
- s = s * s;
193
- oper[reverse_i].SetVariance (m_Variance[i] / s);
194
- }
195
- }
196
- else
197
- {
198
- oper[reverse_i].SetVariance (m_Variance[i]);
199
- }
200
-
201
- oper[reverse_i].SetMaximumKernelWidth (m_MaximumKernelWidth);
202
- oper[reverse_i].SetMaximumError (m_MaximumError[i]);
203
- oper[reverse_i].CreateDirectional ();
194
+ this ->GenerateKernel (i, oper[reverse_i]);
204
195
}
205
196
206
197
// Create a chain of filters
0 commit comments