<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi Ricardo,<div><br></div><div>If you're submitting a mask of all zeros, that would explain the error message you're getting. &nbsp;Instead of submitting a mask of all zeros, just type a non-existent filename and the otsu mask will be calculated. &nbsp;Let me know if that works out.</div><div><br></div><div>Nick&nbsp;</div><div><br></div><div><br></div><div><br></div><div><br><div><div>On Oct 14, 2009, at 5:10 PM, Ricardo Ferrari wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><br>Dear itk users,<br><br>I am trying to run the itk N3 algorithm implemented by Nicholas J. Tustison and James C. Gee&nbsp; and I am getting a "segmentation fault" error.<br><br>Above I am sending the main part of my code and the error I am getting. <br>
<br>-------------------------------------<br>&nbsp;&nbsp;&nbsp; /// 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>&nbsp;&nbsp;&nbsp;&nbsp; int m_shrinkFactor = 2;<br>&nbsp; <br>&nbsp;&nbsp;&nbsp; /// m_maskImage is purposely equal to zero so that it can be computed using Otsu threshold<br><br>&nbsp;&nbsp;&nbsp; ///<br>&nbsp;&nbsp;&nbsp; /// Use Otsu threshold to compute a simple mask, if one is not provided<br>
&nbsp;&nbsp;&nbsp; ///<br>&nbsp;&nbsp;&nbsp; if( ! m_maskImage )<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; typedef itk::OtsuThresholdImageFilter&lt; TInputImageType, TMaskImageType &gt; ThresholderType;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; typename ThresholderType::Pointer otsu = ThresholderType::New();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; otsu-&gt;SetInput( m_inputImage );<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; otsu-&gt;SetNumberOfHistogramBins( 200 );<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; otsu-&gt;SetInsideValue( 0 );<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; otsu-&gt;SetOutsideValue( 1 );<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; otsu-&gt;Update();<br><br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; m_maskImage = otsu-&gt;GetOutput();<br>
&nbsp;&nbsp;&nbsp; } <br><br>&nbsp;&nbsp;&nbsp; ///<br>&nbsp;&nbsp;&nbsp; /// DownSampling the input image to reduce computation time<br>&nbsp;&nbsp;&nbsp; ///<br>&nbsp;&nbsp;&nbsp; typedef itk::ShrinkImageFilter&lt; TInputImageType, TRealImageType &gt; ShrinkerImageType;<br>&nbsp;&nbsp;&nbsp; typename ShrinkerImageType::Pointer shrinker1 = ShrinkerImageType::New();<br>
&nbsp;&nbsp;&nbsp; shrinker1-&gt;SetInput( m_inputImage );<br>&nbsp;&nbsp;&nbsp; shrinker1-&gt;SetShrinkFactors( 1 );<br><br>&nbsp;&nbsp;&nbsp; typedef itk::ShrinkImageFilter&lt; TMaskImageType, TMaskImageType &gt; ShrinkerMaskType;<br>&nbsp;&nbsp;&nbsp; typename ShrinkerMaskType::Pointer shrinker2 = ShrinkerMaskType::New();<br>
&nbsp;&nbsp;&nbsp; shrinker2-&gt;SetInput( m_maskImage );<br>&nbsp;&nbsp;&nbsp; shrinker2-&gt;SetShrinkFactors( 1 );<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; if( m_shrinkFactor &gt; 1 )<br>&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; shrinker1-&gt;SetShrinkFactors( m_shrinkFactor );<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; shrinker2-&gt;SetShrinkFactors( m_shrinkFactor );<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; shrinker1-&gt;Update();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; shrinker2-&gt;Update();<br>&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; typename TRealImageType::Pointer realInputImage = shrinker1-&gt;GetOutput(); <br>&nbsp;&nbsp;&nbsp; typename TMaskImageType::Pointer maskShrinked = shrinker2-&gt;GetOutput();<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; ///<br>&nbsp;&nbsp;&nbsp; /// Run bias field correction<br>&nbsp;&nbsp;&nbsp; ///<br>&nbsp;&nbsp;&nbsp; typedef itk::N3MRIBiasFieldCorrectionImageFilter&lt; TRealImageType, TMaskImageType, TRealImageType &gt; CorrectorType;<br>&nbsp; &nbsp;&nbsp;&nbsp; typename CorrectorType::Pointer corrector = CorrectorType::New();<br>
&nbsp; &nbsp;&nbsp;&nbsp; corrector-&gt;SetInput( realInputImage );<br>&nbsp; &nbsp;&nbsp;&nbsp; corrector-&gt;SetMaskImage( maskShrinked );<br>&nbsp;&nbsp;&nbsp;&nbsp; corrector-&gt;SetMaskLabel( NumericTraits&lt; TMaskImageType::PixelType &gt;::One );<br>&nbsp;&nbsp;&nbsp; corrector-&gt;SetMaximumNumberOfIterations( m_maxNumIter );<br>
&nbsp;&nbsp;&nbsp; corrector-&gt;SetNumberOfFittingLevels( m_numFittingLevels );<br><br>&nbsp;&nbsp;&nbsp; try<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; corrector-&gt;Update();<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; catch ( itk::ExceptionObject &amp; err )<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; std::cout &lt;&lt; "Caught an exception: " &lt;&lt; std::endl;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; std::cout &lt;&lt; err &lt;&lt; " " &lt;&lt; __FILE__ &lt;&lt; " " &lt;&lt; __LINE__ &lt;&lt; std::endl;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; throw err;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; catch (... )<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; std::cout &lt;&lt; "Error while applying bias field correction" &lt;&lt; std::endl;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; throw;<br>&nbsp;&nbsp;&nbsp; }<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.&nbsp; 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>&nbsp;&nbsp; <br>cout &lt;&lt; "Starting" &lt;&lt; endl;<br><br>&nbsp; cout &lt;&lt; fieldEstimate-&gt;GetOrigin() &lt;&lt; endl;<br>&nbsp; cout &lt;&lt; fieldEstimate-&gt;GetSpacing() &lt;&lt; endl;<br>
&nbsp; cout &lt;&lt; fieldEstimate-&gt;GetLargestPossibleRegion().GetSize() &lt;&lt; endl;<br>&nbsp; cout &lt;&lt; fieldEstimate-&gt;GetDirection() &lt;&lt; endl;<br>&nbsp; cout &lt;&lt; this-&gt;m_NumberOfFittingLevels &lt;&lt; endl;<br>
&nbsp; cout &lt;&lt; this-&gt;m_SplineOrder &lt;&lt; endl;<br>&nbsp; cout &lt;&lt; this-&gt;m_NumberOfControlPoints &lt;&lt; endl;&nbsp;&nbsp; <br>&nbsp;&nbsp; <br>&nbsp; typename BSplineFilterType::Pointer bspliner = BSplineFilterType::New();<br>&nbsp; bspliner-&gt;SetOrigin( fieldEstimate-&gt;GetOrigin() );<br>
&nbsp; bspliner-&gt;SetSpacing( fieldEstimate-&gt;GetSpacing() );<br>&nbsp; bspliner-&gt;SetSize( fieldEstimate-&gt;GetLargestPossibleRegion().GetSize() );<br>&nbsp; bspliner-&gt;SetDirection( fieldEstimate-&gt;GetDirection() );<br>&nbsp; bspliner-&gt;SetGenerateOutputImage( true );<br>
&nbsp; bspliner-&gt;SetNumberOfLevels( this-&gt;m_NumberOfFittingLevels );<br>&nbsp; bspliner-&gt;SetSplineOrder( this-&gt;m_SplineOrder );<br>&nbsp; bspliner-&gt;SetNumberOfControlPoints( this-&gt;m_NumberOfControlPoints );<br>&nbsp; bspliner-&gt;SetInput( fieldPoints );<br>
&nbsp; bspliner-&gt;Update();<br>&nbsp;&nbsp; <br>cout &lt;&lt; "Finished" &lt;&lt; endl;<br><br><br>
_____________________________________<br>Powered by <a href="http://www.kitware.com">www.kitware.com</a><br><br>Visit other Kitware open-source projects at<br><a href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a><br><br>Please keep messages on-topic and check the ITK FAQ at: http://www.itk.org/Wiki/ITK_FAQ<br><br>Follow this link to subscribe/unsubscribe:<br>http://www.itk.org/mailman/listinfo/insight-users<br></blockquote></div><br></div></body></html>