ITK  6.0.0
Insight Toolkit
SphinxExamples/src/Registration/Common/MatchFeaturePoints/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"
#include "itkPoint.h"
#include "itkPointSet.h"
using ImageType = itk::Image<unsigned char, 2>;
static void
CreateImage(ImageType::Pointer image, const unsigned int x);
int
main(int /*argc*/, char * /*argv*/[])
{
// Create input images
auto fixedImage = ImageType::New();
CreateImage(fixedImage, 40);
auto movingImage = ImageType::New();
CreateImage(movingImage, 50);
// using BlockMatchingImageFilterType = itk::BlockMatchingImageFilter<ImageType, ImageType, PointSetType>;
using BlockMatchingImageFilterType = itk::BlockMatchingImageFilter<ImageType>;
auto blockMatchingImageFilter = BlockMatchingImageFilterType::New();
// Generate feature points
// using PointSetType = itk::PointSet< float, 2>;
using PointSetType = BlockMatchingImageFilterType::FeaturePointsType;
using PointsContainerPointer = PointSetType::PointsContainerPointer;
auto pointSet = PointSetType::New();
PointsContainerPointer points = pointSet->GetPoints();
PointType p0, p1, p2, p3;
p0[0] = 40.0;
p0[1] = 40.0;
p1[0] = 40.0;
p1[1] = 60.0;
p2[0] = 60.0;
p2[1] = 40.0;
p3[0] = 60.0;
p2[1] = 60.0;
points->InsertElement(0, p0);
points->InsertElement(1, p1);
points->InsertElement(2, p2);
points->InsertElement(3, p3);
blockMatchingImageFilter->SetFixedImage(fixedImage);
blockMatchingImageFilter->SetMovingImage(movingImage);
blockMatchingImageFilter->SetFeaturePoints(pointSet);
blockMatchingImageFilter->UpdateLargestPossibleRegion();
typename BlockMatchingImageFilterType::DisplacementsType * displacements =
blockMatchingImageFilter->GetDisplacements();
std::cout << "There are " << displacements->GetNumberOfPoints() << " displacements." << std::endl;
return EXIT_SUCCESS;
}
void
CreateImage(ImageType::Pointer image, const unsigned int x)
{
// Allocate empty image
start.Fill(0);
size.Fill(100);
ImageType::RegionType region(start, size);
image->SetRegions(region);
image->Allocate();
image->FillBuffer(0);
// Make a white square
for (unsigned int r = x; r < x + 20; ++r)
{
for (unsigned int c = 40; c < 60; ++c)
{
pixelIndex[0] = r;
pixelIndex[1] = c;
image->SetPixel(pixelIndex, 255);
}
}
}
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::Index
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:68
itk::Size< 2 >
itkPoint.h
itk::GTest::TypedefsAndConstructors::Dimension2::PointType
ImageBaseType::PointType PointType
Definition: itkGTestTypedefsAndConstructors.h:51
itk::BlockMatchingImageFilter
Computes displacements of given points from a fixed image in a floating image.
Definition: itkBlockMatchingImageFilter.h:80
itkImage.h
itk::Index::Fill
void Fill(IndexValueType value)
Definition: itkIndex.h:272
itk::Size::Fill
void Fill(SizeValueType value)
Definition: itkSize.h:211
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itkBlockMatchingImageFilter.h
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:88
itkPointSet.h
New
static Pointer New()