ITK  5.2.0
Insight Toolkit
SphinxExamples/src/Filtering/ImageIntensity/ComputeEdgePotential/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.
*
*=========================================================================*/
#include "itkImage.h"
using UnsignedCharImageType = itk::Image<unsigned char, 2>;
static void
CreateImage(UnsignedCharImageType::Pointer image);
int
main(int /*argc*/, char * /*argv*/[])
{
// Setup types
using FloatImageType = itk::Image<float, 2>;
using VectorImageType = itk::Image<itk::CovariantVector<float, 2>, 2>;
UnsignedCharImageType::Pointer image = UnsignedCharImageType::New();
CreateImage(image);
// Create and setup a gradient filter
GradientFilterType::Pointer gradientFilter = GradientFilterType::New();
gradientFilter->SetInput(image);
gradientFilter->Update();
// Create and setup an edge potential filter
EdgePotentialImageFilterType::Pointer edgePotentialImageFilter = EdgePotentialImageFilterType::New();
edgePotentialImageFilter->SetInput(gradientFilter->GetOutput());
edgePotentialImageFilter->Update();
// Scale so we can write to a PNG
RescaleFilterType::Pointer rescaleFilter = RescaleFilterType::New();
rescaleFilter->SetInput(edgePotentialImageFilter->GetOutput());
rescaleFilter->SetOutputMinimum(0);
rescaleFilter->SetOutputMaximum(255);
rescaleFilter->Update();
FileWriterType::Pointer writer = FileWriterType::New();
writer->SetFileName("output.png");
writer->SetInput(rescaleFilter->GetOutput());
writer->Update();
return EXIT_SUCCESS;
}
void
CreateImage(UnsignedCharImageType::Pointer image)
{
// Create a black image with 2 white regions
start.Fill(0);
size.Fill(200);
UnsignedCharImageType::RegionType region(start, size);
image->SetRegions(region);
image->Allocate();
image->FillBuffer(0);
// Make a square
for (unsigned int r = 20; r < 80; r++)
{
for (unsigned int c = 30; c < 100; c++)
{
pixelIndex[0] = r;
pixelIndex[1] = c;
image->SetPixel(pixelIndex, 255);
}
}
}
itkCovariantVector.h
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itkImage.h
itk::Index::Fill
void Fill(IndexValueType value)
Definition: itkIndex.h:270
itk::Size::Fill
void Fill(SizeValueType value)
Definition: itkSize.h:211
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::ImageFileWriter
Writes image data to a single file.
Definition: itkImageFileWriter.h:87
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itkRescaleIntensityImageFilter.h
itk::GradientImageFilter
Computes the gradient of an image using directional derivatives.
Definition: itkGradientImageFilter.h:66
itkImageFileWriter.h
itk::EdgePotentialImageFilter
Computes the edge potential of an image from the image gradient.
Definition: itkEdgePotentialImageFilter.h:69
itkGradientImageFilter.h
itkEdgePotentialImageFilter.h
itk::RescaleIntensityImageFilter
Applies a linear transformation to the intensity levels of the input Image.
Definition: itkRescaleIntensityImageFilter.h:154
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:86