Difference between revisions of "ITK/Examples/Statistics/ImageToListSampleAdaptor"

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
(Use ComposeImageFilter instead of deprecated ScalarToArrayCastImageFilter.)
(Deprecated content that is moved to sphinx)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
Convert the pixels in an image to a list of measurements in a ListSample.
{{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.}}
 
==ImageToListSampleAdaptor.cxx==
<source lang="cpp">
#include "itkImageToListSampleAdaptor.h"
#include "itkImage.h"
#include "itkRandomImageSource.h"
#include "itkComposeImageFilter.h"
 
int main(int, char *[])
{
  typedef itk::Image<float,2> FloatImage2DType;
 
  itk::RandomImageSource<FloatImage2DType>::Pointer random;
  random = itk::RandomImageSource<FloatImage2DType>::New();
 
  random->SetMin(    0.0 );
  random->SetMax( 1000.0 );
 
  typedef FloatImage2DType::SpacingValueType SpacingValueType;
  typedef FloatImage2DType::SizeValueType    SizeValueType;
  typedef FloatImage2DType::PointValueType    PointValueType;
 
  SizeValueType size[2] = {20, 20};
  random->SetSize( size );
 
  SpacingValueType spacing[2] = {0.7, 2.1};
  random->SetSpacing( spacing );
 
   PointValueType origin[2] = {15, 400};
  random->SetOrigin( origin );
 
  typedef itk::FixedArray< float, 1 > MeasurementVectorType;
  typedef itk::Image< MeasurementVectorType, 2 > ArrayImageType;
  typedef itk::ComposeImageFilter< FloatImage2DType, ArrayImageType >
    CasterType;
 
  CasterType::Pointer caster = CasterType::New();
  caster->SetInput( random->GetOutput() );
  caster->Update();
 
  typedef itk::Statistics::ImageToListSampleAdaptor< ArrayImageType > SampleType;
  SampleType::Pointer sample = SampleType::New();
 
  sample->SetImage( caster->GetOutput() );
 
  SampleType::Iterator iter = sample->Begin() ;
 
  while( iter != sample->End() )
    {
    std::cout << iter.GetMeasurementVector() << std::endl ;
    ++iter;
    }
   
  return EXIT_SUCCESS;
}
</source>
 
{{ITKCMakeLists|ImageToListSampleAdaptor}}

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