[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>&nbsp;</DIV>
<DIV class=RTE>D:\Jayant\MTP\ITK\class_filter\firstFilter.h(127) : error C2039: 'fill' : is not a member of 'Vector&lt;double,1&gt;'<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; C:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\xstring(583) : while compiling class-template member function 'void __thiscall firstFilter&lt;class itk::Image&lt;unsigned char,2&gt;,class itk::Image&lt;float,2&gt;,class itk::Image&lt;unsigned char,2&gt; &gt;:<BR>:generateDiffImage(const char *)'<BR>template member function 'void __thiscall firstFilter&lt;class itk::Image&lt;unsigned char,2&gt;,class itk::Image&lt;float,2&gt;,class itk::Image&lt;unsigned char,2&gt; &gt;:<BR>:generateDiffImage(const char *)'</DIV>
<DIV class=RTE>&nbsp;</DIV>
<DIV class=RTE>&nbsp;</DIV>
<DIV class=RTE>Could anyone suggest as to how and where to do the typecasting (if that is possible)</DIV>
<DIV class=RTE>&nbsp;</DIV>
<DIV class=RTE>My function and the various type declarations are as follows :</DIV>
<DIV class=RTE>&nbsp;</DIV>
<DIV class=RTE>typedef itk::Vector&lt;float,1&gt; MeasurementVectorType;<BR>typedef itk::Array&lt; double &gt; ParametersType;</DIV>
<DIV class=RTE>&nbsp;</DIV>
<DIV class=RTE>&nbsp;&nbsp;ParametersType staticParams;<BR>&nbsp;&nbsp;ParametersType mobileParams;<BR>&nbsp;&nbsp;ParametersType proportions;</DIV>
<DIV class=RTE>&nbsp;</DIV>
<DIV class=RTE>template &lt;class TInputImage, class TInternalImage, class TOutputImage&gt;<BR>void firstFilter&lt;TInputImage, TInternalImage, TOutputImage&gt;<BR>::generateDiffImage(const char* image1){<BR>&nbsp;<BR>&nbsp;typedef itk::Statistics::GaussianDensityFunction&lt; MeasurementVectorType &gt; DensityFunctionType;</DIV>
<DIV class=RTE>&nbsp;DensityFunctionType::Pointer staticDensityFunction = DensityFunctionType::New();&nbsp;<BR>&nbsp;DensityFunctionType::Pointer mobileDensityFunction = DensityFunctionType::New();&nbsp;</DIV>
<DIV class=RTE>&nbsp;DensityFunctionType::MeanType staticMean;<BR>&nbsp;DensityFunctionType::MeanType mobileMean;</DIV>
<DIV class=RTE>&nbsp;DensityFunctionType::CovarianceType staticVariance;<BR>&nbsp;DensityFunctionType::CovarianceType mobileVariance;</DIV>
<DIV class=RTE>&nbsp;</DIV>
<DIV class=RTE>&nbsp;staticMean.fill(staticParams[0]);<BR>&nbsp;mobileMean.fill(mobileParams[0]);<BR>&nbsp;<BR>&nbsp;staticVariance.setIdentity();<BR>&nbsp;staticVariance *= staticParams[1];<BR>&nbsp;//staticVariance.fill(staticParams[1]);</DIV>
<DIV class=RTE>&nbsp;mobileVariance.fill(mobileParams[1]);<BR>&nbsp;<BR>&nbsp;staticDensityFunction-&gt;SetMean( &amp;staticMean );<BR>&nbsp;mobileDensityFunction-&gt;SetMean( &amp;mobileMean );</DIV>
<DIV class=RTE>&nbsp;staticDensityFunction-&gt;SetCovariance( &amp;staticVariance );<BR>&nbsp;mobileDensityFunction-&gt;SetCovariance( &amp;mobileVariance );</DIV>
<DIV class=RTE>&nbsp;<BR>&nbsp;typedef itk::ConstNeighborhoodIterator&lt; TInputImage &gt; NeighborhoodIteratorType;<BR>&nbsp;typedef itk::ImageRegionIterator&lt; TInputImage &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IteratorType;</DIV>
<DIV class=RTE>&nbsp;InputImageReader::Pointer reader = InputImageReader::New();<BR>&nbsp;reader-&gt;SetFileName( image1 );<BR>&nbsp;try<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;reader-&gt;Update();<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;catch ( itk::ExceptionObject &amp;err)<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;std::cout &lt;&lt; "ExceptionObject caught !" &lt;&lt; std::endl; <BR>&nbsp;&nbsp;std::cout &lt;&lt; err &lt;&lt; std::endl; <BR>&nbsp;&nbsp;return -1;<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;<BR>&nbsp;NeighborhoodIteratorType::RadiusType radius;<BR>&nbsp;radius.Fill(1);<BR>&nbsp;NeighborhoodIteratorType it( radius, reader-&gt;GetOutput(),<BR>&nbsp;&nbsp;reader-&gt;GetOutput()-&gt;GetRequestedRegion() );<BR>&nbsp;ImageType::Pointer output = ImageType::New();<BR>&nbsp;output-&gt;SetRegions(reader-&gt;GetOutput()-&gt;GetRequestedRegion());<BR>&nbsp;output-&gt;Allocate();<BR>&nbsp;<BR>&nbsp;IteratorType out(output, reader-&gt;GetOutput()-&gt;GetRequestedRegion());<BR>&nbsp;<BR>&nbsp;std::vector&lt;NeighborhoodIteratorType::OffsetType&gt; offsets(9);</DIV>
<DIV class=RTE>&nbsp;offsets[0] = {{0,0}};<BR>&nbsp;offsets[1] = {{-1,-1}};<BR>&nbsp;offsets[2] = {{1,-1}};<BR>&nbsp;offsets[3] = {{-1,0 }};<BR>&nbsp;offsets[4] = {{1,0}};<BR>&nbsp;offsets[5] = {{-1,1}};<BR>&nbsp;offsets[6] = {{1,1}};<BR>&nbsp;offsets[7] = {{0,1}};<BR>&nbsp;offsets[8] = {{0,-1}};<BR>&nbsp;<BR>&nbsp;MeasurementVectorType mv;<BR>&nbsp;float e_trans, e_smooth;</DIV>
<DIV class=RTE>&nbsp;for (it.GoToBegin(), out.GoToBegin(); !it.IsAtEnd(); ++it, ++out)<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;float max;<BR>&nbsp;&nbsp;float tmp = 0.0;&nbsp;<BR>&nbsp;&nbsp;float self = it.GetPixel(offsets[0]);<BR>&nbsp;&nbsp;float neigh;<BR>&nbsp;&nbsp;float neighStatic, neighMobile;<BR>&nbsp;&nbsp;float selfStatic, selfMobile;</DIV>
<DIV class=RTE>&nbsp;&nbsp;selfStatic = staticDensityFunction-&gt;Evaluate(self);<BR>&nbsp;&nbsp;selfMobile = mobileDensityFunction-&gt;Evaluate(self);<BR>&nbsp;&nbsp;for (int indx = 0; indx &lt;8; indx++){<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;neigh = it.GetPixel(offsets[indx]);<BR>&nbsp;&nbsp;&nbsp;neighStatic = staticDensityFunction-&gt;Evaluate(neigh); <BR>&nbsp;&nbsp;&nbsp;neighMobile = mobileDensityFunction-&gt;Evaluate(neigh); </DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp;e_trans = neighStatic*selfMobile + neighMobile*selfStatic;<BR>&nbsp;&nbsp;&nbsp;e_smooth = neighStatic*selfStatic + neighMobile*selfMobile;</DIV>
<DIV class=RTE>&nbsp;&nbsp;&nbsp;tmp = e_trans/e_smooth;<BR>&nbsp;&nbsp;&nbsp;if (max &lt; tmp)<BR>&nbsp;&nbsp;&nbsp;&nbsp;max = tmp;</DIV>
<DIV class=RTE>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;<BR>&nbsp;typedef unsigned char WritePixelType;<BR>&nbsp;typedef itk::Image&lt; WritePixelType, 2 &gt; WriteImageType;<BR>&nbsp;typedef itk::ImageFileWriter&lt; WriteImageT&nbsp;ype &gt; WriterType;<BR>&nbsp;<BR>&nbsp;typedef itk::RescaleIntensityImageFilter&lt; <BR>&nbsp;&nbsp;ImageType, WriteImageType &gt; RescaleFilterType;<BR>&nbsp;<BR>&nbsp;RescaleFilterType::Pointer rescaler = RescaleFilterType::New();<BR>&nbsp;<BR>&nbsp;rescaler-&gt;SetOutputMinimum(&nbsp;&nbsp; 0 );<BR>&nbsp;rescaler-&gt;SetOutputMaximum( 255 );<BR>&nbsp;rescaler-&gt;SetInput(output);<BR>&nbsp;<BR>&nbsp;WriterType::Pointer writer = WriterType::New();<BR>&nbsp;writer-&gt;SetFileName( "I_diff.png" );<BR>&nbsp;writer-&gt;SetInput(rescaler-&gt;GetOutput());<BR>&nbsp;<BR>&nbsp;try<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;writer-&gt;Update();<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;catch ( itk::ExceptionObject &amp;err)<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;std::cout &lt;&lt; "ExceptionObject caught !" &lt;&lt; std::endl; <BR>&nbsp;&nbsp;std::cout &lt;&lt; err &lt;&lt; std::endl; <BR>&nbsp;&nbsp;return -1;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;<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