1 /*===================================================================
3 The Medical Imaging Interaction Toolkit (MITK)
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 See LICENSE.txt or http://www.mitk.org for details.
15 ===================================================================*/
17 /*===================================================================
19 This file is based heavily on a corresponding ITK filter.
21 ===================================================================*/
22 #ifndef _itkTotalVariationDenoisingImageFilter_txx
23 #define _itkTotalVariationDenoisingImageFilter_txx
24 #include "itkTotalVariationDenoisingImageFilter.h"
26 #include "itkConstShapedNeighborhoodIterator.h"
27 #include "itkImageRegionConstIterator.h"
28 #include "itkImageRegionIterator.h"
29 #include "itkLocalVariationImageFilter.h"
30 #include "itkNeighborhoodAlgorithm.h"
31 #include "itkNeighborhoodInnerProduct.h"
32 #include "itkOffset.h"
33 #include "itkProgressReporter.h"
34 #include "itkZeroFluxNeumannBoundaryCondition.h"
41 template <class TInputImage, class TOutputImage>
42 TotalVariationDenoisingImageFilter<TInputImage, TOutputImage>::TotalVariationDenoisingImageFilter()
47 template <class TInputImage, class TOutputImage>
48 void TotalVariationDenoisingImageFilter<TInputImage, TOutputImage>::GenerateData()
50 // first we cast the input image to match output type
51 typename CastType::Pointer infilter = CastType::New();
52 infilter->SetInput(this->GetInput());
54 typename TOutputImage::Pointer image = infilter->GetOutput();
56 // a second copy of the input image is saved as reference
57 infilter = CastType::New();
58 infilter->SetInput(this->GetInput());
60 typename TOutputImage::Pointer origImage = infilter->GetOutput();
62 typename SingleIterationFilterType::Pointer filter;
63 for (int i = 0; i < m_NumberIterations; i++)
65 filter = SingleIterationFilterType::New();
66 filter->SetInput(image);
67 filter->SetOriginalImage(origImage);
68 filter->SetLambda(m_Lambda);
69 filter->SetNumberOfThreads(this->GetNumberOfThreads());
70 filter->UpdateLargestPossibleRegion();
71 image = filter->GetOutput();
72 std::cout << "Iteration " << i + 1 << "/" << m_NumberIterations << std::endl;
75 typename OutputImageType::Pointer output = this->GetOutput();
76 output->SetSpacing(image->GetSpacing());
77 typename OutputImageType::RegionType largestPossibleRegion;
78 largestPossibleRegion.SetSize(image->GetLargestPossibleRegion().GetSize());
79 largestPossibleRegion.SetIndex(image->GetLargestPossibleRegion().GetIndex());
80 output->SetLargestPossibleRegion(image->GetLargestPossibleRegion());
81 output->SetBufferedRegion(image->GetLargestPossibleRegion());
84 itk::ImageRegionIterator<OutputImageType> oit(output, output->GetLargestPossibleRegion());
87 itk::ImageRegionConstIterator<OutputImageType> iit(image, image->GetLargestPossibleRegion());
90 while (!oit.IsAtEnd())
99 * Standard "PrintSelf" method
101 template <class TInputImage, class TOutput>
102 void TotalVariationDenoisingImageFilter<TInputImage, TOutput>::PrintSelf(std::ostream &os, Indent indent) const
104 Superclass::PrintSelf(os, indent);
107 } // end namespace itk