ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkN4BiasFieldCorrectionImageFilter.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef itkN4BiasFieldCorrectionImageFilter_h
19#define itkN4BiasFieldCorrectionImageFilter_h
20
22
23#include "itkArray.h"
26#include "itkPointSet.h"
27#include "itkVector.h"
28
29#include <vector>
30
31#include "vnl/vnl_vector.h"
32
33namespace itk
34{
35
87
88template <typename TInputImage,
90 class TOutputImage = TInputImage>
91class ITK_TEMPLATE_EXPORT N4BiasFieldCorrectionImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
92{
93public:
94 ITK_DISALLOW_COPY_AND_MOVE(N4BiasFieldCorrectionImageFilter);
95
101
103 itkOverrideGetNameOfClassMacro(N4BiasFieldCorrectionImageFilter);
104
106 itkNewMacro(Self);
107
109 static constexpr unsigned int ImageDimension = TInputImage::ImageDimension;
110
112 using InputImageType = TInputImage;
113 using OutputImageType = TOutputImage;
114 using MaskImageType = TMaskImage;
115 using MaskPixelType = typename MaskImageType::PixelType;
116
117 using RealType = float;
121
128
133
135 void
137
141 void
143 {
144 this->SetInput(image);
145 }
146
154 void
156 {
157 this->SetMaskImage(mask);
158 }
159
160
167
177 itkSetMacro(MaskLabel, MaskPixelType);
178 itkGetConstMacro(MaskLabel, MaskPixelType);
180
185 itkSetMacro(UseMaskLabel, bool);
186 itkGetConstMacro(UseMaskLabel, bool);
187 itkBooleanMacro(UseMaskLabel);
189
202 void
204 {
205 this->SetConfidenceImage(image);
206 }
207
208
220
221 // Sharpen histogram parameters: in estimating the bias field, the
222 // first step is to sharpen the intensity histogram by Wiener deconvolution
223 // with a 1-D Gaussian. The following parameters define this operation.
224 // These default values in N4 match the default values in N3.
225
230 itkSetMacro(NumberOfHistogramBins, unsigned int);
231
236 itkGetConstMacro(NumberOfHistogramBins, unsigned int);
237
241 itkSetMacro(WienerFilterNoise, RealType);
242
246 itkGetConstMacro(WienerFilterNoise, RealType);
247
252 itkSetMacro(BiasFieldFullWidthAtHalfMaximum, RealType);
253
258 itkGetConstMacro(BiasFieldFullWidthAtHalfMaximum, RealType);
259
260 // B-spline parameters governing the fitting routine
261
265 itkSetMacro(SplineOrder, unsigned int);
266
270 itkGetConstMacro(SplineOrder, unsigned int);
271
279 itkSetMacro(NumberOfControlPoints, ArrayType);
280
288 itkGetConstMacro(NumberOfControlPoints, ArrayType);
289
296 itkSetMacro(NumberOfFittingLevels, ArrayType);
297
304 void
306 {
307 auto nlevels = MakeFilled<ArrayType>(n);
308 this->SetNumberOfFittingLevels(nlevels);
309 }
310
317 itkGetConstMacro(NumberOfFittingLevels, ArrayType);
318
323 itkSetMacro(MaximumNumberOfIterations, VariableSizeArrayType);
324
329 itkGetConstMacro(MaximumNumberOfIterations, VariableSizeArrayType);
330
338 itkSetMacro(ConvergenceThreshold, RealType);
339
347 itkGetConstMacro(ConvergenceThreshold, RealType);
348
358 itkGetConstObjectMacro(LogBiasFieldControlPointLattice, BiasFieldControlPointLatticeType);
359
364 itkGetConstMacro(ElapsedIterations, unsigned int);
365
370 itkGetConstMacro(CurrentConvergenceMeasurement, RealType);
371
376 itkGetConstMacro(CurrentLevel, unsigned int);
377
383
384protected:
387 void
388 PrintSelf(std::ostream & os, Indent indent) const override;
389
390 void
391 GenerateData() override;
392
393private:
394 // N4 algorithm functions: The basic algorithm iterates between sharpening
395 // the intensity histogram of the corrected input image and spatially
396 // smoothing those results with a B-spline scalar field estimate of the
397 // bias field. The former is handled by the function SharpenImage()
398 // whereas the latter is handled by the function UpdateBiasFieldEstimate().
399 // Convergence is determined by the coefficient of variation of the difference
400 // image between the current bias field estimate and the previous estimate.
401
407 void
408 SharpenImage(const RealImageType * unsharpenedImage, RealImageType * sharpenedImage) const;
409
418
424 void
426
428 void
430
432
436
443
445 bool m_UseMaskLabel{ false };
446
447 // Parameters for deconvolution with Wiener filter
448
449 unsigned int m_NumberOfHistogramBins{ 200 };
450 RealType m_WienerFilterNoise{ static_cast<RealType>(0.01) };
452
453 // Convergence parameters
454
456 unsigned int m_ElapsedIterations{ 0 };
459 unsigned int m_CurrentLevel{ 0 };
460
461 // B-spline fitting parameters
462
463 typename BiasFieldControlPointLatticeType::Pointer m_LogBiasFieldControlPointLattice{};
464
465 unsigned int m_SplineOrder{ 3 };
468};
469
470} // end namespace itk
471
472#ifndef ITK_MANUAL_INSTANTIATION
473# include "itkN4BiasFieldCorrectionImageFilter.hxx"
474#endif
475
476#endif
Array class with size defined at construction time.
Definition itkArray.h:48
Process a given a B-spline grid of control points.
Image filter which provides a B-spline output approximation.
Base class for all data objects in ITK.
virtual void SetInput(const InputImageType *input)
Templated n-dimensional image class.
Definition itkImage.h:89
Control indentation during Print() invocation.
Definition itkIndent.h:53
itkGetInputMacro(ConfidenceImage, RealImageType)
virtual void SetNumberOfFittingLevels(ArrayType _arg)
Image< ScalarType, Self::ImageDimension > ScalarImageType
void SharpenImage(const RealImageType *unsharpenedImage, RealImageType *sharpenedImage) const
itkGetInputMacro(MaskImage, MaskImageType)
itkSetInputMacro(MaskImage, MaskImageType)
BSplineScatteredDataPointSetToImageFilter< PointSetType, ScalarImageType > BSplineFilterType
BSplineControlPointImageFilter< BiasFieldControlPointLatticeType, ScalarImageType > BiasFieldReconstructerType
BiasFieldControlPointLatticeType::Pointer m_LogBiasFieldControlPointLattice
void PrintSelf(std::ostream &os, Indent indent) const override
void ReconstructBiasFieldInto(const BiasFieldControlPointLatticeType *, RealImageType *)
itkSetInputMacro(ConfidenceImage, RealImageType)
void EnlargeOutputRequestedRegion(DataObject *) override
BiasFieldReconstructerType::Pointer MakeBiasFieldReconstructer(const BiasFieldControlPointLatticeType *) const
typename BSplineFilterType::PointDataImageType BiasFieldControlPointLatticeType
RealImagePointer ReconstructBiasField(const BiasFieldControlPointLatticeType *)
~N4BiasFieldCorrectionImageFilter() override=default
void UpdateBiasFieldEstimate(RealImageType *, FitPoints &, RealImageType *)
ImageToImageFilter< TInputImage, TOutputImage > Superclass
RealType CalculateConvergenceMeasurement(const RealImageType *, const RealImageType *) const
PointSet< ScalarType, Self::ImageDimension > PointSetType
typename PointsContainer::Pointer PointsContainerPointer
A superclass of the N-dimensional mesh structure; supports point (geometric coordinate and attribute)...
Definition itkPointSet.h:82
typename PointDataContainer::Pointer PointDataContainerPointer
Implements transparent reference counting.
A templated class holding a n-Dimensional vector.
Definition itkVector.h:63
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
constexpr TContainer MakeFilled(typename TContainer::const_reference value)
BSplineFilterType::WeightsContainerType::Pointer weights