ITK  5.4.0
Insight Toolkit
SphinxExamples/src/Filtering/CurvatureFlow/SmoothRGBImageUsingCurvatureFlow/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 "itkRGBPixel.h"
#include <sstream>
#ifdef ENABLE_QUICKVIEW
# include "QuickView.h"
#endif
int
main(int argc, char * argv[])
{
// Verify command line arguments
if (argc < 2)
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] << " InputImageFile [iterations]" << std::endl;
return EXIT_FAILURE;
}
int iterations = 5;
if (argc > 2)
{
std::stringstream ss(argv[2]);
ss >> iterations;
}
std::string inputFileName = argv[1];
// Setup types
using ComponentType = float;
using PixelType = itk::RGBPixel<ComponentType>;
using RGBImageType = itk::Image<PixelType, 2>;
using ImageType = itk::Image<ComponentType, 2>;
const auto input = itk::ReadImage<RGBImageType>(inputFileName);
// Run the filter for each component
auto rAdaptor = ImageAdaptorType::New();
rAdaptor->SelectNthElement(0);
rAdaptor->SetImage(input);
auto rCurvatureFilter = CurvatureFlowType::New();
rCurvatureFilter->SetInput(rAdaptor);
rCurvatureFilter->SetNumberOfIterations(iterations);
rCurvatureFilter->Update();
auto gAdaptor = ImageAdaptorType::New();
gAdaptor->SelectNthElement(1);
gAdaptor->SetImage(input);
auto gCurvatureFilter = CurvatureFlowType::New();
gCurvatureFilter->SetInput(gAdaptor);
gCurvatureFilter->SetNumberOfIterations(iterations);
gCurvatureFilter->Update();
auto bAdaptor = ImageAdaptorType::New();
bAdaptor->SelectNthElement(2);
bAdaptor->SetImage(input);
auto bCurvatureFilter = CurvatureFlowType::New();
bCurvatureFilter->SetInput(bAdaptor);
bCurvatureFilter->SetNumberOfIterations(iterations);
bCurvatureFilter->Update();
// compose an RGB image from the three filtered images
auto compose = ComposeType::New();
compose->SetInput1(rCurvatureFilter->GetOutput());
compose->SetInput2(gCurvatureFilter->GetOutput());
compose->SetInput3(bCurvatureFilter->GetOutput());
#ifdef ENABLE_QUICKVIEW
QuickView viewer;
viewer.AddRGBImage(input.GetPointer(), true, itksys::SystemTools::GetFilenameName(inputFileName));
std::stringstream desc;
desc << "CurvatureFlow iterations = " << iterations;
viewer.AddRGBImage(compose->GetOutput(), true, desc.str());
viewer.Visualize();
#endif
return EXIT_SUCCESS;
}
itk::CurvatureFlowImageFilter
Denoise an image using curvature driven flow.
Definition: itkCurvatureFlowImageFilter.h:96
itk::NthElementImageAdaptor
Presents an image as being composed of the N-th element of its pixels.
Definition: itkNthElementImageAdaptor.h:58
itk::RGBPixel
Represent Red, Green and Blue components for color images.
Definition: itkRGBPixel.h:58
itkRGBPixel.h
itkNthElementImageAdaptor.h
itkComposeImageFilter.h
itkImageFileReader.h
itkImage.h
itkImageRegionIterator.h
itkImageAdaptor.h
QuickView::AddRGBImage
void AddRGBImage(TImage *, bool FlipVertical=true, std::string Description="")
QuickView.h
itkCurvatureFlowImageFilter.h
itk::ComposeImageFilter
ComposeImageFilter combine several scalar images into a multicomponent image.
Definition: itkComposeImageFilter.h:62
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)