ITK/Examples/Statistics/ImageToListSampleAdaptor: Difference between revisions
From KitwarePublic
Jump to navigationJump to search
(Wrong signature for main.) |
Daviddoria (talk | contribs) mNo edit summary |
||
Line 1: | Line 1: | ||
Convert the pixels in an image to a list of measurements in a ListSample. | |||
==ImageToListSampleAdaptor.cxx== | ==ImageToListSampleAdaptor.cxx== | ||
<source lang="cpp"> | <source lang="cpp"> | ||
Line 8: | Line 10: | ||
int main(int, char *[]) | int main(int, char *[]) | ||
{ | { | ||
typedef itk::Image<float,2> FloatImage2DType; | typedef itk::Image<float,2> FloatImage2DType; | ||
Revision as of 17:49, 20 November 2010
Convert the pixels in an image to a list of measurements in a ListSample.
ImageToListSampleAdaptor.cxx
<source lang="cpp">
- include "itkImageToListSampleAdaptor.h"
- include "itkImage.h"
- include "itkRandomImageSource.h"
- include "itkScalarToArrayCastImageFilter.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::ScalarToArrayCastImageFilter< 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>
CMakeLists.txt
<source lang="cmake"> cmake_minimum_required(VERSION 2.6)
PROJECT(ImageToListSampleAdaptor)
FIND_PACKAGE(ITK REQUIRED) INCLUDE(${ITK_USE_FILE})
ADD_EXECUTABLE(ImageToListSampleAdaptor ImageToListSampleAdaptor.cxx) TARGET_LINK_LIBRARIES(ImageToListSampleAdaptor ITKBasicFilters ITKCommon ITKIO)
</source>