Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
Medical Imaging Interaction Toolkit
mitkBilateralFilter.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "mitkBilateralFilter.h"
14 #include "mitkImageAccessByItk.h"
15 #include "mitkImageCast.h"
16 #include <itkBilateralImageFilter.h>
17 
19  : m_DomainSigma(2.0f), m_RangeSigma(50.0f), m_AutoKernel(true), m_KernelRadius(1u)
20 {
21  // default parameters DomainSigma: 2 , RangeSigma: 50, AutoKernel: true, KernelRadius: 1
22 }
23 
25 {
26 }
27 
29 {
30  mitk::Image::ConstPointer inputImage = this->GetInput(0);
31  if ((inputImage->GetDimension() > 4) || (inputImage->GetDimension() < 2))
32  {
33  MITK_ERROR << "mitk::BilateralFilter:GenerateData works only with 2D, 2D+t, 3D, 3D+t and 4D images, sorry."
34  << std::endl;
35  itkExceptionMacro("mitk::BilateralFilter:GenerateData works only with 2D, 2D+t, 3D, 3D+t and 4D images, sorry.");
36  return;
37  }
38  switch (inputImage->GetDimension())
39  {
40  case 2:
41  {
42  AccessFixedDimensionByItk(inputImage.GetPointer(), ItkImageProcessing, 2);
43  break;
44  }
45  case 3:
46  {
47  AccessFixedDimensionByItk(inputImage.GetPointer(), ItkImageProcessing, 3);
48  break;
49  }
50  case 4:
51  {
52  AccessFixedDimensionByItk(inputImage.GetPointer(), ItkImageProcessing, 4);
53  break;
54  }
55  default:
56  break;
57  }
58 }
59 
60 template <typename TPixel, unsigned int VImageDimension>
61 void mitk::BilateralFilter::ItkImageProcessing(const itk::Image<TPixel, VImageDimension> *itkImage)
62 {
63  // ITK Image type given from the input image
64  typedef itk::Image<TPixel, VImageDimension> ItkImageType;
65  // bilateral filter with same type
66  typedef itk::BilateralImageFilter<ItkImageType, ItkImageType> BilateralFilterType;
67  typename BilateralFilterType::Pointer bilateralFilter = BilateralFilterType::New();
68  bilateralFilter->SetInput(itkImage);
69  // set parameters
70  if (!m_AutoKernel)
71  {
72  bilateralFilter->SetAutomaticKernelSize(m_AutoKernel);
73  bilateralFilter->SetRadius(m_KernelRadius);
74  }
75  bilateralFilter->SetDomainSigma(m_DomainSigma);
76  bilateralFilter->SetRangeSigma(m_RangeSigma);
77  bilateralFilter->UpdateLargestPossibleRegion();
78  // get Pointer to output image
79  mitk::Image::Pointer resultImage = this->GetOutput();
80  // write into output image
81  mitk::CastToMitkImage(bilateralFilter->GetOutput(), resultImage);
82 }
83 
85 {
86  mitk::Image::Pointer inputImage = (mitk::Image *)this->GetInput();
87  mitk::Image::Pointer output = this->GetOutput();
88  itkDebugMacro(<< "GenerateOutputInformation()");
89  if (inputImage.IsNull())
90  return;
91 }
#define AccessFixedDimensionByItk(mitkImage, itkImageTypeFunction, dimension)
Access a mitk-image with known dimension by an itk-image.
#define MITK_ERROR
Definition: mitkLogMacros.h:20
BilateralFilter()
standard constructor
void GenerateOutputInformation() override
Method generating the output information of this filter (e.g. image dimension, image type...
itk::BilateralImageFilter< ItkImageType2D, ItkImageType2D > BilateralFilterType
float m_RangeSigma
Sigma of the gaussian kernel. See ITK docu.
~BilateralFilter() override
standard destructor
Image class for storing images.
Definition: mitkImage.h:72
void ItkImageProcessing(const itk::Image< TPixel, VImageDimension > *itkImage)
Internal templated method calling the ITK bilteral filter. Here the actual filtering is performed...
InputImageType * GetInput(void)
void CastToMitkImage(const itk::SmartPointer< ItkOutputImageType > &itkimage, itk::SmartPointer< mitk::Image > &mitkoutputimage)
Cast an itk::Image (with a specific type) to an mitk::Image.
Definition: mitkImageCast.h:74
bool m_AutoKernel
Sigma of the range mask kernel. See ITK docu.
void GenerateData() override
Method generating the output of this filter. Called in the updated process of the pipeline...
OutputType * GetOutput()
Get the output data of this image source object.