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"
25#include "itkPointSet.h"
26#include "itkVector.h"
27
28#include "vnl/vnl_vector.h"
29
30namespace itk
31{
32
84
85template <typename TInputImage,
87 class TOutputImage = TInputImage>
88class ITK_TEMPLATE_EXPORT N4BiasFieldCorrectionImageFilter : public ImageToImageFilter<TInputImage, TOutputImage>
89{
90public:
91 ITK_DISALLOW_COPY_AND_MOVE(N4BiasFieldCorrectionImageFilter);
92
98
100 itkOverrideGetNameOfClassMacro(N4BiasFieldCorrectionImageFilter);
101
103 itkNewMacro(Self);
104
106 static constexpr unsigned int ImageDimension = TInputImage::ImageDimension;
107
109 using InputImageType = TInputImage;
110 using OutputImageType = TOutputImage;
111 using MaskImageType = TMaskImage;
112 using MaskPixelType = typename MaskImageType::PixelType;
113
114 using RealType = float;
118
125
130
132 void
134
138 void
140 {
141 this->SetInput(image);
142 }
143
150 void
152 {
153 this->SetMaskImage(mask);
154 }
155
156
163
172 itkSetMacro(MaskLabel, MaskPixelType);
173 itkGetConstMacro(MaskLabel, MaskPixelType);
175
179 itkSetMacro(UseMaskLabel, bool);
180 itkGetConstMacro(UseMaskLabel, bool);
181 itkBooleanMacro(UseMaskLabel);
183
195 void
197 {
198 this->SetConfidenceImage(image);
199 }
200
201
213
214 // Sharpen histogram parameters: in estimating the bias field, the
215 // first step is to sharpen the intensity histogram by Wiener deconvolution
216 // with a 1-D Gaussian. The following parameters define this operation.
217 // These default values in N4 match the default values in N3.
218
223 itkSetMacro(NumberOfHistogramBins, unsigned int);
224
229 itkGetConstMacro(NumberOfHistogramBins, unsigned int);
230
234 itkSetMacro(WienerFilterNoise, RealType);
235
239 itkGetConstMacro(WienerFilterNoise, RealType);
240
245 itkSetMacro(BiasFieldFullWidthAtHalfMaximum, RealType);
246
251 itkGetConstMacro(BiasFieldFullWidthAtHalfMaximum, RealType);
252
253 // B-spline parameters governing the fitting routine
254
258 itkSetMacro(SplineOrder, unsigned int);
259
263 itkGetConstMacro(SplineOrder, unsigned int);
264
272 itkSetMacro(NumberOfControlPoints, ArrayType);
273
281 itkGetConstMacro(NumberOfControlPoints, ArrayType);
282
289 itkSetMacro(NumberOfFittingLevels, ArrayType);
290
297 void
299 {
300 auto nlevels = MakeFilled<ArrayType>(n);
301 this->SetNumberOfFittingLevels(nlevels);
302 }
303
304
311 itkGetConstMacro(NumberOfFittingLevels, ArrayType);
312
317 itkSetMacro(MaximumNumberOfIterations, VariableSizeArrayType);
318
323 itkGetConstMacro(MaximumNumberOfIterations, VariableSizeArrayType);
324
332 itkSetMacro(ConvergenceThreshold, RealType);
333
341 itkGetConstMacro(ConvergenceThreshold, RealType);
342
352 itkGetConstObjectMacro(LogBiasFieldControlPointLattice, BiasFieldControlPointLatticeType);
353
358 itkGetConstMacro(ElapsedIterations, unsigned int);
359
364 itkGetConstMacro(CurrentConvergenceMeasurement, RealType);
365
370 itkGetConstMacro(CurrentLevel, unsigned int);
371
377
378protected:
381 void
382 PrintSelf(std::ostream & os, Indent indent) const override;
383
384 void
385 GenerateData() override;
386
387private:
388 // N4 algorithm functions: The basic algorithm iterates between sharpening
389 // the intensity histogram of the corrected input image and spatially
390 // smoothing those results with a B-spline scalar field estimate of the
391 // bias field. The former is handled by the function SharpenImage()
392 // whereas the latter is handled by the function UpdateBiasFieldEstimate().
393 // Convergence is determined by the coefficient of variation of the difference
394 // image between the current bias field estimate and the previous estimate.
395
401 void
402 SharpenImage(const RealImageType * unsharpenedImage, RealImageType * sharpenedImage) const;
403
411
418
420 bool m_UseMaskLabel{ false };
421
422 // Parameters for deconvolution with Wiener filter
423
424 unsigned int m_NumberOfHistogramBins{ 200 };
425 RealType m_WienerFilterNoise{ static_cast<RealType>(0.01) };
427
428 // Convergence parameters
429
431 unsigned int m_ElapsedIterations{ 0 };
434 unsigned int m_CurrentLevel{ 0 };
435
436 // B-spline fitting parameters
437
438 typename BiasFieldControlPointLatticeType::Pointer m_LogBiasFieldControlPointLattice{};
439
440 unsigned int m_SplineOrder{ 3 };
443};
444
445} // end namespace itk
446
447#ifndef ITK_MANUAL_INSTANTIATION
448# include "itkN4BiasFieldCorrectionImageFilter.hxx"
449#endif
450
451#endif
Array class with size defined at construction time.
Definition itkArray.h:48
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:50
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
BiasFieldControlPointLatticeType::Pointer m_LogBiasFieldControlPointLattice
void PrintSelf(std::ostream &os, Indent indent) const override
itkSetInputMacro(ConfidenceImage, RealImageType)
void EnlargeOutputRequestedRegion(DataObject *) override
RealImagePointer UpdateBiasFieldEstimate(RealImageType *, vcl_size_t)
typename BSplineFilterType::PointDataImageType BiasFieldControlPointLatticeType
RealImagePointer ReconstructBiasField(const BiasFieldControlPointLatticeType *)
~N4BiasFieldCorrectionImageFilter() override=default
ImageToImageFilter< TInputImage, TOutputImage > Superclass
RealType CalculateConvergenceMeasurement(const RealImageType *, const RealImageType *) const
PointSet< ScalarType, Self::ImageDimension > PointSetType
A superclass of the N-dimensional mesh structure; supports point (geometric coordinate and attribute)...
Definition itkPointSet.h:82
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)