ITK  5.1.0
Insight Toolkit
SphinxExamples/src/Filtering/CurvatureFlow/SmoothImageUsingCurvatureFlow/Code.cxx
/*=========================================================================
*
* Copyright Insight Software Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#include "itkImage.h"
#ifdef ENABLE_QUICKVIEW
# include "QuickView.h"
#endif
int
main(int argc, char * argv[])
{
if (argc < 2)
{
std::cerr << "Usage: " << argv[0];
std::cerr << " inputImage [iterations]" << std::endl;
return EXIT_FAILURE;
}
int iterations = 5;
if (argc > 2)
{
iterations = std::stoi(argv[2]);
}
using InternalPixelType = float;
constexpr unsigned int Dimension = 2;
using InternalImageType = itk::Image<InternalPixelType, Dimension>;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(argv[1]);
CurvatureFlowImageFilterType::Pointer smoothing = CurvatureFlowImageFilterType::New();
smoothing->SetInput(reader->GetOutput());
smoothing->SetNumberOfIterations(iterations);
smoothing->SetTimeStep(0.125);
using SubtractImageFilterType = itk::SubtractImageFilter<InternalImageType>;
SubtractImageFilterType::Pointer diff = SubtractImageFilterType::New();
diff->SetInput1(reader->GetOutput());
diff->SetInput2(smoothing->GetOutput());
#ifdef ENABLE_QUICKVIEW
QuickView viewer;
viewer.AddImage<InternalImageType>(reader->GetOutput(), true, itksys::SystemTools::GetFilenameName(argv[1]));
std::stringstream desc;
desc << "CurvatureFlow\niterations = " << iterations;
viewer.AddImage<InternalImageType>(smoothing->GetOutput(), true, desc.str());
std::stringstream desc2;
desc2 << "Original - CurvatureFlow";
viewer.AddImage<InternalImageType>(diff->GetOutput(), true, desc2.str());
viewer.Visualize();
#endif
return EXIT_SUCCESS;
}
itk::CurvatureFlowImageFilter
Denoise an image using curvature driven flow.
Definition: itkCurvatureFlowImageFilter.h:95
itkImageFileReader.h
itkImage.h
itkCastImageFilter.h
itk::ImageFileReader
Data source that reads image data from a single file.
Definition: itkImageFileReader.h:75
QuickView.h
QuickView::AddImage
void AddImage(TImage *, bool FlipVertical=true, std::string Description="")
itkCurvatureFlowImageFilter.h
itkSubtractImageFilter.h
itk::SubtractImageFilter
Pixel-wise subtraction of two images.
Definition: itkSubtractImageFilter.h:67
QuickView
A convenient class to render itk images with vtk.
Definition: QuickView.h:107
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:86
QuickView::Visualize
void Visualize(bool interact=true)
itk::GTest::TypedefsAndConstructors::Dimension2::Dimension
constexpr unsigned int Dimension
Definition: itkGTestTypedefsAndConstructors.h:44