ITK  5.1.0
Insight Toolkit
SphinxExamples/src/Filtering/AnisotropicSmoothing/SmoothImageWhilePreservingEdges/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"
#include "itksys/SystemTools.hxx"
#include <sstream>
#ifdef ENABLE_QUICKVIEW
# include "QuickView.h"
#endif
int
main(int argc, char * argv[])
{
// Verify arguments
if (argc < 2)
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0];
std::cerr << " InputFileName";
std::cerr << " [NumberOfIterations] ";
std::cerr << " [Conductance]" << std::endl;
return EXIT_FAILURE;
}
// 0) Parse arguments
std::string inputFileName = argv[1];
using FloatImageType = itk::Image<itk::Vector<float, 3>, 2>;
using RGBImageType = itk::Image<itk::RGBPixel<float>, 2>;
// 1) Read the RGB image
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(inputFileName);
// 2) Cast to Vector image for processing
AdaptorInputType::Pointer adaptInput = AdaptorInputType::New();
adaptInput->SetImage(reader->GetOutput());
CastInputType::Pointer castInput = CastInputType::New();
castInput->SetInput(adaptInput);
// 3) Smooth the image
using VectorGradientAnisotropicDiffusionImageFilterType =
VectorGradientAnisotropicDiffusionImageFilterType::Pointer filter =
VectorGradientAnisotropicDiffusionImageFilterType::New();
filter->SetInput(castInput->GetOutput());
filter->SetTimeStep(0.125);
if (argc > 2)
{
filter->SetNumberOfIterations(atoi(argv[2]));
}
if (argc > 3)
{
filter->SetConductanceParameter(atof(argv[3]));
}
// 4) Cast the Vector image to an RGB image for display
AdaptorOutputType::Pointer adaptOutput = AdaptorOutputType::New();
adaptOutput->SetImage(filter->GetOutput());
CastOutputType::Pointer castOutput = CastOutputType::New();
castOutput->SetInput(adaptOutput);
// 5) Display the input and smoothed images
#ifdef ENABLE_QUICKVIEW
QuickView viewer;
viewer.AddRGBImage(reader->GetOutput(), true, itksys::SystemTools::GetFilenameName(inputFileName));
std::stringstream desc;
desc << "VectorGradientAnisotropicDiffusionImageFilter\niterations: " << filter->GetNumberOfIterations()
<< " conductance: " << filter->GetConductanceParameter();
viewer.AddRGBImage(castOutput->GetOutput(), true, desc.str());
viewer.Visualize();
#endif
return EXIT_SUCCESS;
}
itk::CastImageFilter
Casts input pixels to output pixel type.
Definition: itkCastImageFilter.h:104
itkRGBToVectorImageAdaptor.h
itkImageFileReader.h
itkImage.h
itkVectorGradientAnisotropicDiffusionImageFilter.h
itkCastImageFilter.h
itk::ImageFileReader
Data source that reads image data from a single file.
Definition: itkImageFileReader.h:75
QuickView::AddRGBImage
void AddRGBImage(TImage *, bool FlipVertical=true, std::string Description="")
QuickView.h
itk::RGBToVectorImageAdaptor
Presents an image of pixel type RGBPixel as being and image of Vectors.
Definition: itkRGBToVectorImageAdaptor.h:36
itk::VectorGradientAnisotropicDiffusionImageFilter
Definition: itkVectorGradientAnisotropicDiffusionImageFilter.h:61
itk::VectorToRGBImageAdaptor
Presents an image of pixel type Vector as being and image of RGBPixel type.
Definition: itkVectorToRGBImageAdaptor.h:36
itkVectorToRGBImageAdaptor.h
QuickView
A convenient class to render itk images with vtk.
Definition: QuickView.h:111
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:86
QuickView::Visualize
void Visualize(bool interact=true)