ITK  5.4.0
Insight Toolkit
SphinxExamples/src/Core/ImageFunction/MultiplyKernelWithAnImageAtLocation/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"
using UnsignedCharImageType = itk::Image<unsigned char, 2>;
static void
CreateImage(UnsignedCharImageType::Pointer image);
int
main()
{
CreateImage(image);
neighborhood.SetRadius(1);
for (unsigned int i = 0; i < neighborhood.GetSize()[0] * neighborhood.GetSize()[1]; ++i)
{
neighborhood[i] = 1;
}
using NeighborhoodOperatorImageFunctionType = itk::NeighborhoodOperatorImageFunction<UnsignedCharImageType, float>;
NeighborhoodOperatorImageFunctionType::Pointer neighborhoodOperatorImageFunction =
neighborhoodOperatorImageFunction->SetOperator(neighborhood);
neighborhoodOperatorImageFunction->SetInputImage(image);
{
index.Fill(20);
float output = neighborhoodOperatorImageFunction->EvaluateAtIndex(index);
std::cout << "Sum on border: " << output << std::endl;
}
{
index.Fill(35);
float output = neighborhoodOperatorImageFunction->EvaluateAtIndex(index);
std::cout << "Sum in center: " << output << std::endl;
}
{
index.Fill(7);
float output = neighborhoodOperatorImageFunction->EvaluateAtIndex(index);
std::cout << "Sum outside: " << output << std::endl;
}
return EXIT_SUCCESS;
}
void
{
// Create an image with 2 connected components
start.Fill(0);
size.Fill(100);
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 = 20; c < 80; ++c)
{
pixelIndex[0] = r;
pixelIndex[1] = c;
image->SetPixel(pixelIndex, 1);
}
}
}
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::Index
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:70
itkNeighborhoodOperator.h
itk::Neighborhood
A light-weight container object for storing an N-dimensional neighborhood of values.
Definition: itkNeighborhood.h:54
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itkImage.h
itk::Neighborhood::GetSize
SizeValueType GetSize(DimensionValueType n) const
Definition: itkNeighborhood.h:145
itk::Index::Fill
void Fill(IndexValueType value)
Definition: itkIndex.h:274
itk::Size::Fill
void Fill(SizeValueType value)
Definition: itkSize.h:213
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::Neighborhood::SetRadius
void SetRadius(const SizeType &)
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::NeighborhoodOperatorImageFunction
Compute the convolution of a neighborhood operator with the image at a specific location in space,...
Definition: itkNeighborhoodOperatorImageFunction.h:41
itkNeighborhoodOperatorImageFunction.h
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:88
New
static Pointer New()