[Insight-users] mean from vectorial images return nothing ...

Lagaffe lagaffe74130 at yahoo.fr
Fri Feb 10 12:21:32 EST 2006


Hello,

I don't understand why this simple code doesn't return
the mean vector from this simple vectorial image ...

the result is=>Mean  Vector :[] ??


#include "itkImage.h"
#include "itkVector.h"
#include "itkMeanCalculator.h"
#include "itkListSample.h"


int main (int argc, char *argv[]) 
{
	
	// Simple vectorial image  
	typedef itk::Vector< int, 3 >   PixelType;
	typedef itk::Image< PixelType, 2 >    ImageType;
	ImageType::Pointer image = ImageType::New();
	ImageType::RegionType imageRegion;
	ImageType::SizeType imageSize;
	ImageType::IndexType index;
	imageSize[0]=2; imageSize[1]=2;
	imageRegion.SetSize(imageSize);
	image->SetRegions(imageRegion);
	image->Allocate();
	
	// fill the image
	PixelType v;
	//P1
	v[0]=12;v[1]=12;v[2]=12;
	index[0]=0;index[1]=0;
	image->SetPixel(index,v);
	//P2
	v[0]=1;v[1]=2;v[2]=3;
	index[0]=0;index[1]=1;
	image->SetPixel(index,v);
	//P3
	v[0]=5;v[1]=7;v[2]=4;
	index[0]=1;index[1]=0;
	image->SetPixel(index,v);
	//P24
	v[0]=1;v[1]=1;v[2]=3;
	index[0]=1;index[1]=1;
	image->SetPixel(index,v);

	//Add samples p1 and p2 for the test
	typedef  itk::Statistics::ListSample< PixelType >
SampleType;
	typedef SampleType::Pointer SamplePointerType;
	SamplePointerType sample=SampleType::New();
	//p1
	index[0]=0;index[1]=0;
	sample->PushBack(image->GetPixel(index));
	//p2
	index[0]=0;index[1]=1;
	sample->PushBack(image->GetPixel(index));
	
	//-> Compute the mean
	typedef itk::Statistics::MeanCalculator< SampleType >
MeanAlgorithmType;
	typedef MeanAlgorithmType::Pointer MeanPointerType;
	MeanPointerType mean = MeanAlgorithmType::New();
	mean->SetInputSample(sample);
	mean->Update();
	std::cout << "Mean  Vector :" << *(mean->GetOutput())
<< std::endl;
	return 0;
}



	

	
		
___________________________________________________________________________ 
Nouveau : téléphonez moins cher avec Yahoo! Messenger ! Découvez les tarifs exceptionnels pour appeler la France et l'international.
Téléchargez sur http://fr.messenger.yahoo.com


More information about the Insight-users mailing list