[Insight-users] KdTreeBasedKMeansClustering for 3D vector image

Sara Rolfe smrolfe at u.washington.edu
Thu Dec 2 18:55:27 EST 2010


I did clear this error up, I needed to define the sample classifier as:

	typedef itk::Statistics::SampleClassifier< AdaptorType >  
ClassifierType;

instead of:
		
	typedef itk::Statistics::SampleClassifier< SampleType > ClassifierType;

Since I'm using the ImageToListAdaptor to get the samples from my image.

On Dec 2, 2010, at 2:30 PM, Sara Rolfe wrote:

> Thanks for the additional example.  I have not yet gotten it to run,  
> since I think I'm dealing with some version issues (I'm using  
> itk-3.14).  RIght now it's not recognizing itkMinimumDecisionRule2,  
> itkSampleClassifierFilter, etc.  I will let you know when I'm able  
> to get this working.  Is it possible that using older versions of  
> these filters is part of my problem?
>
> In the meantime, with my code, the estimated mean vectors are  
> calculated correctly, but when I add the classification I getting  
> the following error:
>
> error: no matching function for call to  
> ‘itk 
> ::Statistics 
> ::SampleClassifier 
> < 
> main 
> (int 
> ,char 
> **)::SampleType 
> > 
> ::SetSample 
> (itk::SmartPointer<itk::Statistics::ImageToListAdaptor<main(int,  
> char**)::ImageType, main(int, char**)::PixelType> >&)’
>
> ...itkSampleClassifier.txx:56: note: candidates are: void  
> itk::Statistics::SampleClassifier<TSample>::SetSample(const  
> TSample*) [with TSample = main(int, char**)::SampleType]
>
>
> So there's a problem when I set my classifier sample.  My full code  
> is below.
>
> #include "itkKdTree.h"
> #include "itkKdTreeBasedKmeansEstimator.h"
> #include "itkWeightedCentroidKdTreeGenerator.h"
>
> #include "itkImageToListAdaptor.h"
> #include "itkImageFileReader.h"
> #include "itkImage.h"
>
> #include "itkMinimumDecisionRule.h"
> #include "itkEuclideanDistance.h"
> #include "itkSampleClassifier.h"
>
> #include "itkVector.h"
> #include "itkListSample.h"
> #include "itkDistanceToCentroidMembershipFunction.h"
>
>
>
> int main(  int argc,  char * argv[]  )
> {
> 	if( argc < 5 )
>     {
> 		std::cerr << "Usage: " << std::endl;
> 		std::cerr << argv[0];
> 		std::cerr << " inputVectorImage.vtk outputLabeledImage.vtk";
> 		std::cerr << " numberOfClasses numberOfComponents " << std::endl;
> 		return EXIT_FAILURE;
>     }
> 	
> 	typedef itk::Vector< unsigned char, 2 >	PixelType;
> 	typedef itk::Image< PixelType, 3 > ImageType;
> 	typedef itk::ImageFileReader< ImageType > ReaderType;
> 	typedef itk::Statistics::ImageToListAdaptor< ImageType > AdaptorType;
> 	typedef  
> itk::Statistics::WeightedCentroidKdTreeGenerator<AdaptorType >  
> TreeGeneratorType;
> 	typedef TreeGeneratorType::KdTreeType TreeType;
> 	typedef itk:: Statistics:: KdTreeBasedKmeansEstimator< TreeType >  
> EstimatorType;
> 	typedef itk::Vector< PixelType, 3 > MeasurementVectorType;
> 	typedef itk::Statistics::EuclideanDistance< MeasurementVectorType >  
> MembershipFunctionType;
> 	typedef itk::MinimumDecisionRule DecisionRuleType;
> 	typedef itk::Statistics::ListSample< MeasurementVectorType >  
> SampleType;
> 	typedef itk::Statistics::SampleClassifier< SampleType >  
> ClassifierType;
> 	
> 	const char * inputImageFileName = argv[1];
> 	const char * outputImageFileName = argv[2];
> 	int numberOfClasses = atoi( argv[3] );
> 	int numberOfComponents = atoi( argv[4] );
> 	
> 	ReaderType::Pointer reader = ReaderType::New();
> 	reader->SetFileName( inputImageFileName );
> 	reader->Update();
> 	
> 	AdaptorType::Pointer adaptor = AdaptorType::New();
> 	adaptor->SetImage(  reader->GetOutput() );
> 	
> 	TreeGeneratorType::Pointer treeGenerator = TreeGeneratorType::New();
> 	treeGenerator->SetSample( adaptor );
> 	treeGenerator->SetBucketSize( 16 );
> 	treeGenerator->Update();
>
> 	EstimatorType::Pointer estimator = EstimatorType::New();
> 	EstimatorType::ParametersType initialMeans( numberOfClasses *  
> numberOfComponents );
> 	estimator->SetParameters( initialMeans );
> 	estimator->SetKdTree( treeGenerator->GetOutput() );
> 	estimator->SetMaximumIteration( 200 );
> 	estimator->SetCentroidPositionChangesThreshold(0.0);
> 	estimator->StartOptimization();
> 	
> 	EstimatorType::ParametersType estimatedMeans = estimator- 
> >GetParameters();
>
> 	for ( int i = 0 ; i < numberOfClasses ; ++i )
>     {
> 		std::cout << "cluster[" << i << "] ";
> 		std::cout << "  estimated mean : ";
> 		for ( int j = 0 ; j < numberOfComponents ; ++j )
> 		{
> 			std::cout << "    " << estimatedMeans[ i * numberOfComponents +  
> j ];
> 		}
> 		std::cout << std::endl;
>     }
>
> 	//classification using estimated means - this is the part that is  
> not working correctly
> 	DecisionRuleType::Pointer decisionRule = DecisionRuleType::New();
> 	
> 	ClassifierType::Pointer classifier = ClassifierType::New();
> 	classifier->SetDecisionRule( (itk::DecisionRuleBase::Pointer)  
> decisionRule);
> 	classifier->SetSample( adaptor );
> 	classifier->SetNumberOfClasses( 7 );
> 	
> 	std::vector< unsigned int > classLabels;
> 	classLabels.resize( numberOfClasses );
> 	for ( int i = 0 ; i < numberOfClasses ; ++i )
>     {
> 		classLabels[i] = i;
> 	}
> 	classifier->SetMembershipFunctionClassLabels( classLabels );
> 	
> }
>
> On Dec 1, 2010, at 6:32 PM, Luis Ibanez wrote:
>
>> Voila !
>>
>> http://www.itk.org/Wiki/ITK/Examples/Statistics/KdTreeBasedKMeansClustering_3D
>>
>> Thanks for pointing to these examples David.
>>
>>
>> Sara,
>>
>> when running the example above,
>> the code seems to behave correctly.
>>
>> Please give it a try and let us know
>> if you see anything out of order.
>>
>>
>>    Thanks
>>
>>
>>      Luis
>>
>>
>> -----------------------------------------
>> On Wed, Dec 1, 2010 at 8:31 PM, David Doria <daviddoria at gmail.com>  
>> wrote:
>>> On Wed, Dec 1, 2010 at 8:16 PM, Luis Ibanez  
>>> <luis.ibanez at kitware.com> wrote:
>>>> Hi Sara,
>>>>
>>>> The KdTree should work in N-D.
>>>>
>>>> We tend to do 2D test just because they are
>>>> easier to debug, but we probably should add
>>>> a 3D one in this case.
>>>>
>>>> Could you tell us more about the behavior of
>>>> this class that lead you to believe that is doing
>>>> something incorrect ?
>>>>
>>>> A minimal example will be greatly appreciated...
>>>
>>>
>>> Are these the examples you were looking at?
>>>
>>> http://www.vtk.org/Wiki/ITK/Examples/Statistics/KdTreeBasedKMeansClustering_1D
>>> http://www.vtk.org/Wiki/ITK/Examples/Statistics/KdTreeBasedKMeansClustering_2D
>>>
>>> If not, maybe they will help. If so, please add
>>> http://www.vtk.org/Wiki/ITK/Examples/Statistics/KdTreeBasedKMeansClustering_3D
>>>
>>> and we can work on it there.
>>>
>>> David
>>>
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20101202/75eb8704/attachment.htm>


More information about the Insight-users mailing list