[Insight-users] Gaussian Density Function and the Array and Vector types
Jayant Chauhan
gripened@hotmail.com
Sat May 15 03:10:07 EDT 2004
<html><div style='background-color:'><DIV class=RTE>Hey fellas,</DIV>
<DIV class=RTE>Stuck with a stupid problem. But cant seem to figure it out :(</DIV>
<DIV class=RTE>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 :</DIV>
<DIV class=RTE> </DIV>
<DIV class=RTE>D:\Jayant\MTP\ITK\class_filter\firstFilter.h(127) : error C2039: 'fill' : is not a member of 'Vector<double,1>'<BR> 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> >:<BR>:generateDiffImage(const char *)'<BR>template member function 'void __thiscall firstFilter<class itk::Image<unsigned char,2>,class itk::Image<float,2>,class itk::Image<unsigned char,2> >:<BR>:generateDiffImage(const char *)'</DIV>
<DIV class=RTE> </DIV>
<DIV class=RTE> </DIV>
<DIV class=RTE>Could anyone suggest as to how and where to do the typecasting (if that is possible)</DIV>
<DIV class=RTE> </DIV>
<DIV class=RTE>My function and the various type declarations are as follows :</DIV>
<DIV class=RTE> </DIV>
<DIV class=RTE>typedef itk::Vector<float,1> MeasurementVectorType;<BR>typedef itk::Array< double > ParametersType;</DIV>
<DIV class=RTE> </DIV>
<DIV class=RTE> ParametersType staticParams;<BR> ParametersType mobileParams;<BR> ParametersType proportions;</DIV>
<DIV class=RTE> </DIV>
<DIV class=RTE>template <class TInputImage, class TInternalImage, class TOutputImage><BR>void firstFilter<TInputImage, TInternalImage, TOutputImage><BR>::generateDiffImage(const char* image1){<BR> <BR> typedef itk::Statistics::GaussianDensityFunction< MeasurementVectorType > DensityFunctionType;</DIV>
<DIV class=RTE> DensityFunctionType::Pointer staticDensityFunction = DensityFunctionType::New(); <BR> DensityFunctionType::Pointer mobileDensityFunction = DensityFunctionType::New(); </DIV>
<DIV class=RTE> DensityFunctionType::MeanType staticMean;<BR> DensityFunctionType::MeanType mobileMean;</DIV>
<DIV class=RTE> DensityFunctionType::CovarianceType staticVariance;<BR> DensityFunctionType::CovarianceType mobileVariance;</DIV>
<DIV class=RTE> </DIV>
<DIV class=RTE> staticMean.fill(staticParams[0]);<BR> mobileMean.fill(mobileParams[0]);<BR> <BR> staticVariance.setIdentity();<BR> staticVariance *= staticParams[1];<BR> //staticVariance.fill(staticParams[1]);</DIV>
<DIV class=RTE> mobileVariance.fill(mobileParams[1]);<BR> <BR> staticDensityFunction->SetMean( &staticMean );<BR> mobileDensityFunction->SetMean( &mobileMean );</DIV>
<DIV class=RTE> staticDensityFunction->SetCovariance( &staticVariance );<BR> mobileDensityFunction->SetCovariance( &mobileVariance );</DIV>
<DIV class=RTE> <BR> typedef itk::ConstNeighborhoodIterator< TInputImage > NeighborhoodIteratorType;<BR> typedef itk::ImageRegionIterator< TInputImage > IteratorType;</DIV>
<DIV class=RTE> InputImageReader::Pointer reader = InputImageReader::New();<BR> reader->SetFileName( image1 );<BR> try<BR> {<BR> reader->Update();<BR> }<BR> catch ( itk::ExceptionObject &err)<BR> {<BR> std::cout << "ExceptionObject caught !" << std::endl; <BR> std::cout << err << std::endl; <BR> return -1;<BR> }<BR> <BR> NeighborhoodIteratorType::RadiusType radius;<BR> radius.Fill(1);<BR> NeighborhoodIteratorType it( radius, reader->GetOutput(),<BR> reader->GetOutput()->GetRequestedRegion() );<BR> ImageType::Pointer output = ImageType::New();<BR> output->SetRegions(reader->GetOutput()->GetRequestedRegion());<BR> output->Allocate();<BR> <BR> IteratorType out(output, reader->GetOutput()->GetRequestedRegion());<BR> <BR> std::vector<NeighborhoodIteratorType::OffsetType> offsets(9);</DIV>
<DIV class=RTE> offsets[0] = {{0,0}};<BR> offsets[1] = {{-1,-1}};<BR> offsets[2] = {{1,-1}};<BR> offsets[3] = {{-1,0 }};<BR> offsets[4] = {{1,0}};<BR> offsets[5] = {{-1,1}};<BR> offsets[6] = {{1,1}};<BR> offsets[7] = {{0,1}};<BR> offsets[8] = {{0,-1}};<BR> <BR> MeasurementVectorType mv;<BR> float e_trans, e_smooth;</DIV>
<DIV class=RTE> for (it.GoToBegin(), out.GoToBegin(); !it.IsAtEnd(); ++it, ++out)<BR> {<BR> <BR> <BR> float max;<BR> float tmp = 0.0; <BR> float self = it.GetPixel(offsets[0]);<BR> float neigh;<BR> float neighStatic, neighMobile;<BR> float selfStatic, selfMobile;</DIV>
<DIV class=RTE> selfStatic = staticDensityFunction->Evaluate(self);<BR> selfMobile = mobileDensityFunction->Evaluate(self);<BR> for (int indx = 0; indx <8; indx++){<BR> <BR> neigh = it.GetPixel(offsets[indx]);<BR> neighStatic = staticDensityFunction->Evaluate(neigh); <BR> neighMobile = mobileDensityFunction->Evaluate(neigh); </DIV>
<DIV class=RTE> e_trans = neighStatic*selfMobile + neighMobile*selfStatic;<BR> e_smooth = neighStatic*selfStatic + neighMobile*selfMobile;</DIV>
<DIV class=RTE> tmp = e_trans/e_smooth;<BR> if (max < tmp)<BR> max = tmp;</DIV>
<DIV class=RTE> }<BR> }<BR> <BR> typedef unsigned char WritePixelType;<BR> typedef itk::Image< WritePixelType, 2 > WriteImageType;<BR> typedef itk::ImageFileWriter< WriteImageT ype > WriterType;<BR> <BR> typedef itk::RescaleIntensityImageFilter< <BR> ImageType, WriteImageType > RescaleFilterType;<BR> <BR> RescaleFilterType::Pointer rescaler = RescaleFilterType::New();<BR> <BR> rescaler->SetOutputMinimum( 0 );<BR> rescaler->SetOutputMaximum( 255 );<BR> rescaler->SetInput(output);<BR> <BR> WriterType::Pointer writer = WriterType::New();<BR> writer->SetFileName( "I_diff.png" );<BR> writer->SetInput(rescaler->GetOutput());<BR> <BR> try<BR> {<BR> writer->Update();<BR> }<BR> catch ( itk::ExceptionObject &err)<BR> {<BR> std::cout << "ExceptionObject caught !" << std::endl; <BR> std::cout << err << std::endl; <BR> return -1; <BR> }<BR> <BR>}</DIV></div><br clear=all><hr>Earn without investing. <a href="http://g.msn.com/8HMAENIN/2752??PS=47575">Sell anything on www.baazee.com.</a> </html>
More information about the Insight-users
mailing list