Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "mitkBilateralFilter.h"
18 #include "mitkImageAccessByItk.h"
19 #include "mitkImageCast.h"
20 #include <itkBilateralImageFilter.h>
21 
23  : m_DomainSigma(2.0f), m_RangeSigma(50.0f), m_AutoKernel(true), m_KernelRadius(1u)
24 {
25  // default parameters DomainSigma: 2 , RangeSigma: 50, AutoKernel: true, KernelRadius: 1
26 }
27 
29 {
30 }
31 
33 {
34  mitk::Image::ConstPointer inputImage = this->GetInput(0);
35  if ((inputImage->GetDimension() > 4) || (inputImage->GetDimension() < 2))
36  {
37  MITK_ERROR << "mitk::BilateralFilter:GenerateData works only with 2D, 2D+t, 3D, 3D+t and 4D images, sorry."
38  << std::endl;
39  itkExceptionMacro("mitk::BilateralFilter:GenerateData works only with 2D, 2D+t, 3D, 3D+t and 4D images, sorry.");
40  return;
41  }
42  switch (inputImage->GetDimension())
43  {
44  case 2:
45  {
46  AccessFixedDimensionByItk(inputImage.GetPointer(), ItkImageProcessing, 2);
47  break;
48  }
49  case 3:
50  {
51  AccessFixedDimensionByItk(inputImage.GetPointer(), ItkImageProcessing, 3);
52  break;
53  }
54  case 4:
55  {
56  AccessFixedDimensionByItk(inputImage.GetPointer(), ItkImageProcessing, 4);
57  break;
58  }
59  default:
60  break;
61  }
62 }
63 
64 template <typename TPixel, unsigned int VImageDimension>
65 void mitk::BilateralFilter::ItkImageProcessing(const itk::Image<TPixel, VImageDimension> *itkImage)
66 {
67  // ITK Image type given from the input image
68  typedef itk::Image<TPixel, VImageDimension> ItkImageType;
69  // bilateral filter with same type
70  typedef itk::BilateralImageFilter<ItkImageType, ItkImageType> BilateralFilterType;
71  typename BilateralFilterType::Pointer bilateralFilter = BilateralFilterType::New();
72  bilateralFilter->SetInput(itkImage);
73  // set parameters
74  if (!m_AutoKernel)
75  {
76  bilateralFilter->SetAutomaticKernelSize(m_AutoKernel);
77  bilateralFilter->SetRadius(m_KernelRadius);
78  }
79  bilateralFilter->SetDomainSigma(m_DomainSigma);
80  bilateralFilter->SetRangeSigma(m_RangeSigma);
81  bilateralFilter->UpdateLargestPossibleRegion();
82  // get Pointer to output image
83  mitk::Image::Pointer resultImage = this->GetOutput();
84  // write into output image
85  mitk::CastToMitkImage(bilateralFilter->GetOutput(), resultImage);
86 }
87 
89 {
90  mitk::Image::Pointer inputImage = (mitk::Image *)this->GetInput();
91  mitk::Image::Pointer output = this->GetOutput();
92  itkDebugMacro(<< "GenerateOutputInformation()");
93  if (inputImage.IsNull())
94  return;
95 }
itk::SmartPointer< Self > Pointer
#define AccessFixedDimensionByItk(mitkImage, itkImageTypeFunction, dimension)
Access a mitk-image with known dimension by an itk-image.
#define MITK_ERROR
Definition: mitkLogMacros.h:24
BilateralFilter()
standard constructor
virtual void GenerateOutputInformation() override
Method generating the output information of this filter (e.g. image dimension, image type...
itk::BilateralImageFilter< ItkImageType2D, ItkImageType2D > BilateralFilterType
Image class for storing images.
Definition: mitkImage.h:76
void ItkImageProcessing(const itk::Image< TPixel, VImageDimension > *itkImage)
Internal templated method calling the ITK bilteral filter. Here the actual filtering is performed...
~BilateralFilter()
standard destructor
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:78
virtual void GenerateData() override
Method generating the output of this filter. Called in the updated process of the pipeline...
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.