ITK/Examples/VectorImages/VectorIndexSelectionCastImageFilter: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
(Procedures should be static.)
(Deprecated content that is moved to sphinxe)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
This example demonstrates how to access a specified channel of a vector image as if it were a scalar image.
{{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.
 
}}
==VectorIndexSelectionCastImageFilter.cxx==
<source lang="cpp">
#include "itkVectorImage.h"
#include "itkImageRegionIterator.h"
#include "itkMinimumMaximumImageCalculator.h"
#include "itkVectorIndexSelectionCastImageFilter.h"
 
typedef itk::VectorImage<float, 2> VectorImageType;
typedef itk::Image<float, 2> ScalarImageType;
 
static void CreateImage(VectorImageType::Pointer image);
 
int main(int, char *[])
{
  VectorImageType::Pointer image = VectorImageType::New();
  CreateImage(image);
 
  typedef itk::VectorIndexSelectionCastImageFilter<VectorImageType, ScalarImageType> IndexSelectionType;
  IndexSelectionType::Pointer indexSelectionFilter = IndexSelectionType::New();
  indexSelectionFilter->SetIndex(0);
  indexSelectionFilter->SetInput(image);
 
  typedef itk::MinimumMaximumImageCalculator <ScalarImageType> ImageCalculatorFilterType;
  ImageCalculatorFilterType::Pointer imageCalculatorFilter = ImageCalculatorFilterType::New();
  imageCalculatorFilter->SetImage(indexSelectionFilter->GetOutput());
  imageCalculatorFilter->Compute();
 
  return EXIT_SUCCESS;
}
 
void CreateImage(VectorImageType::Pointer image)
{
  VectorImageType::IndexType start;
  start.Fill(0);
 
  VectorImageType::SizeType size;
  size.Fill(2);
 
   VectorImageType::RegionType region(start, size);
 
  image->SetRegions(region);
  image->SetNumberOfComponentsPerPixel(3);
  image->Allocate();
 
  typedef itk::VariableLengthVector<double> VariableVectorType;
  VariableVectorType variableLengthVector;
  variableLengthVector.SetSize(3);
  variableLengthVector[0] = 1.1;
  variableLengthVector[1] = 2.2;
  variableLengthVector[2] = 3.3;
 
  image->FillBuffer(variableLengthVector);
 
}
</source>
 
{{ITKCMakeLists|VectorIndexSelectionCastImageFilter}}

Latest revision as of 21:40, 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.