@@ -88,9 +88,10 @@ AttenuationImageFilter<TInputImage, TOutputImage, TMaskImage>::GetImageRegionSpl
88
88
89
89
template <typename TInputImage, typename TOutputImage, typename TMaskImage>
90
90
void
91
- AttenuationImageFilter<TInputImage, TOutputImage, TMaskImage>::BeforeThreadedGenerateData()
91
+ AttenuationImageFilter<TInputImage, TOutputImage, TMaskImage>::VerifyPreconditions() const
92
92
{
93
- // Verify inputs
93
+ Superclass::VerifyPreconditions ();
94
+
94
95
if (this ->GetInputMaskImage () == nullptr )
95
96
{
96
97
itkExceptionMacro (" Filter requires a mask image for inclusion estimates!" );
@@ -109,7 +110,12 @@ AttenuationImageFilter<TInputImage, TOutputImage, TMaskImage>::BeforeThreadedGen
109
110
{
110
111
itkExceptionMacro (" RF sampling frequency was not set!" );
111
112
}
113
+ }
112
114
115
+ template <typename TInputImage, typename TOutputImage, typename TMaskImage>
116
+ void
117
+ AttenuationImageFilter<TInputImage, TOutputImage, TMaskImage>::BeforeThreadedGenerateData()
118
+ {
113
119
Superclass::BeforeThreadedGenerateData ();
114
120
115
121
// Initialize metric image
@@ -122,6 +128,19 @@ AttenuationImageFilter<TInputImage, TOutputImage, TMaskImage>::BeforeThreadedGen
122
128
m_OutputMaskImage->SetRegions (inputMaskImage->GetLargestPossibleRegion ());
123
129
m_OutputMaskImage->Allocate ();
124
130
m_OutputMaskImage->FillBuffer (0 .0f );
131
+
132
+ // Initialize iVars used in ComputeAttenuation()
133
+ float nyquistFrequency = m_SamplingFrequencyMHz / 2 ;
134
+ float numComponents = this ->GetInput ()->GetNumberOfComponentsPerPixel ();
135
+ m_FrequencyDelta = nyquistFrequency / numComponents;
136
+ m_StartComponent = m_FrequencyBandStartMHz / m_FrequencyDelta;
137
+ m_EndComponent = m_FrequencyBandEndMHz / m_FrequencyDelta;
138
+ if (m_EndComponent == 0 ) // If m_FrequencyBandEndMHz is not set
139
+ {
140
+ m_EndComponent = numComponents - 1 ; // Use all components
141
+ }
142
+ m_ConsideredComponents = m_EndComponent - m_StartComponent + 1 ;
143
+ m_ScanStepMM = this ->GetInput ()->GetSpacing ()[m_Direction];
125
144
}
126
145
127
146
template <typename TInputImage, typename TOutputImage, typename TMaskImage>
@@ -184,7 +203,7 @@ AttenuationImageFilter<TInputImage, TOutputImage, TMaskImage>::ThreadedGenerateD
184
203
target[m_Direction] = start[m_Direction] + m_FixedEstimationDepth;
185
204
}
186
205
187
- float estimatedAttenuation = ComputeAttenuation (target, start);
206
+ float estimatedAttenuation = ComputeAttenuation (target, start);
188
207
189
208
// Update the corresponding pixel in the metric image
190
209
if (estimatedAttenuation > 0.0 || m_ConsiderNegativeAttenuations)
@@ -219,34 +238,22 @@ typename AttenuationImageFilter<TInputImage, TOutputImage, TMaskImage>::OutputPi
219
238
AttenuationImageFilter<TInputImage, TOutputImage, TMaskImage>::ComputeAttenuation(const InputIndexType & end,
220
239
const InputIndexType & start) const
221
240
{
222
- const float nyquistFrequency = m_SamplingFrequencyMHz / 2 ;
223
-
224
- // Number and width of RF spectra frequency bins over the range (0, nyquist_frequency]
225
- const unsigned int numComponents = this ->GetInput ()->GetNumberOfComponentsPerPixel ();
226
- const float frequencyDelta = nyquistFrequency / numComponents;
227
-
228
- // Frequency band to consider for attenuation
229
- const unsigned int startComponent = m_FrequencyBandStartMHz / frequencyDelta;
230
- const unsigned int endComponent = m_FrequencyBandEndMHz / frequencyDelta;
231
- const unsigned int consideredComponents = endComponent - startComponent + 1 ;
232
-
233
241
// Get RF spectra frequency bins at start and end pixel positions
234
242
auto input = this ->GetInput ();
235
243
InputPixelType endSample = input->GetPixel (end);
236
244
InputPixelType startSample = input->GetPixel (start);
237
245
238
246
// Get distance between start and end pixel positions (assume mm units)
239
- const float scanStepMM = input->GetSpacing ()[m_Direction];
240
247
const unsigned int pixelDistance = end[m_Direction] - start[m_Direction];
241
- float distanceMM = pixelDistance * scanStepMM ;
248
+ float distanceMM = pixelDistance * m_ScanStepMM ;
242
249
243
- Eigen::Matrix<float , Eigen::Dynamic, 2 > A (consideredComponents , 2 );
244
- Eigen::Matrix<float , Eigen::Dynamic, 1 > b (consideredComponents );
245
- for (unsigned i = 0 ; i < consideredComponents ; i++)
250
+ Eigen::Matrix<float , Eigen::Dynamic, 2 > A (m_ConsideredComponents , 2 );
251
+ Eigen::Matrix<float , Eigen::Dynamic, 1 > b (m_ConsideredComponents );
252
+ for (unsigned i = 0 ; i < m_ConsideredComponents ; i++)
246
253
{
247
254
A (i, 0 ) = 1 ;
248
- A (i, 1 ) = (1 + i + startComponent ) * frequencyDelta ; // x_i = frequency
249
- b (i) = endSample[i + startComponent ] / (startSample[i + startComponent ] + itk::Math::eps); // y_i = ratio
255
+ A (i, 1 ) = (1 + i + m_StartComponent ) * m_FrequencyDelta ; // x_i = frequency
256
+ b (i) = endSample[i + m_StartComponent ] / (startSample[i + m_StartComponent ] + itk::Math::eps); // y_i = ratio
250
257
}
251
258
252
259
// from https://eigen.tuxfamily.org/dox/group__LeastSquares.html
0 commit comments