ITK  5.4.0
Insight Toolkit
SphinxExamples/src/Filtering/AnisotropicSmoothing/SmoothImageWhilePreservingEdges2/Code.cxx
/*=========================================================================
*
* Copyright NumFOCUS
*
* 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
*
* https://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
const auto input = itk::ReadImage<RGBImageType>(inputFileName);
// 2) Cast to Vector image for processing
auto adaptInput = AdaptorInputType::New();
adaptInput->SetImage(input);
auto castInput = CastInputType::New();
castInput->SetInput(adaptInput);
// 3) Smooth the image
using VectorCurvatureAnisotropicDiffusionImageFilterType =
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
auto adaptOutput = AdaptorOutputType::New();
adaptOutput->SetImage(filter->GetOutput());
auto castOutput = CastOutputType::New();
castOutput->SetInput(adaptOutput);
// 5) Display the input and smoothed images
#ifdef ENABLE_QUICKVIEW
QuickView viewer;
viewer.AddRGBImage(input.GetPointer(), true, itksys::SystemTools::GetFilenameName(inputFileName));
std::stringstream desc;
desc << "VectorCurvatureAnisotropicDiffusionImageFilter\niterations: " << filter->GetNumberOfIterations()
<< " conductance: " << filter->GetConductanceParameter();
viewer.AddRGBImage(castOutput->GetOutput(), true, desc.str());
viewer.Visualize();
#endif
return EXIT_SUCCESS;
}
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::CastImageFilter
Casts input pixels to output pixel type.
Definition: itkCastImageFilter.h:100
itkVectorCurvatureAnisotropicDiffusionImageFilter.h
itkRGBToVectorImageAdaptor.h
itkImageFileReader.h
itkImage.h
itkCastImageFilter.h
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::VectorCurvatureAnisotropicDiffusionImageFilter
Definition: itkVectorCurvatureAnisotropicDiffusionImageFilter.h:68
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:88
New
static Pointer New()
QuickView::Visualize
void Visualize(bool interact=true)