1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: itkSampleSelectiveMeanShiftBlurringFilterTest.cxx,v $
Language: C++
Date: $Date: 2006-09-02 12:56:09 $
Version: $Revision: 1.6 $
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkImageRegionIterator.h"
#include "itkJointDomainImageToListAdaptor.h"
#include "itkSampleSelectiveMeanShiftBlurringFilter.h"
#include "itkHypersphereKernelMeanShiftModeSeeker.h"
int itkSampleSelectiveMeanShiftBlurringFilterTest(int argc, char* argv[] )
{
std::cout << "SampleSelectiveMeanShiftBlurringFilter Test \n \n";
if (argc < 3)
{
std::cerr << "Missing Parameters " << std::endl;
std::cerr << "Usage: " << argv[0];
std::cerr << " inputImage outputImage" << std::endl;
return EXIT_FAILURE;
}
typedef itk::Image< unsigned char, 2 > ImageType ;
typedef itk::ImageFileReader< ImageType > ImageReaderType ;
ImageReaderType::Pointer imageReader = ImageReaderType::New() ;
imageReader->SetFileName( argv[1] ) ;
imageReader->Update() ;
ImageType::Pointer image = imageReader->GetOutput() ;
typedef itk::Statistics::JointDomainImageToListAdaptor< ImageType >
ListSampleType ;
ListSampleType::Pointer listSample = ListSampleType::New() ;
listSample->SetImage( image ) ;
ListSampleType::NormalizationFactorsType factors ;
factors[0] = 4 ;
factors[1] = 4 ;
factors[2] = 8 ;
listSample->SetNormalizationFactors( factors ) ;
typedef itk::Statistics::HypersphereKernelMeanShiftModeSeeker<
ListSampleType > ModeSeekerType ;
ModeSeekerType::Pointer modeSeeker = ModeSeekerType::New() ;
modeSeeker->SetInputSample( listSample ) ;
modeSeeker->SetSearchRadius( 1.0 ) ;
typedef itk::Statistics::SampleSelectiveMeanShiftBlurringFilter<
ListSampleType > FilterType ;
FilterType::Pointer filter = FilterType::New() ;
filter->SetInputSample( listSample ) ;
filter->SetMeanShiftModeSeeker( modeSeeker ) ;
std::cout << "Length of measurement vectors in the list sample: "
<< listSample->GetMeasurementVectorSize() << std::endl;
FilterType::ComponentSelectionsType componentSelections(
listSample->GetMeasurementVectorSize(), false) ;
componentSelections[2] = true ;
filter->SetComponentSelections( componentSelections ) ;
try
{
filter->Update() ;
}
catch ( ... )
{
std::cout << "Test failed." << std::endl;
return EXIT_FAILURE;
}
typedef ImageType OutputImageType ;
typedef itk::ImageRegionIterator< OutputImageType > ImageIteratorType ;
typedef ImageType::PixelType PixelType ;
typedef itk::ImageFileWriter< OutputImageType > ImageWriterType ;
OutputImageType::Pointer outputImage = OutputImageType::New() ;
outputImage->SetRegions( image->GetLargestPossibleRegion() ) ;
outputImage->Allocate() ;
ImageIteratorType io_iter( outputImage,
outputImage->GetLargestPossibleRegion() ) ;
io_iter.GoToBegin() ;
FilterType::OutputType::Pointer output = filter->GetOutput() ;
FilterType::OutputType::Iterator fo_iter = output->Begin() ;
FilterType::OutputType::Iterator fo_end = output->End() ;
while ( fo_iter != fo_end )
{
io_iter.Set
((PixelType) (factors[2] * fo_iter.GetMeasurementVector()[2])) ;
++fo_iter ;
++io_iter ;
}
ImageWriterType::Pointer writer = ImageWriterType::New() ;
writer->SetFileName(argv[2]) ;
writer->SetInput( outputImage ) ;
writer->Update() ;
std::cout << "Test passed." << std::endl;
return EXIT_SUCCESS;
}
|