[Insight-developers] itkMahalanobisDistanceMembershipFunction problem ...

Lagaffe lagaffe74130 at yahoo.fr
Sat Oct 1 08:44:06 EDT 2005


(Hi, just a copy to the developers of the
itkMahalanobisDistanceMembershipFunction problem I
sent to the Insight Users list)


Hello Karthik,

I did a checkout this morning, for your last update
concerning the SetMean function of the
itkMahalanobisDistanceMembershipFunction filter ...
But there is still a problem ...
error: invalid conversion from 'itk::Array<double>*'
to 'unsigned int'

So, I did a simple program below, that evaluate the
mahalanobis distance so you can easily check if the
filter work with the new convention (itkArray)
Hope it will help you and I to debug the filter ;-)
thanks
arnaud

#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#include "itkVector.h"
#include "itkListSample.h"
#include "itkMeanCalculator.h"
#include "itkCovarianceCalculator.h"
#include "itkMahalanobisDistanceMembershipFunction.h"
int main()
{

	const unsigned int MeasurementVectorLength = 3;
	typedef itk::Vector< float, MeasurementVectorLength >
MeasurementVectorType;
	typedef itk::Statistics::ListSample<
MeasurementVectorType > SampleType;
	SampleType::Pointer sample = SampleType::New();
	sample->SetMeasurementVectorSize(
MeasurementVectorLength );
	MeasurementVectorType mv;
	mv[0] = 1.0;
	mv[1] = 2.0;
	mv[2] = 4.0;
	
	sample->PushBack( mv );
	
	mv[0] = 2.0;
	mv[1] = 4.0;
	mv[2] = 5.0;
	sample->PushBack( mv );
	
	mv[0] = 3.0;
	mv[1] = 8.0;
	mv[2] = 6.0;
	sample->PushBack( mv );
	
	mv[0] = 2.0;
	mv[1] = 7.0;
	mv[2] = 4.0;
	sample->PushBack( mv );
	
	mv[0] = 3.0;
	mv[1] = 2.0;
	mv[2] = 7.0;
	sample->PushBack( mv );
	typedef itk::Statistics::MeanCalculator< SampleType >
MeanAlgorithmType;
	
	MeanAlgorithmType::Pointer meanAlgorithm =
MeanAlgorithmType::New();
	
	meanAlgorithm->SetInputSample( sample );
	meanAlgorithm->Update();
	
	std::cout << "Sample mean = " <<
*(meanAlgorithm->GetOutput()) << std::endl;

	typedef itk::Statistics::CovarianceCalculator<
SampleType > 
		CovarianceAlgorithmType;
	CovarianceAlgorithmType::Pointer covarianceAlgorithm
= 
		CovarianceAlgorithmType::New();
	
	covarianceAlgorithm->SetInputSample( sample );
	covarianceAlgorithm->SetMean(
meanAlgorithm->GetOutput() );
	covarianceAlgorithm->Update();
	
	std::cout << "Sample covariance = " << std::endl ; 
	std::cout << *(covarianceAlgorithm->GetOutput()) <<
std::endl;
	
	typedef 
itk::Statistics::MahalanobisDistanceMembershipFunction<
MeasurementVectorType >
MahalanobisDistanceMembershipFunctionType;
	MahalanobisDistanceMembershipFunctionType::Pointer
MahalanobisDistance =
MahalanobisDistanceMembershipFunctionType::New();

MahalanobisDistance->SetMean(meanAlgorithm->GetOutput());

MahalanobisDistance->SetCovariance(covarianceAlgorithm->GetOutput()->GetVnlMatrix());
	std::cout << "Mahalanobis distance=" <<
MahalanobisDistance->Evaluate(mv) << std::endl;	
	
	return 0;
}



	

	
		
___________________________________________________________________________ 
Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger 
Téléchargez cette version sur http://fr.messenger.yahoo.com


More information about the Insight-developers mailing list