[Insight-users] Gaussian Density Function and the Array and Vector
types
Luis Ibanez
luis.ibanez@kitware.com
Sat May 15 04:03:33 EDT 2004
Hi Jayant,
Please consult the Doxygen documentation when you
are in doubt about the existance of a method in ITK.
There is not "fill()" method in the Vector class, you
will find it with uppercase as "Fill()". This is the
coding style for all methods in ITK.
The method is defined in the class FixedArry<> class:
http://www.itk.org/Insight/Doxygen/html/classitk_1_1FixedArray.html
Regards,
Luis
--------------------
Jayant Chauhan wrote:
> Hey fellas,
> Stuck with a stupid problem. But cant seem to figure it out :(
> I am getting errors with regard to the statistics kit, when I try to
> fill my density function related members. The errors I get are like :
>
> D:\Jayant\MTP\ITK\class_filter\firstFilter.h(127) : error C2039: 'fill'
> : is not a member of 'Vector<double,1>'
> C:\Program Files\Microsoft Visual
> Studio\VC98\INCLUDE\xstring(583) : while compiling class-template member
> function 'void __thiscall firstFilter<class itk::Image<unsigned
> char,2>,class itk::Image<float,2>,class itk::Image<unsigned char,2> >:
> :generateDiffImage(const char *)'
> template member function 'void __thiscall firstFilter<class
> itk::Image<unsigned char,2>,class itk::Image<float,2>,class
> itk::Image<unsigned char,2> >:
> :generateDiffImage(const char *)'
>
>
> Could anyone suggest as to how and where to do the typecasting (if that
> is possible)
>
> My function and the various type declarations are as follows :
>
> typedef itk::Vector<float,1> MeasurementVectorType;
> typedef itk::Array< double > ParametersType;
>
> ParametersType staticParams;
> ParametersType mobileParams;
> ParametersType proportions;
>
> template <class TInputImage, class TInternalImage, class TOutputImage>
> void firstFilter<TInputImage, TInternalImage, TOutputImage>
> ::generateDiffImage(const char* image1){
>
> typedef itk::Statistics::GaussianDensityFunction< MeasurementVectorType
> > DensityFunctionType;
> DensityFunctionType::Pointer staticDensityFunction =
> DensityFunctionType::New();
> DensityFunctionType::Pointer mobileDensityFunction =
> DensityFunctionType::New();
> DensityFunctionType::MeanType staticMean;
> DensityFunctionType::MeanType mobileMean;
> DensityFunctionType::CovarianceType staticVariance;
> DensityFunctionType::CovarianceType mobileVariance;
>
> staticMean.fill(staticParams[0]);
> mobileMean.fill(mobileParams[0]);
>
> staticVariance.setIdentity();
> staticVariance *= staticParams[1];
> //staticVariance.fill(staticParams[1]);
> mobileVariance.fill(mobileParams[1]);
>
> staticDensityFunction->SetMean( &staticMean );
> mobileDensityFunction->SetMean( &mobileMean );
> staticDensityFunction->SetCovariance( &staticVariance );
> mobileDensityFunction->SetCovariance( &mobileVariance );
>
> typedef itk::ConstNeighborhoodIterator< TInputImage >
> NeighborhoodIteratorType;
> typedef itk::ImageRegionIterator< TInputImage > IteratorType;
> InputImageReader::Pointer reader = InputImageReader::New();
> reader->SetFileName( image1 );
> try
> {
> reader->Update();
> }
> catch ( itk::ExceptionObject &err)
> {
> std::cout << "ExceptionObject caught !" << std::endl;
> std::cout << err << std::endl;
> return -1;
> }
>
> NeighborhoodIteratorType::RadiusType radius;
> radius.Fill(1);
> NeighborhoodIteratorType it( radius, reader->GetOutput(),
> reader->GetOutput()->GetRequestedRegion() );
> ImageType::Pointer output = ImageType::New();
> output->SetRegions(reader->GetOutput()->GetRequestedRegion());
> output->Allocate();
>
> IteratorType out(output, reader->GetOutput()->GetRequestedRegion());
>
> std::vector<NeighborhoodIteratorType::OffsetType> offsets(9);
> offsets[0] = {{0,0}};
> offsets[1] = {{-1,-1}};
> offsets[2] = {{1,-1}};
> offsets[3] = {{-1,0 }};
> offsets[4] = {{1,0}};
> offsets[5] = {{-1,1}};
> offsets[6] = {{1,1}};
> offsets[7] = {{0,1}};
> offsets[8] = {{0,-1}};
>
> MeasurementVectorType mv;
> float e_trans, e_smooth;
> for (it.GoToBegin(), out.GoToBegin(); !it.IsAtEnd(); ++it, ++out)
> {
>
>
> float max;
> float tmp = 0.0;
> float self = it.GetPixel(offsets[0]);
> float neigh;
> float neighStatic, neighMobile;
> float selfStatic, selfMobile;
> selfStatic = staticDensityFunction->Evaluate(self);
> selfMobile = mobileDensityFunction->Evaluate(self);
> for (int indx = 0; indx <8; indx++){
>
> neigh = it.GetPixel(offsets[indx]);
> neighStatic = staticDensityFunction->Evaluate(neigh);
> neighMobile = mobileDensityFunction->Evaluate(neigh);
> e_trans = neighStatic*selfMobile + neighMobile*selfStatic;
> e_smooth = neighStatic*selfStatic + neighMobile*selfMobile;
> tmp = e_trans/e_smooth;
> if (max < tmp)
> max = tmp;
> }
> }
>
> typedef unsigned char WritePixelType;
> typedef itk::Image< WritePixelType, 2 > WriteImageType;
> typedef itk::ImageFileWriter< WriteImageT ype > WriterType;
>
> typedef itk::RescaleIntensityImageFilter<
> ImageType, WriteImageType > RescaleFilterType;
>
> RescaleFilterType::Pointer rescaler = RescaleFilterType::New();
>
> rescaler->SetOutputMinimum( 0 );
> rescaler->SetOutputMaximum( 255 );
> rescaler->SetInput(output);
>
> WriterType::Pointer writer = WriterType::New();
> writer->SetFileName( "I_diff.png" );
> writer->SetInput(rescaler->GetOutput());
>
> try
> {
> writer->Update();
> }
> catch ( itk::ExceptionObject &err)
> {
> &n bsp;std::cout << "ExceptionObject caught !" << std::endl;
> std::cout << err << std::endl;
> return -1;
> }
>
> }
>
> ------------------------------------------------------------------------
> Earn without investing. Sell anything on www.baazee.com.
> <http://g.msn.com/8HMAENIN/2752??PS=47575>
> _______________________________________________ Insight-users mailing
> list Insight-users@itk.org
> http://www.itk.org/mailman/listinfo/insight-users
More information about the Insight-users
mailing list