ITK  5.4.0
Insight Toolkit
SphinxExamples/src/Core/Common/WatchAFilter/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"
template <class TImage>
void
CreateImage(typename TImage::Pointer image)
{
using ImageType = TImage;
// Create an image with 2 connected components
typename ImageType::RegionType region;
typename ImageType::IndexType start;
start.Fill(0);
typename ImageType::SizeType size;
size.Fill(100);
region.SetSize(size);
region.SetIndex(start);
image->SetRegions(region);
image->Allocate();
itk::ImageRegionIterator<ImageType> imageIterator(image, region);
while (!imageIterator.IsAtEnd())
{
imageIterator.Set(255);
++imageIterator;
}
}
int
main()
{
constexpr unsigned int Dimension = 2;
using PixelType = unsigned char;
auto image = ImageType::New();
CreateImage<ImageType>(image);
using ThresholdImageFilterType = itk::ThresholdImageFilter<ImageType>;
auto thresholdFilter = ThresholdImageFilterType::New();
thresholdFilter->SetInput(image);
thresholdFilter->ThresholdBelow(100);
thresholdFilter->SetOutsideValue(0);
itk::SimpleFilterWatcher watcher(thresholdFilter, "ThresholdFilter");
thresholdFilter->Update();
return EXIT_SUCCESS;
}
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itkImage.h
itkImageRegionIterator.h
itkThresholdImageFilter.h
itk::Index::Fill
void Fill(IndexValueType value)
Definition: itkIndex.h:274
itk::Size::Fill
void Fill(SizeValueType value)
Definition: itkSize.h:213
itk::SimpleFilterWatcher
Simple mechanism for monitoring the pipeline events of a filter and reporting these events to std::co...
Definition: itkSimpleFilterWatcher.h:68
itk::ImageConstIterator::IsAtEnd
bool IsAtEnd() const
Definition: itkImageConstIterator.h:377
itk::ImageRegionIterator
A multi-dimensional iterator templated over image type that walks a region of pixels.
Definition: itkImageRegionIterator.h:80
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::ThresholdImageFilter
Set image values to a user-specified value if they are below, above, or outside threshold values.
Definition: itkThresholdImageFilter.h:71
itk::ImageRegionIterator::Set
void Set(const PixelType &value) const
Definition: itkImageRegionIterator.h:116
itkSimpleFilterWatcher.h
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