<br>Dear itk users,<br><br>I am trying to run the itk N3 algorithm implemented by Nicholas J. Tustison and James C. Gee  and I am getting a &quot;segmentation fault&quot; error.<br><br>Above I am sending the main part of my code and the error I am getting. <br>
<br>-------------------------------------<br>    /// m_inputImage is a minc image - you can download it from the following site: <a href="http://www.4shared.com/file/140891877/c11d6f0c/20090808_0_DUAL.html">http://www.4shared.com/file/140891877/c11d6f0c/20090808_0_DUAL.html</a><br>
<br>     int m_shrinkFactor = 2;<br>  <br>    /// m_maskImage is purposely equal to zero so that it can be computed using Otsu threshold<br><br>    ///<br>    /// Use Otsu threshold to compute a simple mask, if one is not provided<br>
    ///<br>    if( ! m_maskImage )<br>    {<br>        typedef itk::OtsuThresholdImageFilter&lt; TInputImageType, TMaskImageType &gt; ThresholderType;<br>        typename ThresholderType::Pointer otsu = ThresholderType::New();<br>
        otsu-&gt;SetInput( m_inputImage );<br>        otsu-&gt;SetNumberOfHistogramBins( 200 );<br>        otsu-&gt;SetInsideValue( 0 );<br>        otsu-&gt;SetOutsideValue( 1 );<br>        otsu-&gt;Update();<br><br>        m_maskImage = otsu-&gt;GetOutput();<br>
    } <br><br>    ///<br>    /// DownSampling the input image to reduce computation time<br>    ///<br>    typedef itk::ShrinkImageFilter&lt; TInputImageType, TRealImageType &gt; ShrinkerImageType;<br>    typename ShrinkerImageType::Pointer shrinker1 = ShrinkerImageType::New();<br>
    shrinker1-&gt;SetInput( m_inputImage );<br>    shrinker1-&gt;SetShrinkFactors( 1 );<br><br>    typedef itk::ShrinkImageFilter&lt; TMaskImageType, TMaskImageType &gt; ShrinkerMaskType;<br>    typename ShrinkerMaskType::Pointer shrinker2 = ShrinkerMaskType::New();<br>
    shrinker2-&gt;SetInput( m_maskImage );<br>    shrinker2-&gt;SetShrinkFactors( 1 );<br>    <br>    if( m_shrinkFactor &gt; 1 )<br>    {    <br>        shrinker1-&gt;SetShrinkFactors( m_shrinkFactor );<br>        shrinker2-&gt;SetShrinkFactors( m_shrinkFactor );<br>
        shrinker1-&gt;Update();<br>        shrinker2-&gt;Update();<br>    }<br><br>    typename TRealImageType::Pointer realInputImage = shrinker1-&gt;GetOutput(); <br>    typename TMaskImageType::Pointer maskShrinked = shrinker2-&gt;GetOutput();<br>
<br>     <br>    ///<br>    /// Run bias field correction<br>    ///<br>    typedef itk::N3MRIBiasFieldCorrectionImageFilter&lt; TRealImageType, TMaskImageType, TRealImageType &gt; CorrectorType;<br>      typename CorrectorType::Pointer corrector = CorrectorType::New();<br>
      corrector-&gt;SetInput( realInputImage );<br>      corrector-&gt;SetMaskImage( maskShrinked );<br>     corrector-&gt;SetMaskLabel( NumericTraits&lt; TMaskImageType::PixelType &gt;::One );<br>    corrector-&gt;SetMaximumNumberOfIterations( m_maxNumIter );<br>
    corrector-&gt;SetNumberOfFittingLevels( m_numFittingLevels );<br><br>    try<br>    {<br>        corrector-&gt;Update();<br>    }<br>    catch ( itk::ExceptionObject &amp; err )<br>    {<br>        std::cout &lt;&lt; &quot;Caught an exception: &quot; &lt;&lt; std::endl;<br>
        std::cout &lt;&lt; err &lt;&lt; &quot; &quot; &lt;&lt; __FILE__ &lt;&lt; &quot; &quot; &lt;&lt; __LINE__ &lt;&lt; std::endl;<br>        throw err;<br>    }<br>    catch (... )<br>    {<br>        std::cout &lt;&lt; &quot;Error while applying bias field correction&quot; &lt;&lt; std::endl;<br>
        throw;<br>    }<br><br><br>OUTPUT <br>--------------------------<br>Starting<br>[-116.98, -103.715, -34.2648]<br>[0.857143, 0.857143, 6]<br>[280, 280, 25]<br>0.999208 -0.00996255 -0.0385217<br>0.0108005 0.999708 0.0216062<br>
0.0382952 -0.0220051 0.999024<br><br>[3, 3, 3]<br>3<br>[4, 4, 4]<br>Segmentation fault<br>--------------------------<br><br><br>After spending some time looking for the problem I found out that the it is happening in the following part of the itkN3MRIBiasFieldCorrectionImageFilter.txx file.  The problem does not occur if I use the original image without downsampling it.<br>
<br>I really appreciate any help on this !!!<br><br>Thanks,<br>Ricardo<br><br>   <br>cout &lt;&lt; &quot;Starting&quot; &lt;&lt; endl;<br><br>  cout &lt;&lt; fieldEstimate-&gt;GetOrigin() &lt;&lt; endl;<br>  cout &lt;&lt; fieldEstimate-&gt;GetSpacing() &lt;&lt; endl;<br>
  cout &lt;&lt; fieldEstimate-&gt;GetLargestPossibleRegion().GetSize() &lt;&lt; endl;<br>  cout &lt;&lt; fieldEstimate-&gt;GetDirection() &lt;&lt; endl;<br>  cout &lt;&lt; this-&gt;m_NumberOfFittingLevels &lt;&lt; endl;<br>
  cout &lt;&lt; this-&gt;m_SplineOrder &lt;&lt; endl;<br>  cout &lt;&lt; this-&gt;m_NumberOfControlPoints &lt;&lt; endl;   <br>   <br>  typename BSplineFilterType::Pointer bspliner = BSplineFilterType::New();<br>  bspliner-&gt;SetOrigin( fieldEstimate-&gt;GetOrigin() );<br>
  bspliner-&gt;SetSpacing( fieldEstimate-&gt;GetSpacing() );<br>  bspliner-&gt;SetSize( fieldEstimate-&gt;GetLargestPossibleRegion().GetSize() );<br>  bspliner-&gt;SetDirection( fieldEstimate-&gt;GetDirection() );<br>  bspliner-&gt;SetGenerateOutputImage( true );<br>
  bspliner-&gt;SetNumberOfLevels( this-&gt;m_NumberOfFittingLevels );<br>  bspliner-&gt;SetSplineOrder( this-&gt;m_SplineOrder );<br>  bspliner-&gt;SetNumberOfControlPoints( this-&gt;m_NumberOfControlPoints );<br>  bspliner-&gt;SetInput( fieldPoints );<br>
  bspliner-&gt;Update();<br>   <br>cout &lt;&lt; &quot;Finished&quot; &lt;&lt; endl;<br><br><br>