ITK/Examples/VectorImages/VectorImageToImageAdaptor: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
(Created page with "==VectorImageToImageAdaptor.cxx== <source lang="cpp"> #include "itkVectorImage.h" #include "itkImage.h" #include "itkVectorImageToImageAdaptor.h" #include "itkImageRegionIterator...")
 
(Deprecated content that is moved to sphinxe)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==VectorImageToImageAdaptor.cxx==
{{warning|1=The media wiki content on this page is no longer maintained. The examples presented on the https://itk.org/Wiki/*  pages likely require ITK version 4.13 or earlier releasesIn many cases, the examples on this page no longer conform to the best practices for modern ITK versions.
<source lang="cpp">
}}
#include "itkVectorImage.h"
#include "itkImage.h"
#include "itkVectorImageToImageAdaptor.h"
#include "itkImageRegionIterator.h"
 
typedef itk::Image<float, 2> ScalarImageType;
typedef itk::VectorImage<float, 2> VectorImageType;
 
void CreateImage(VectorImageType::Pointer image);
 
int main(int, char *[])
{
  VectorImageType::Pointer image = VectorImageType::New();
  CreateImage(image);
 
  typedef itk::VectorImageToImageAdaptor<float, 2> ImageAdaptorType;
  ImageAdaptorType::Pointer adaptor = ImageAdaptorType::New();
  adaptor->SetExtractComponentIndex(0);
  adaptor->SetImage(image);
 
  itk::Index<2> index;
  index[0] = 0;
  index[1] = 0;
 
  std::cout << adaptor->GetPixel(index) << std::endl;
 
  return EXIT_SUCCESS;
}
 
void CreateImage(VectorImageType::Pointer image)
{
  VectorImageType::IndexType start;
  start.Fill(0);
 
  VectorImageType::SizeType size;
  size.Fill(2);
 
  VectorImageType::RegionType region;
  region.SetSize(size);
  region.SetIndex(start);
 
  image->SetRegions(region);
  image->SetNumberOfComponentsPerPixel(2);
  image->Allocate();
 
  typedef itk::VariableLengthVector<double> VariableVectorType;
  VariableVectorType variableLengthVector;
  variableLengthVector.SetSize(2);
 
   itk::ImageRegionIterator<VectorImageType> imageIterator(image,image->GetLargestPossibleRegion());
  variableLengthVector[0] = 1;
  variableLengthVector[1] = 2;
 
  while(!imageIterator.IsAtEnd())
    {
    imageIterator.Set(variableLengthVector);
 
    ++imageIterator;
    }
}
</source>
{{ITKCMakeLists|VectorImageToImageAdaptor}}

Latest revision as of 21:16, 5 June 2019

Warning: The media wiki content on this page is no longer maintained. The examples presented on the https://itk.org/Wiki/* pages likely require ITK version 4.13 or earlier releases. In many cases, the examples on this page no longer conform to the best practices for modern ITK versions.