ITK  6.0.0
Insight Toolkit
SphinxExamples/src/Bridge/VtkGlue/VisualizeStaticMalcolm2DLevelSetLayers/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 "itkVTKVisualize2DSparseLevelSetLayers.h"
#include "vtkRenderWindowInteractor.h"
int
main(int argc, char * argv[])
{
if (argc != 3)
{
std::cerr << "Missing Arguments" << std::endl;
std::cerr << argv[0] << std::endl;
std::cerr << "<Input Image> <Interactive (0 or 1)>" << std::endl;
return EXIT_FAILURE;
}
// Image Dimension
constexpr unsigned int Dimension = 2;
using InputPixelType = unsigned char;
using InputImageType = itk::Image<InputPixelType, Dimension>;
InputImageType::Pointer input = itk::ReadImage<InputImageType>(argv[1]);
// Generate a binary mask that will be used as initialization for the level
// set evolution.
auto otsu = OtsuFilterType::New();
otsu->SetInput(input);
otsu->SetNumberOfHistogramBins(256);
otsu->SetNumberOfThresholds(1);
auto rescaler = RescaleType::New();
rescaler->SetInput(otsu->GetOutput());
rescaler->SetOutputMinimum(0);
rescaler->SetOutputMaximum(1);
// convert a binary mask to a level-set function
adaptor->SetInputImage(rescaler->GetOutput());
adaptor->Initialize();
LevelSetType::Pointer levelSet = adaptor->GetModifiableLevelSet();
// Create the visualizer
using VisualizationType = itk::VTKVisualize2DSparseLevelSetLayers<InputImageType, LevelSetType>;
auto visualizer = VisualizationType::New();
visualizer->SetInputImage(input);
visualizer->SetLevelSet(levelSet);
visualizer->SetScreenCapture(true);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(visualizer->GetRenderWindow());
try
{
visualizer->Update();
}
catch (const itk::ExceptionObject & error)
{
std::cerr << "Error: " << error << std::endl;
return EXIT_FAILURE;
}
bool interactive = (std::stoi(argv[2]) != 0);
if (interactive)
{
renderWindowInteractor->Start();
}
return EXIT_SUCCESS;
}
itk::BinaryImageToLevelSetImageAdaptor
Converts one binary image to the appropriate level-set type provided by the template argument TLevelS...
Definition: itkBinaryImageToLevelSetImageAdaptor.h:51
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itkBinaryImageToLevelSetImageAdaptor.h
itkImageFileReader.h
itk::OtsuMultipleThresholdsImageFilter
Threshold an image using multiple Otsu Thresholds.
Definition: itkOtsuMultipleThresholdsImageFilter.h:61
itkMalcolmSparseLevelSetImage.h
itkOtsuMultipleThresholdsImageFilter.h
itkRescaleIntensityImageFilter.h
itk::ExceptionObject
Standard exception handling object.
Definition: itkExceptionObject.h:50
itk::RescaleIntensityImageFilter
Applies a linear transformation to the intensity levels of the input Image.
Definition: itkRescaleIntensityImageFilter.h:133
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:88
New
static Pointer New()
itk::GTest::TypedefsAndConstructors::Dimension2::Dimension
constexpr unsigned int Dimension
Definition: itkGTestTypedefsAndConstructors.h:44
itk::MalcolmSparseLevelSetImage
Derived class for the Malcolm representation of level-set function.
Definition: itkMalcolmSparseLevelSetImage.h:41