[Insight-users] Problem with itkN3MRIBiasFieldCorrectionImageFilter

Nicholas Tustison ntustison at gmail.com
Wed Oct 14 20:01:14 EDT 2009


Hi Ricardo,

Okay, now I understand.  In that case, I have two other suggestions:

1) In the output of your code below

>  cout << fieldEstimate->GetOrigin() << endl;
>   cout << fieldEstimate->GetSpacing() << endl;
>   cout << fieldEstimate->GetLargestPossibleRegion().GetSize() << endl;
>   cout << fieldEstimate->GetDirection() << endl;
>   cout << this->m_NumberOfFittingLevels << endl;
>   cout << this->m_SplineOrder << endl;
>   cout << this->m_NumberOfControlPoints << endl;

can you also add

cout << fieldPoints->GetNumberOfPoints() << endl;

2) Also, could you see what happens if you convert your minc file to  
nifti or some other format?

Nick



On Oct 14, 2009, at 7:55 PM, Ricardo Ferrari wrote:

> Hi Nick,
>
> Thanks for your e-mail.
>
> 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.
>
> 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.
>
> 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 & mask, and apparentely (by visually checking)  
> everything is fine.
>
> I will keep trying to figure out the problem!!!  Any suggestion is  
> welcome !!
>
> Thanks,
> Ricardo
>
>
>
> On Wed, Oct 14, 2009 at 7:29 PM, Nicholas Tustison <ntustison at gmail.com 
> > wrote:
> Hi Ricardo,
>
> 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.
>
> Nick
>
>
>
>
> On Oct 14, 2009, at 5:10 PM, Ricardo Ferrari wrote:
>
>>
>> Dear itk users,
>>
>> 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.
>>
>> Above I am sending the main part of my code and the error I am  
>> getting.
>>
>> -------------------------------------
>>     /// m_inputImage is a minc image - you can download it from the  
>> following site: http://www.4shared.com/file/140891877/c11d6f0c/20090808_0_DUAL.html
>>
>>      int m_shrinkFactor = 2;
>>
>>     /// m_maskImage is purposely equal to zero so that it can be  
>> computed using Otsu threshold
>>
>>     ///
>>     /// Use Otsu threshold to compute a simple mask, if one is not  
>> provided
>>     ///
>>     if( ! m_maskImage )
>>     {
>>         typedef itk::OtsuThresholdImageFilter< TInputImageType,  
>> TMaskImageType > ThresholderType;
>>         typename ThresholderType::Pointer otsu =  
>> ThresholderType::New();
>>         otsu->SetInput( m_inputImage );
>>         otsu->SetNumberOfHistogramBins( 200 );
>>         otsu->SetInsideValue( 0 );
>>         otsu->SetOutsideValue( 1 );
>>         otsu->Update();
>>
>>         m_maskImage = otsu->GetOutput();
>>     }
>>
>>     ///
>>     /// DownSampling the input image to reduce computation time
>>     ///
>>     typedef itk::ShrinkImageFilter< TInputImageType, TRealImageType  
>> > ShrinkerImageType;
>>     typename ShrinkerImageType::Pointer shrinker1 =  
>> ShrinkerImageType::New();
>>     shrinker1->SetInput( m_inputImage );
>>     shrinker1->SetShrinkFactors( 1 );
>>
>>     typedef itk::ShrinkImageFilter< TMaskImageType, TMaskImageType  
>> > ShrinkerMaskType;
>>     typename ShrinkerMaskType::Pointer shrinker2 =  
>> ShrinkerMaskType::New();
>>     shrinker2->SetInput( m_maskImage );
>>     shrinker2->SetShrinkFactors( 1 );
>>
>>     if( m_shrinkFactor > 1 )
>>     {
>>         shrinker1->SetShrinkFactors( m_shrinkFactor );
>>         shrinker2->SetShrinkFactors( m_shrinkFactor );
>>         shrinker1->Update();
>>         shrinker2->Update();
>>     }
>>
>>     typename TRealImageType::Pointer realInputImage = shrinker1- 
>> >GetOutput();
>>     typename TMaskImageType::Pointer maskShrinked = shrinker2- 
>> >GetOutput();
>>
>>
>>     ///
>>     /// Run bias field correction
>>     ///
>>     typedef itk::N3MRIBiasFieldCorrectionImageFilter<  
>> TRealImageType, TMaskImageType, TRealImageType > CorrectorType;
>>       typename CorrectorType::Pointer corrector = CorrectorType::New 
>> ();
>>       corrector->SetInput( realInputImage );
>>       corrector->SetMaskImage( maskShrinked );
>>      corrector->SetMaskLabel( NumericTraits<  
>> TMaskImageType::PixelType >::One );
>>     corrector->SetMaximumNumberOfIterations( m_maxNumIter );
>>     corrector->SetNumberOfFittingLevels( m_numFittingLevels );
>>
>>     try
>>     {
>>         corrector->Update();
>>     }
>>     catch ( itk::ExceptionObject & err )
>>     {
>>         std::cout << "Caught an exception: " << std::endl;
>>         std::cout << err << " " << __FILE__ << " " << __LINE__ <<  
>> std::endl;
>>         throw err;
>>     }
>>     catch (... )
>>     {
>>         std::cout << "Error while applying bias field correction"  
>> << std::endl;
>>         throw;
>>     }
>>
>>
>> OUTPUT
>> --------------------------
>> Starting
>> [-116.98, -103.715, -34.2648]
>> [0.857143, 0.857143, 6]
>> [280, 280, 25]
>> 0.999208 -0.00996255 -0.0385217
>> 0.0108005 0.999708 0.0216062
>> 0.0382952 -0.0220051 0.999024
>>
>> [3, 3, 3]
>> 3
>> [4, 4, 4]
>> Segmentation fault
>> --------------------------
>>
>>
>> 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.
>>
>> I really appreciate any help on this !!!
>>
>> Thanks,
>> Ricardo
>>
>>
>> cout << "Starting" << endl;
>>
>>   cout << fieldEstimate->GetOrigin() << endl;
>>   cout << fieldEstimate->GetSpacing() << endl;
>>   cout << fieldEstimate->GetLargestPossibleRegion().GetSize() <<  
>> endl;
>>   cout << fieldEstimate->GetDirection() << endl;
>>   cout << this->m_NumberOfFittingLevels << endl;
>>   cout << this->m_SplineOrder << endl;
>>   cout << this->m_NumberOfControlPoints << endl;
>>
>>   typename BSplineFilterType::Pointer bspliner =  
>> BSplineFilterType::New();
>>   bspliner->SetOrigin( fieldEstimate->GetOrigin() );
>>   bspliner->SetSpacing( fieldEstimate->GetSpacing() );
>>   bspliner->SetSize( fieldEstimate->GetLargestPossibleRegion 
>> ().GetSize() );
>>   bspliner->SetDirection( fieldEstimate->GetDirection() );
>>   bspliner->SetGenerateOutputImage( true );
>>   bspliner->SetNumberOfLevels( this->m_NumberOfFittingLevels );
>>   bspliner->SetSplineOrder( this->m_SplineOrder );
>>   bspliner->SetNumberOfControlPoints( this- 
>> >m_NumberOfControlPoints );
>>   bspliner->SetInput( fieldPoints );
>>   bspliner->Update();
>>
>> cout << "Finished" << endl;
>>
>>
>> _____________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the ITK FAQ at: http://www.itk.org/Wiki/ITK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.itk.org/mailman/listinfo/insight-users
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20091014/b4a28f11/attachment.htm>


More information about the Insight-users mailing list