ITK  5.3.0
Insight Toolkit
SphinxExamples/src/Filtering/MathematicalMorphology/ErodeBinaryImageUsingFlatStruct/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
*
* 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.
*
*=========================================================================*/
#ifdef ENABLE_QUICKVIEW
# include "QuickView.h"
#endif
int
main(int argc, char * argv[])
{
if (argc < 2)
{
std::cerr << argv[0] << " InputImageFile [radius]" << std::endl;
return EXIT_FAILURE;
}
unsigned int radius = 2;
if (argc > 2)
{
radius = std::stoi(argv[2]);
}
using ImageType = itk::Image<unsigned char, 2>;
using ReaderType = itk::ImageFileReader<ImageType>;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(argv[1]);
using StructuringElementType = itk::FlatStructuringElement<2>;
StructuringElementType::RadiusType elementRadius;
elementRadius.Fill(radius);
StructuringElementType structuringElement = StructuringElementType::Box(elementRadius);
BinaryErodeImageFilterType::Pointer erodeFilter = BinaryErodeImageFilterType::New();
erodeFilter->SetInput(reader->GetOutput());
erodeFilter->SetKernel(structuringElement);
erodeFilter->SetForegroundValue(255); // Intensity value to erode
erodeFilter->SetBackgroundValue(0); // Replacement value for eroded voxels
#ifdef ENABLE_QUICKVIEW
QuickView viewer;
viewer.AddImage(reader->GetOutput());
viewer.AddImage(erodeFilter->GetOutput());
viewer.Visualize();
#endif
return EXIT_SUCCESS;
}
itk::FlatStructuringElement
A class to support a variety of flat structuring elements, including versions created by decompositio...
Definition: itkKernelImageFilter.h:27
itkImageFileReader.h
itk::BinaryErodeImageFilter
Fast binary erosion of a single intensity value in the image.
Definition: itkBinaryErodeImageFilter.h:72
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="")
itkBinaryErodeImageFilter.h
itkFlatStructuringElement.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)