<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Hi Ricardo,</div><div><br></div><div>Okay, now I understand. &nbsp;In that case, I have two other suggestions:</div><div><br></div><div>1) In the output of your code below</div><div><br></div><div><blockquote type="cite">&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;&nbsp;<br></blockquote><br></div><div>can you also add&nbsp;</div><div><br></div><div>cout &lt;&lt; fieldPoints-&gt;GetNumberOfPoints() &lt;&lt; endl;</div><div><br></div><div>2) Also, could you see what happens if you convert your minc file to nifti or some other format?</div><div><br></div><div>Nick</div><div><br></div><div><br></div><div><br><div><div>On Oct 14, 2009, at 7:55 PM, Ricardo Ferrari wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Hi Nick,<br><br>Thanks for your e-mail. <br><br>Actually, I am not submitting a mask of all zeros because I am saving and checking the resulting mask image obtained from the Otsu threshold. <br><br>What I´ve meant by "m_maskImage is purposely equal to zero" in the source code is that I have set the pointer to 0 (NULL) so that the mask could be computed by using the Otsu thresh. As I said, the mask seems to be okay - I have visually checked it.  <br>
<br>The funny thing is if I do not downsample the image (and the mask, of course) I have no problems. I have also checked both the downsampled image &amp; mask, and apparentely (by visually checking) everything is fine.<br>
<br>I will keep trying to figure out the problem!!!&nbsp; Any suggestion is welcome !!<br><br>Thanks, <br>Ricardo <br><br><br><br><div class="gmail_quote">On Wed, Oct 14, 2009 at 7:29 PM, Nicholas Tustison <span dir="ltr">&lt;<a href="mailto:ntustison@gmail.com">ntustison@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div style="word-wrap: break-word;">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><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" target="_blank">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/" target="_blank">www.kitware.com</a><br><br>Visit other Kitware open-source projects at<br><a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>Please keep messages on-topic and check the ITK FAQ at: <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br><br>Follow this link to subscribe/unsubscribe:<br><a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
</blockquote></div><br></div></div></blockquote></div><br>
</blockquote></div><br></div></body></html>