<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. Instead of submitting a mask of all zeros, just type a non-existent filename and the otsu mask will be calculated. Let me know if that works out.</div><div><br></div><div>Nick </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 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> /// 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< TInputImageType, TMaskImageType > ThresholderType;<br> typename ThresholderType::Pointer otsu = ThresholderType::New();<br>
otsu->SetInput( m_inputImage );<br> otsu->SetNumberOfHistogramBins( 200 );<br> otsu->SetInsideValue( 0 );<br> otsu->SetOutsideValue( 1 );<br> otsu->Update();<br><br> m_maskImage = otsu->GetOutput();<br>
} <br><br> ///<br> /// DownSampling the input image to reduce computation time<br> ///<br> typedef itk::ShrinkImageFilter< TInputImageType, TRealImageType > ShrinkerImageType;<br> typename ShrinkerImageType::Pointer shrinker1 = ShrinkerImageType::New();<br>
shrinker1->SetInput( m_inputImage );<br> shrinker1->SetShrinkFactors( 1 );<br><br> typedef itk::ShrinkImageFilter< TMaskImageType, TMaskImageType > ShrinkerMaskType;<br> typename ShrinkerMaskType::Pointer shrinker2 = ShrinkerMaskType::New();<br>
shrinker2->SetInput( m_maskImage );<br> shrinker2->SetShrinkFactors( 1 );<br> <br> if( m_shrinkFactor > 1 )<br> { <br> shrinker1->SetShrinkFactors( m_shrinkFactor );<br> shrinker2->SetShrinkFactors( m_shrinkFactor );<br>
shrinker1->Update();<br> shrinker2->Update();<br> }<br><br> typename TRealImageType::Pointer realInputImage = shrinker1->GetOutput(); <br> typename TMaskImageType::Pointer maskShrinked = shrinker2->GetOutput();<br>
<br> <br> ///<br> /// Run bias field correction<br> ///<br> typedef itk::N3MRIBiasFieldCorrectionImageFilter< TRealImageType, TMaskImageType, TRealImageType > CorrectorType;<br> typename CorrectorType::Pointer corrector = CorrectorType::New();<br>
corrector->SetInput( realInputImage );<br> corrector->SetMaskImage( maskShrinked );<br> corrector->SetMaskLabel( NumericTraits< TMaskImageType::PixelType >::One );<br> corrector->SetMaximumNumberOfIterations( m_maxNumIter );<br>
corrector->SetNumberOfFittingLevels( m_numFittingLevels );<br><br> try<br> {<br> corrector->Update();<br> }<br> catch ( itk::ExceptionObject & err )<br> {<br> std::cout << "Caught an exception: " << std::endl;<br>
std::cout << err << " " << __FILE__ << " " << __LINE__ << std::endl;<br> throw err;<br> }<br> catch (... )<br> {<br> std::cout << "Error while applying bias field correction" << 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 << "Starting" << endl;<br><br> cout << fieldEstimate->GetOrigin() << endl;<br> cout << fieldEstimate->GetSpacing() << endl;<br>
cout << fieldEstimate->GetLargestPossibleRegion().GetSize() << endl;<br> cout << fieldEstimate->GetDirection() << endl;<br> cout << this->m_NumberOfFittingLevels << endl;<br>
cout << this->m_SplineOrder << endl;<br> cout << this->m_NumberOfControlPoints << endl; <br> <br> typename BSplineFilterType::Pointer bspliner = BSplineFilterType::New();<br> bspliner->SetOrigin( fieldEstimate->GetOrigin() );<br>
bspliner->SetSpacing( fieldEstimate->GetSpacing() );<br> bspliner->SetSize( fieldEstimate->GetLargestPossibleRegion().GetSize() );<br> bspliner->SetDirection( fieldEstimate->GetDirection() );<br> bspliner->SetGenerateOutputImage( true );<br>
bspliner->SetNumberOfLevels( this->m_NumberOfFittingLevels );<br> bspliner->SetSplineOrder( this->m_SplineOrder );<br> bspliner->SetNumberOfControlPoints( this->m_NumberOfControlPoints );<br> bspliner->SetInput( fieldPoints );<br>
bspliner->Update();<br> <br>cout << "Finished" << 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>