Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkHistogramMatching.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 "mitkHistogramMatching.h"
18 
19 #include <mitkImageCast.h>
20 
21 namespace mitk
22 {
24  {
28  }
29 
32  {
33  m_NumberOfHistogramLevels = histogrammLevels;
34  }
35 
36  void HistogramMatching::SetNumberOfMatchPoints(int matchPoints) { m_NumberOfMatchPoints = matchPoints; }
38  template <typename TPixel, unsigned int VImageDimension>
39  void HistogramMatching::GenerateData2(const itk::Image<TPixel, VImageDimension> *itkImage1)
40  {
41  typedef typename itk::Image<TPixel, VImageDimension> FixedImageType;
42  typedef typename itk::Image<TPixel, VImageDimension> MovingImageType;
43 
44  typedef float InternalPixelType;
45  typedef typename itk::Image<InternalPixelType, VImageDimension> InternalImageType;
46  typedef typename itk::CastImageFilter<FixedImageType, InternalImageType> FixedImageCasterType;
47  typedef typename itk::CastImageFilter<MovingImageType, InternalImageType> MovingImageCasterType;
48  typedef typename itk::HistogramMatchingImageFilter<InternalImageType, InternalImageType> MatchingFilterType;
49 
50  typename FixedImageType::Pointer fixedImage = FixedImageType::New();
52  typename MovingImageType::ConstPointer movingImage = itkImage1;
53  if (fixedImage.IsNotNull() && movingImage.IsNotNull())
54  {
55  typename FixedImageCasterType::Pointer fixedImageCaster = FixedImageCasterType::New();
56  fixedImageCaster->SetInput(fixedImage);
57  typename MovingImageCasterType::Pointer movingImageCaster = MovingImageCasterType::New();
58  movingImageCaster->SetInput(movingImage);
60  matcher->SetInput(movingImageCaster->GetOutput());
61  matcher->SetReferenceImage(fixedImageCaster->GetOutput());
62  matcher->SetNumberOfHistogramLevels(m_NumberOfHistogramLevels);
63  matcher->SetNumberOfMatchPoints(m_NumberOfMatchPoints);
64  matcher->SetThresholdAtMeanIntensity(m_ThresholdAtMeanIntensity);
65  matcher->Update();
66  Image::Pointer outputImage = this->GetOutput();
67  mitk::CastToMitkImage(matcher->GetOutput(), outputImage);
68  }
69  }
70 } // end namespace
void GenerateData2(const itk::Image< TPixel, VImageDimension > *itkImage1)
Template class to perform the histogram matching with any kind of image. Called by GenerateData()...
void SetNumberOfMatchPoints(int matchPoints)
Sets the number of match points for the histogram generation.
itk::SmartPointer< Self > Pointer
DataCollection - Class to facilitate loading/accessing structured data.
itk::SmartPointer< const Self > ConstPointer
void SetThresholdAtMeanIntensity(bool on)
Sets whether a threshold at mean intensity should be used for the histogram generation.
HistogramMatching()
Default constructor.
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
void MITKCORE_EXPORT CastToItkImage(const mitk::Image *mitkImage, itk::SmartPointer< ItkOutputImageType > &itkOutputImage)
Cast an mitk::Image to an itk::Image with a specific type.
OutputType * GetOutput()
Get the output data of this image source object.
virtual ~HistogramMatching()
Default destructor.
void SetNumberOfHistogramLevels(int histogrammLevels)
Sets the number of histogram levels for the histogram generation.
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.