ITK  5.2.0
Insight Toolkit
SphinxExamples/src/Core/Common/CustomOperationToEachPixelInImage/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 "itkVectorImage.h"
#include "itkVector.h"
#include "itkMath.h"
template <class TInput, class TOutput>
class RotateVectors
{
public:
RotateVectors() = default;
~RotateVectors() = default;
bool
operator!=(const RotateVectors &) const
{
return false;
}
bool
operator==(const RotateVectors & other) const
{
return !(*this != other);
}
inline TOutput
operator()(const TInput & A) const
{
v[0] = A[0];
v[1] = A[1];
using TransformType = itk::Rigid2DTransform<float>;
TransformType::Pointer transform = TransformType::New();
transform->SetAngle(itk::Math::pi / 2.0);
VectorType outputV = transform->TransformVector(v);
TOutput transformedVector;
transformedVector.SetSize(2);
transformedVector[0] = outputV[0];
transformedVector[1] = outputV[1];
return transformedVector;
}
};
int
main(int, char *[])
{
using ImageType = itk::VectorImage<float, 2>;
start[0] = 0;
start[1] = 0;
size[0] = 2;
size[1] = 3;
region.SetSize(size);
region.SetIndex(start);
ImageType::Pointer image = ImageType::New();
image->SetRegions(region);
image->SetVectorLength(2);
image->Allocate();
pixelIndex[0] = 1;
pixelIndex[1] = 1;
v.SetSize(2);
v[0] = 1;
v[1] = 0;
image->SetPixel(pixelIndex, v);
using FilterType =
FilterType::Pointer filter = FilterType::New();
filter->SetInput(image);
filter->Update();
ImageType::PixelType inputPixelValue = image->GetPixel(pixelIndex);
ImageType::PixelType outputPixelValue = filter->GetOutput()->GetPixel(pixelIndex);
std::cout << "pixel (1,1) was = " << inputPixelValue << std::endl;
std::cout << "pixel (1,1) now = " << outputPixelValue << std::endl;
return EXIT_SUCCESS;
}
itkUnaryFunctorImageFilter.h
itkRigid2DTransform.h
itk::UnaryFunctorImageFilter
Implements pixel-wise generic operation on one image.
Definition: itkUnaryFunctorImageFilter.h:50
itk::ImageToImageFilterDetail::operator!=
bool operator!=(const ImageRegionCopier< D1, D2 > &c1, const ImageRegionCopier< D1, D2 > &c2)
Definition: itkImageToImageFilterDetail.h:355
itkVariableLengthVector.h
itk::GTest::TypedefsAndConstructors::Dimension2::VectorType
ImageBaseType::SpacingType VectorType
Definition: itkGTestTypedefsAndConstructors.h:53
itk::VectorImage
Templated n-dimensional vector image class.
Definition: itkImageAlgorithm.h:29
itk::Vector
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itkVectorImage.h
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::Rigid2DTransform
Rigid2DTransform of a vector space (e.g. space coordinates)
Definition: itkRigid2DTransform.h:56
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itk::operator==
bool operator==(const Index< VDimension > &one, const Index< VDimension > &two)
Definition: itkIndex.h:532
itk::VariableLengthVector
Represents an array whose length can be defined at run-time.
Definition: itkConstantBoundaryCondition.h:28
itk::Size::SetSize
void SetSize(const SizeValueType val[VDimension])
Definition: itkSize.h:179
itkVector.h
itk::Math::pi
static constexpr double pi
Definition: itkMath.h:64
itkMath.h